aboutsummaryrefslogtreecommitdiff
path: root/picker.java
diff options
context:
space:
mode:
Diffstat (limited to 'picker.java')
-rw-r--r--picker.java25
1 files changed, 19 insertions, 6 deletions
diff --git a/picker.java b/picker.java
index f25cf8f..d9de0f1 100644
--- a/picker.java
+++ b/picker.java
@@ -27,7 +27,7 @@ class Backpointer {
public Backpointer(int previousValue, Stock stock) {
this.stock = stock;
- this.totalValue = previousValue + stock.value;
+ this.totalValue = previousValue + stock.getValue();
}
public static Backpointer chooseBackpointer(Stock[] stocks,
@@ -38,7 +38,7 @@ class Backpointer {
new Backpointer(backpointers.get(currentPrice - 1).totalValue, NOTHING);
for (Stock stock : stocks) {
- int previousPrice = currentPrice - stock.price;
+ int previousPrice = currentPrice - stock.getPrice();
if (previousPrice >= 0) {
Backpointer candidate =
@@ -65,7 +65,7 @@ class Backpointer {
// postprocess backpointers
ArrayList<Stock> result = new ArrayList<Stock>();
for (int price = priceLimit; price > 0;
- price -= backpointers.get(price).stock.price) {
+ price -= backpointers.get(price).stock.getPrice()) {
Stock stock = backpointers.get(price).stock;
if (stock != NOTHING)
@@ -132,22 +132,27 @@ class Backpointer {
break;
}
}
- while(!run);
+ while (!run);
scanner.close();
// Stock stocks[] = {new Stock(3, 10, "A"), new Stock(4, 14, "B")};
ArrayList<Stock> result = chooseStocks(choices.toArray(
new Stock[choices.size()]), priceLimit);
+ int totalValue = 0;
for (Stock stock : result) {
System.out.println(stock);
+ totalValue += stock.getValue();
}
+
+ System.out.println("\nBuying power: " + priceLimit);
+ System.out.println("Total value: " + totalValue);
}
}
class Stock {
- int price, value;
- String ticker;
+ private int price, value;
+ private String ticker;
public Stock() {
price = 0;
@@ -161,6 +166,14 @@ class Stock {
this.ticker = ticker;
}
+ public int getPrice() {
+ return price;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
@Override
public String toString() {
return "Ticker: " + ticker + " price: " + price + " value: " + value;