Skip to content

Commit 2e4159d

Browse files
committed
Now exalted price can be passed via args
1 parent 81aed99 commit 2e4159d

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

src/main/java/org/example/domain/Trade.java

-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class Trade {
1313
private final double price;
1414
private final double pricePerUnit;
1515
private final int amount;
16-
private static final ExaltedPrice exaltedPrice = new ExaltedPrice(150);
1716

1817
public Trade(String date, String item, String currency, int amount, double price) {
1918
this.amount = amount;
@@ -44,10 +43,6 @@ public int getAmount() {
4443
return amount;
4544
}
4645

47-
public static int getExPrice() {
48-
return exaltedPrice.getExPrice();
49-
}
50-
5146
@Override
5247
public String toString() {
5348
DecimalFormat df = new DecimalFormat("0.#");

src/main/java/org/example/reader/DataStorage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class DataStorage {
1010
private static final Eternal eternal = new Eternal();
1111
private static final Karui karui = new Karui();
1212
private static DataStorage instance;
13-
private static final int exaltedPrice = Trade.getExPrice();
13+
private static final int exaltedPrice = ExaltedPrice.getExPrice();
1414

1515
private DataStorage() {
1616
}

src/main/java/org/example/reader/Emblem.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.example.reader;
22

3-
4-
import org.example.domain.Trade;
5-
63
import java.text.DecimalFormat;
74

85
public abstract class Emblem {
@@ -43,8 +40,8 @@ public void add(String currency, int amountTrade, double price, String name) {
4340
}
4441
if (currency.equals("Exalted Orb")) {
4542
exaltedSpent += price;
46-
maxPriceE = Math.max(price * Trade.getExPrice(), maxPriceE);
47-
minPriceE = (minPriceE == 0) ? price * Trade.getExPrice() : (Math.min(minPriceE, price * Trade.getExPrice()));
43+
maxPriceE = Math.max(price * ExaltedPrice.getExPrice(), maxPriceE);
44+
minPriceE = (minPriceE == 0) ? price * ExaltedPrice.getExPrice() : (Math.min(minPriceE, price * ExaltedPrice.getExPrice()));
4845
}
4946
}
5047

@@ -54,13 +51,14 @@ public String toString() {
5451
return emblemName
5552
+ " -> TOTAL: " + amount
5653
+ ", average: " + df.format(getAveragePrice())
57-
+ "c, c spent: " + chaosSpent
58-
+ ", ex spent: " + df.format(exaltedSpent)
59-
+ (splinters > 0 ? ", splinters left: " + splinters : "");
54+
+ "c, spent: " + chaosSpent
55+
+ "c, " + df.format(exaltedSpent)
56+
+ "ex " + (splinters > 0 ? ", splinters left: " + splinters : "")
57+
+ (totalSplinters > 0 ? "(" + totalSplinters + " for " + spentOnSplinters + "c)" : "");
6058
}
6159

6260
public double getAveragePrice() {
63-
double average = (chaosSpent + exaltedSpent * Trade.getExPrice()) / amount;
61+
double average = (chaosSpent + exaltedSpent * ExaltedPrice.getExPrice()) / amount;
6462
return (Double.isNaN(average) || amount == 0) ? 0d : average;
6563
}
6664

src/main/java/org/example/reader/ExaltedPrice.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
public class ExaltedPrice {
44

5-
private int exPrice;
5+
private static int exPrice;
66

7-
public ExaltedPrice(int price) {
7+
public static void setExPrice(int price) {
88
exPrice = price;
99
}
1010

11-
public void setExPrice(int price) {
12-
exPrice = price;
13-
}
14-
15-
public int getExPrice() {
11+
public static int getExPrice() {
1612
return exPrice;
1713
}
1814
}

src/main/java/org/example/reader/Main.java

+15
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,24 @@
1010
public class Main {
1111

1212
public static void main(String[] args) throws IOException {
13+
int exPrice = isNumeric(args[0]) ? Integer.parseInt(args[0]) : 150;
14+
ExaltedPrice.setExPrice(exPrice);
15+
System.out.println(exPrice);
1316
init();
1417
}
1518

19+
public static boolean isNumeric(String strNum) {
20+
if (strNum == null) {
21+
return false;
22+
}
23+
try {
24+
int d = Integer.parseInt(strNum);
25+
} catch (NumberFormatException nfe) {
26+
return false;
27+
}
28+
return true;
29+
}
30+
1631
private static void init() throws IOException {
1732
Parser parser = new Parser();
1833

0 commit comments

Comments
 (0)