-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStockMarket.java
More file actions
74 lines (62 loc) · 2.56 KB
/
Copy pathStockMarket.java
File metadata and controls
74 lines (62 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.*;
// Class that represents the stock market in the bank
public class StockMarket implements BankComponent {
private final ID id = new ID();
private ArrayList<Stock> stocks;
public StockMarket() {
this.stocks = new ArrayList<>();
addDefaultStocks();
}
public ID getID() {
return id;
}
public ArrayList<Stock> getStocks() {
return stocks;
}
public void setStocks(ArrayList<Stock> stocks) {
this.stocks = stocks;
}
// method that adds 10 stocks that the stock market will start off with
public ArrayList<Stock> addDefaultStocks() {
Stock amzn = new Stock("Amazon", "AMZN", new Dollar(2474.00), 100);
Stock fb = new Stock("Facebook", "FB", new Dollar(204.71), 100);
Stock msft = new Stock("Microsoft", "MSFT", new Dollar(174.57), 100);
Stock googl = new Stock("Alphabet", "GOOGL", new Dollar(1317.32), 100);
Stock baba = new Stock("Alibaba", "BABA", new Dollar(194.48), 100);
Stock fis = new Stock("Fidelity", "FIS", new Dollar(26.01), 100);
Stock crm = new Stock("Salesforce", "CRM", new Dollar(156.37), 100);
Stock ma = new Stock("Mastercard", "MA", new Dollar(268.74), 100);
Stock v = new Stock("Visa", "V", new Dollar(175.57), 100);
Stock nflx = new Stock("Netflix", "NFLX", new Dollar(415.27), 100);
stocks.add(amzn);
stocks.add(fb);
stocks.add(msft);
stocks.add(googl);
stocks.add(baba);
stocks.add(fis);
stocks.add(crm);
stocks.add(ma);
stocks.add(v);
stocks.add(nflx);
return stocks;
}
// method to create a String representation of the stock market
public String toString() {
StringBuilder str = new StringBuilder();
str.append("NAME\t TICKER\t PRICE\t # SHARES\t\n");
str.append(String.format("%1$-" + 15 + "s", "NAME") +
String.format("%1$-" + 15 + "s", "TICKER") +
String.format("%1$-" + 15 + "s", "PRICE") +
String.format("%1$-" + 15 + "s", "# SHARES"));
/*
for (Stock s : stocks) {
str.append(String.format("%1$-" + 15 + "s", s.getName()) +
String.format("%1$-" + 15 + "s", s.getTicker()) +
String.format("%1$-" + 15 + "s", s.getCurrentPrice().toString()) +
String.format("%1$-" + 15 + "s", s.getVolume()));
str.append("\n");
}
*/
return str.toString();
}
}