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
25 lines (23 loc) · 1.3 KB
/
Calculator.java
File metadata and controls
25 lines (23 loc) · 1.3 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
import java.util.Scanner;
public class Calculator {
static Scanner scanner = new Scanner(System.in);
public static void calculator() {
System.out.println("Введите название товара");
String nameProduct = scanner.next();
Main.amountProducts = Main.amountProducts + 1;
Main.listProducts = Main.listProducts + "\n" + nameProduct;
System.out.println("Введите стоимость товара в формате в рубли и копейки. Образец 11.11");
double price = scanner.nextDouble();
while (price < 0) {
System.out.println("Ошибка! У товара не может быть отрицательной стоимости. Повторите ввод цены.");
price = scanner.nextDouble();
}
Main.totalPrice = Main.totalPrice + price;
System.out.println("Товар добавлен.\nДля продолжения введите любой символ и нажмите Enter. " +
"\nЕсли хотите завершить процесс добавления товара введите 'Завершить'");
String input = scanner.next();
if (!input.equalsIgnoreCase("завершить")){
calculator();
}
}
}