Repository navigation
Expand file tree
/
Copy pathCalculator.java
More file actions
54 lines (47 loc) · 2.26 KB
/
Copy pathCalculator.java
File metadata and controls
54 lines (47 loc) · 2.26 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.Scanner;
public class Calculator {
public static String spisok = "";
public static void calculator(String tovar, int skolkoLudei) {
float itogo = 0.00f;
float itogoSKazhdogo = 0.00f;
String raschet = "";
String okonchanie = "";
while (true) {
System.out.println("Хотите добавить товар?");
System.out.println("введите название товара ( если товаров более нет, то введите *Завершить*)");
Scanner scanner = new Scanner(System.in);
String nazvanieTovara = scanner.nextLine();
if (nazvanieTovara.equalsIgnoreCase("завершить")) {
itogoSKazhdogo = itogo / (float) skolkoLudei;
raschet = String.format("%.2f", itogoSKazhdogo);
okonchanie = Rublei.rublei(itogoSKazhdogo);
System.out.println("общий список: \n" + spisok);
System.out.println("итого с каждого: " + raschet + " рубл" + okonchanie);
return;
} else {
while (true) {
System.out.println("введите стоимость в формате *рубли.копейки*");
try {
float cena = scanner.nextFloat();
if (cena>=0) {
itogo = itogo + cena;
tovar = (nazvanieTovara + (" ") + cena);
spisok = (spisok + tovar + "\n");
System.out.println("итого: \n" + spisok);
break;
}
else
{
System.out.println("Введено некорректное значение");
break;
}
}
catch (Exception e) {
System.out.println("Введено некорректное значение");
break;
}
}
}
}
}
}