-
Notifications
You must be signed in to change notification settings - Fork 0
WK4 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
WK4 #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package StockServices; | ||
|
|
||
| import java.util.Calendar; | ||
|
|
||
| public class BasicStockService extends StockQuote { | ||
| String bssSymbol; | ||
| Calendar bssFrom; | ||
| Calendar bssUntil; | ||
| Interval bssInterval; | ||
|
|
||
| public BasicStockService(String symbol, Calendar from, Calendar until, Interval interval){ | ||
| this.bssSymbol = symbol; | ||
| this .bssFrom = from; | ||
| this.bssUntil = until; | ||
| this.bssInterval = interval; | ||
| } | ||
| public StockQuote getStockQuote(String bssSymbol, Calendar bssFrom, Calendar bssUntil, Interval bssInterval) { | ||
| if (bssFrom == null ) | ||
| return new StockQuote(bssSymbol); | ||
| else if (bssInterval == null) | ||
| return new StockQuote(bssSymbol, bssFrom, bssUntil); | ||
| else | ||
| return new StockQuote(bssSymbol, bssFrom, bssUntil, bssInterval); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package StockServices; | ||
|
|
||
| public class Interval { | ||
|
|
||
| public enum chooseWeek { | ||
| WK1, WK2, WK3, WK4 | ||
| } | ||
|
|
||
| chooseWeek week; | ||
|
|
||
| public Interval(chooseWeek week) { | ||
| this.week = week; | ||
| } | ||
|
|
||
| public void weekChosen() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what this code is about? |
||
| switch (week) { | ||
| case WK1: | ||
| System.out.println("Biggest Market Place in the World."); | ||
| break; | ||
|
|
||
| case WK2: | ||
| System.out.println("Simplest way to manage Money."); | ||
| break; | ||
|
|
||
| case WK3: | ||
| case WK4: | ||
| System.out.println("1st Web 2.0 Company."); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package StockServices; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Calendar; | ||
| import java.util.List; | ||
|
|
||
| public class StockQuote implements StockService { | ||
| String sqSymbol; | ||
| Calendar sqFrom, sqUntil; | ||
| Interval sqInterval; | ||
|
|
||
| public StockQuote(String symbol) { | ||
| this.sqSymbol = symbol; | ||
| } | ||
| public StockQuote(String symbol, Calendar from, Calendar until) { | ||
| this.sqSymbol = symbol; | ||
| this.sqFrom = from; | ||
| this.sqUntil = until; | ||
| } | ||
| public StockQuote(String symbol, Calendar from, Calendar until, Interval interval) { | ||
| this.sqSymbol = symbol; | ||
| this.sqFrom = from; | ||
| this.sqUntil = until; | ||
| this.sqInterval = interval; | ||
| } | ||
| public StockQuote() { | ||
| } | ||
|
|
||
| @Override | ||
| public StockQuote getQuote(String symbol) { | ||
| return new StockQuote(sqSymbol); | ||
| } | ||
| @Override | ||
| public List<StockQuote> getQuote(String symbol, Calendar from, Calendar until) { | ||
| List<StockQuote> stockQuoteList = new ArrayList<>(); | ||
| StockQuote stockQuote = new StockQuote(); | ||
| StockService stockService = new StockQuote(); | ||
| stockService.getQuote(sqSymbol, sqFrom, sqUntil); | ||
| stockQuoteList.add(stockQuote); | ||
| return stockQuoteList; | ||
| } | ||
| @Override | ||
| public List<StockQuote> getQuote(String sqSymbol, Calendar sqFrom, Calendar sqUntil, Interval sqInterval) { | ||
| List<StockQuote> stockQuoteList = new ArrayList<>(); | ||
| StockQuote stockQuote = new StockQuote(sqSymbol, sqFrom, sqUntil, sqInterval); | ||
| stockQuoteList.add(stockQuote); | ||
| return stockQuoteList; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package StockServices; | ||
|
|
||
| import java.text.ParseException; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Calendar; | ||
| import java.util.Date; | ||
|
|
||
| public class StockQuoteApplication { | ||
| public static void main(String[] args) throws ParseException { | ||
|
|
||
| String symbol, startDate, endDate; | ||
|
|
||
| SimpleDateFormat sdf = new SimpleDateFormat("yyyy MM dd"); | ||
|
|
||
| symbol = "ABC"; | ||
|
|
||
| startDate = "2018 01 01"; | ||
| Date fromDate = sdf.parse(startDate); | ||
| Calendar from = Calendar.getInstance(); | ||
| from.setTime(fromDate); | ||
|
|
||
| endDate = "2018 01 07"; | ||
| Date toDate = sdf.parse(endDate); | ||
| Calendar until = Calendar.getInstance(); | ||
| until.setTime(toDate); | ||
|
|
||
| String week = "WK1"; | ||
| Interval interval; | ||
|
|
||
| if (week == "WK1") { | ||
| interval = new Interval(Interval.chooseWeek.WK1); | ||
| interval.weekChosen(); | ||
| } | ||
| else if (week == "WK2") { | ||
| interval = new Interval(Interval.chooseWeek.WK2); | ||
| interval.weekChosen(); | ||
| } | ||
| else if (week == "WK3") { | ||
| interval = new Interval(Interval.chooseWeek.WK3); | ||
| interval.weekChosen(); | ||
| } | ||
| else { | ||
| interval = new Interval(Interval.chooseWeek.WK4); | ||
| interval.weekChosen(); | ||
| } | ||
|
|
||
| StockServiceFactory stockServiceFactory = new StockServiceFactory(symbol, from, until, interval); | ||
| stockServiceFactory.getStockService(symbol, from, until, interval); | ||
| System.out.println(stockServiceFactory); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package StockServices; | ||
|
|
||
| import java.util.Calendar; | ||
| import java.util.List; | ||
|
|
||
| public interface StockService { | ||
| /** | ||
| * Return the current price for a share of stock for the | ||
| * given symbol | ||
| * @param symbol the stock symbol of the company you want a | ||
| * quote for e.g. APPL for APPLE | ||
| * @return a <CODE>BigDecimal</CODE> instance | ||
| */ | ||
| StockQuote getQuote(String symbol); | ||
| /** | ||
| * Get a historical list of stock quotes for the provided | ||
| * symbol | ||
| * @param symbol the stock symbol to search for | ||
| * @param from the date of the first stock quote | ||
| * @param until the date of the last stock quote | ||
| * @return a list of StockQuote instan | ||
| ces. | ||
| * One for each day in the range specified. | ||
| */ | ||
| List<StockQuote> getQuote(String symbol, Calendar from, Calendar until); | ||
| /** | ||
| * Get a historical list of stock quotes for the provide symbol | ||
| * This method will return one StockQuote per interval specified. | ||
| * | ||
| *@param symbol the stock symbol to search for | ||
| *@param from the date of the first stock quote | ||
| *@param until the date of the last stock quote | ||
| *@param interval the number of StockQuotes to get. E.g. if Interval.DAILY was specified | ||
| *one StockQuote per day will be returned. | ||
| * | ||
| @return a list of StockQuote instances. One for each day in the range specified. | ||
| */ | ||
| List<StockQuote> getQuote(String symbol, Calendar from, Calendar until, Interval interval); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package StockServices; | ||
|
|
||
| import java.util.Calendar; | ||
|
|
||
| public class StockServiceFactory{ | ||
| public StockServiceFactory() { | ||
| } | ||
| public StockServiceFactory getStockService(String Symbol, Calendar From, Calendar Until, Interval INTERVAL){ | ||
| BasicStockService basicStockService = new BasicStockService(Symbol, From, Until, INTERVAL); | ||
| StockServiceFactory stockServiceFactory = new StockServiceFactory(); | ||
| basicStockService.getStockQuote(Symbol, From, Until, INTERVAL); | ||
| return stockServiceFactory; | ||
| /*returs stock service*/ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need comments like this. what the code is doing is obvious |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package StockServices; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class StockTest { | ||
|
|
||
| @org.junit.jupiter.api.Test | ||
| void getQuote() { | ||
| } | ||
|
|
||
| @org.junit.jupiter.api.Test | ||
| void getQuote1() { | ||
| } | ||
|
|
||
| @org.junit.jupiter.api.Test | ||
| void getStockService() { | ||
| } | ||
|
|
||
| @org.junit.jupiter.api.Test | ||
| void getQuote2() { | ||
| } | ||
|
|
||
| @org.junit.jupiter.api.Test | ||
| void getQuote3() { | ||
| } | ||
|
|
||
| @org.junit.jupiter.api.Test | ||
| void main() { | ||
| } | ||
|
|
||
| @Test | ||
| void getQuote4() { | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these aren't doing anything. |
||
| @Test | ||
| void getQuote5() { | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javadoc