This repository was archived by the owner on Apr 14, 2025. It is now read-only.
forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
41 lines (40 loc) · 1.86 KB
/
Main.java
File metadata and controls
41 lines (40 loc) · 1.86 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
// dev branch for Y.Practicum
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int countPerson;
String line;
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите количество человек, на которых нужно разделить счет");
line = scanner.next();
try {
countPerson = Integer.parseInt(line.trim());
if(countPerson<=1){
System.out.println("Нужно ввести число больше 1");
}else{
break;
}
} catch (NumberFormatException nfe) {
System.out.println("Нужно ввести целое число");
}
}
Item item = new Item(scanner);
Calculate calculate = new Calculate();
Format formatter = new Format();
while(true) {
calculate.add(item.getName(),item.getPrice());
System.out.println("Товар успешно добавлен");
System.out.println("Введите слово \"Завершить\" для расчета. Если хотите продолжить, введите любой символ");
line = scanner.next();
if(line.equalsIgnoreCase("Завершить")){
System.out.println("Список товаров:");
System.out.println(calculate.productList);
break;
}
}
System.out.printf("Итог - %s\n",formatter.price(calculate.finalPrice));
System.out.printf("Сумма с каждого - %s ",formatter.price(calculate.finalPrice/(float)countPerson));
System.out.println(formatter.ruble(calculate.finalPrice/(float)countPerson));
}
}