forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculate.java
More file actions
40 lines (34 loc) · 1.85 KB
/
Calculate.java
File metadata and controls
40 lines (34 loc) · 1.85 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.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class Calculate {
public static void productArray (int number) {
ArrayList <Product> productList = new ArrayList<>();
Scanner scanner =new Scanner(System.in);
double summ = 0;
while (true) {
String nameProduct = NameAndPrice.nameProduct();
double priceProduct = NameAndPrice.priceProduct();
Product product = new Product(nameProduct, priceProduct);
productList.add(product);
System.out.printf("Вы добавили: %s, стоимостью: %.2f %s%n", product.name, product.price, Formatting.endingRuble(product.price));
System.out.println("Хотите ли добавить ещё товар? Или стоит завершить?");
System.out.println("Для добавления нажмите \"Ввод/Enter\" любую кнопку.");
System.out.println("Для завершения введите \"Завершить\"");
String endProgram = scanner.nextLine();
if (endProgram.equalsIgnoreCase("Завершить")) {
Iterator <Product> iteratorList = productList.iterator();
System.out.println("Добавлено товаров: ");
while (iteratorList.hasNext()){
Product element = iteratorList.next();
System.out.println(element.name);
summ += element.price;
}
System.out.printf("Общей стоимостью: %.2f%n", summ);
double payEach = summ / (double) number;
System.out.printf("Каждый должен заплатить по: %.2f %s%n", payEach, Formatting.endingRuble(payEach) );
break;
}
}
}
}