Repository navigation
Expand file tree
/
Copy pathCalculator.java
More file actions
53 lines (47 loc) · 2.11 KB
/
Copy pathCalculator.java
File metadata and controls
53 lines (47 loc) · 2.11 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
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.Scanner;
public class Calculator {
double totalPrice=0;
String totalProduct = "" ;
public void priceEntry() {
System.out.println("Введите стоимость товара в формате \"xx,xx\" цифрами");
Scanner scanner = new Scanner(System.in);
while (true) {
if (scanner.hasNextDouble()) {
double inputPrice = scanner.nextDouble();
if (inputPrice<=0){
System.out.println("вы ввели некорректные данные");
scanner.nextLine();
} else{
System.out.println("Стоимость- "+ inputPrice);
totalPrice = totalPrice + inputPrice;
break;
}
} else {
System.out.println("Похоже вы ввели буквы или \".\",введите стоимость товара в формате \"xx,xx\" цифрами ");
scanner.nextLine();
}
}
}
public void productEntry(){
Scanner scanner = new Scanner(System.in);
System.out.println("Введите название продукта");
String nameOfProduct = scanner.nextLine();
while (true){
if(nameOfProduct.equalsIgnoreCase("завершить")){
System.out.println("операция завершена");
break;
}
else if(nameOfProduct.isEmpty()) {
System.out.println("вы ввели некоректные данные, попробуйте еще раз");
nameOfProduct = scanner.nextLine();
}
else {
System.out.println("вы выбрали "+ nameOfProduct);
totalProduct = totalProduct +"\n"+ nameOfProduct;
priceEntry();
System.out.println("Хотите добавить что-то еще? Если нет, введите \"завершить\" ?");
nameOfProduct = scanner.nextLine();
}
}
}
}