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
41 lines (36 loc) · 1.45 KB
/
Calculator.java
File metadata and controls
41 lines (36 loc) · 1.45 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
import java.util.ArrayList;
public class Calculator {
ArrayList<Product> products = new ArrayList<>();
double sum;
boolean add(String name, double price){
Product product = new Product(name, price);
boolean res = products.add(product);
if( res ){
System.out.println("Товар '" + name+"'"+
" стоимостью "+
String.format("%.2f ", price) +
(new Formatter( price ) ).getName()+
" добавлен в список.\n");
sum += price;
}
return res;
}
void printProductList(){
System.out.println("Добавленные товары:");
for(Product product : products){
System.out.println("'" + product.name+"' стоимостью " +
String.format("%.2f ", product.price) +
(new Formatter( product.price ) ).getName() );
}
}
void splitCheck(int countPerson){
double amountPerPerson = sum/countPerson;
System.out.println("\nОбщая сумма: " +
String.format("%.2f ",sum) +
(new Formatter( sum ) ).getName());
System.out.println("Количество человек: " + countPerson);
System.out.println("С каждого: " +
String.format("%.2f ", amountPerPerson) +
(new Formatter( amountPerPerson ) ).getName());
}
}