-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarket.java
More file actions
68 lines (61 loc) · 2.55 KB
/
Copy pathMarket.java
File metadata and controls
68 lines (61 loc) · 2.55 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
import java.util.*;
import java.io.*;
import java.awt.*;
public class Market{
// instance variables - replace the example below with your own
public static TextArea marketArea;
static HashMap<String,Double> stockPrices;
static HashMap<String,Double> newStockPrices;
Label label = new Label();
private static ArrayList<Stock> stocksMarket;
/**
* Constructor for objects of class Market
*/
public Market() {
// initialise instance variables
stocksMarket = new ArrayList<Stock>();
//Setting up stocks
TechStock google = new TechStock("Google", "GOOGL", 1127.58);
TechStock apple = new TechStock("Apple", "APPL", 170.89);
FashionStock nike = new FashionStock("Nike", "NYSE", 84.71);
FashionStock adidas = new FashionStock("Adidas","ETR", 201.10);
BussinessStock amazon = new BussinessStock("Amazon", "AMZN", 1638.01);
BussinessStock paypal = new BussinessStock("PayPal", "PYPL", 94.38);
stocksMarket.add(0,google);
stocksMarket.add(1,apple);
stocksMarket.add(2,nike);
stocksMarket.add(3,adidas);
stocksMarket.add(4,amazon);
stocksMarket.add(5,paypal);
}
public static ArrayList<Stock> upDown() {
//Market market = new Market();
//String content;
for(int i=0; i<6; i++) {
Random rand = new Random();
Stock stock = stocksMarket.get(i);
String company = stock.getSymbol();
double currentValue = stock.getValue();
int operator = rand.nextInt(2);
if(operator==0) {
double decrease = Math.round((rand.nextDouble()*30.456));
double newValue = Math.round(currentValue-decrease);
stock.setPrice(newValue);
//content = "<html>" + String.valueOf(company) + ": " + String.valueOf(newValue) + "( - " + decrease+")</br></html>";
stocksMarket.set(i, stock);
//system.out.println(content);
} else {
double increase = Math.round((rand.nextDouble()*30.456));
double newValue = Math.round(currentValue+increase);
stock.setPrice(newValue);
//content = "<html>" + String.valueOf(company) + ": " + String.valueOf(newValue) + "( + " + increase+")</br></html>";
stocksMarket.set(i, stock);
//system.out.println(content);
}
}
return stocksMarket;
}
public static void main(String args[]) {
upDown();
}
}