forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
40 lines (35 loc) · 1 KB
/
Calculator.java
File metadata and controls
40 lines (35 loc) · 1 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
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.List;
public class Calculator {
private double currentSum = 0;
final private List<Item> itemList = new ArrayList<>();
public double getCurrentSum() {
return currentSum;
}
public boolean addItem(Item item) {
if (findItem(item)) {
return false;
} else {
itemList.add(item);
currentSum = currentSum + item.getPrice();
return true;
}
}
private boolean findItem(Item lookingItem) {
for (Item item : itemList) {
if (item.equals(lookingItem)) {
return true;
}
}
return false;
}
public String getItemList() {
String resultString = "";
for (Item item : itemList) {
resultString = resultString + item.getName() + ", "
+ Formatter.formatDoubleToString(item.getPrice()) + "\n";
}
return resultString;
}
}