Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions WK4/StockService/src/StockServices/BasicStockService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package StockServices;

import java.util.Calendar;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc

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);
}
}

31 changes: 31 additions & 0 deletions WK4/StockService/src/StockServices/Interval.java
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() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what this code is about?
you don't need this. Interval should be an enum the describes a period of time. e.g. a minute, hour, day etc.

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;
}
}
}
49 changes: 49 additions & 0 deletions WK4/StockService/src/StockServices/StockQuote.java
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;
}
}
51 changes: 51 additions & 0 deletions WK4/StockService/src/StockServices/StockQuoteApplication.java
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);
}
}
39 changes: 39 additions & 0 deletions WK4/StockService/src/StockServices/StockService.java
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);
}
15 changes: 15 additions & 0 deletions WK4/StockService/src/StockServices/StockServiceFactory.java
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*/
Copy link

Choose a reason for hiding this comment

The 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

}
}
Binary file not shown.
38 changes: 38 additions & 0 deletions WK4/StockService/src/StockServices/StockTest.java
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() {
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these aren't doing anything.

@Test
void getQuote5() {
}
}