Repository navigation
Expand file tree
/
Copy pathCalculator.java
More file actions
72 lines (57 loc) · 2.3 KB
/
Copy pathCalculator.java
File metadata and controls
72 lines (57 loc) · 2.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
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.Scanner;
public class Calculator {
int number;
String products = "";
float amount = 0;
public int numberPeople() {
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("На скольки человек необходимо разделить счет?");
if(scanner.hasNextInt()) {
number = scanner.nextInt();
if (number == 1)
System.out.println("Нет смысла ничего делить");
else if (number < 1)
System.out.println("Введено некорректное количество");
else
break;
}
else
System.out.println("Введите целое положительное число:");
}
return number;
}
public void addProduct() {
while (true) {
Scanner scanner = new Scanner(System.in);
AddProduct nomenclature = new AddProduct();
nomenclature.addproduct();
amount += nomenclature.price;
products = products +"\n"+ nomenclature.product;
System.out.println("Вы хотите добавить еще один товар? Если нет, введите завершить");
String complete = scanner.next();
if (complete.equalsIgnoreCase("Завершить"))
break;
}
}
public void totals(){
String rub;
System.out.println("Добавленные товары: \n" + products);
System.out.println("Стоимость товаров: " + amount);
int lastnumber = (int) (Math.floor(amount/number)%10);
int ostatok = (int) ((amount/number)%100);
if (ostatok>=11 && ostatok<=14)
rub = "рублей";
else
{
int ostatok10 = (int) ((amount/number)%10);
if (ostatok10==1)
rub = "рубль";
else if (ostatok10>=2 && ostatok10<=4)
rub = "рубля";
else
rub = "рублей";
}
System.out.println("Каждый должен заплатить: " + String.format("%.2f",amount/number)+" "+rub);
}
}