Repository navigation
Expand file tree
/
Copy pathCalculator.java
More file actions
55 lines (52 loc) · 1.93 KB
/
Copy pathCalculator.java
File metadata and controls
55 lines (52 loc) · 1.93 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 sum = 0;
String name = "";
int quantity;
Scanner scanner = new Scanner(System.in);
public int quantityOfGuest(){
System.out.println("На скольких человек необходимо разделить счёт?");
while (true) {
if (scanner.hasNextInt()) {
quantity = scanner.nextInt();
if (quantity<=1){
System.out.println("Введено отрицательное значение или 1.Повторите ввод.");
}else {
return quantity;
}
} else {
System.out.println("Введено не корректное значение.Повторите ввод.");
}
scanner.nextLine();
}
}
public void cheque(String name, double cost) {
if (cost < 1) {
System.out.println("Товар не добавлен.\nТовар не может быть бесплатным.Повторите ввод.");
} else {
sum += cost;
this.name = this.name + name + "\n";
System.out.println("Товар успешно добалвен.");
}
}
public void finalAccount(int quantity){
System.out.println("Добавленные товары: \n" + name );
sum = sum / quantity;
System.out.println("Каждый человек должен заплатить: \n" + String.format("%.2f",sum) + price());
}
public String price(){
if ((int)(sum % 100 / 10) == 1){
return " рублей.";
}
switch ((int) (sum % 10)){
case 1:
return " рубль.";
case 2:
case 3:
case 4:
return " рубля.";
default:
return " рублей.";
}
}
}