Repository navigation
Expand file tree
/
Copy pathCalculator.java
More file actions
51 lines (44 loc) · 2.25 KB
/
Copy pathCalculator.java
File metadata and controls
51 lines (44 loc) · 2.25 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
import java.util.*;
public class Calculator {
public static float calculate() {
Scanner console = new Scanner(System.in);
float sum=0.00f;
System.out.println("Введите товар");
String product = console.nextLine();
float price = priceChecking();
sum=sum+price;
String cheque = String.format("*********************************************\nДобавленные товары:\n" + product + " %.2f", price) + " " + FormOfCurrency.defineTheForm((int)Math.floor(price));
System.out.println("Товар успешно добавлен. Завершить? (Введите Завершить либо любой другой символ для продолжения)");
while(true) {
if (console.next().equalsIgnoreCase("Завершить")) {
System.out.println(cheque);
break;
}
else {
System.out.println("Введите товар");
console.nextLine();
product = console.nextLine();
price = priceChecking();
sum=sum+price;
cheque = String.format(cheque + "\n" + product + " %.2f", price) + " " + FormOfCurrency.defineTheForm((int)Math.floor(price));
System.out.println("Товар успешно добавлен. Завершить? (Введите Завершить либо любой другой символ для продолжения)");
}
}
return sum;
}
public static float priceChecking () {
System.out.println("Введите цену товара в формате 00,00 (рубли,копейки)");
float price;
Scanner console = new Scanner(System.in);
while (!(console.hasNextFloat())) {
System.out.println("Требуется именно число в формате 00,00 (рубли,копейки) или 00 (рубли)");
console.next();
}
price=console.nextFloat();
while (!(price > 0)) {
System.out.println("Стоимость товара должна быть больше нуля");
price=console.nextFloat();
}
return price;
}
}