forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
102 lines (99 loc) · 3.89 KB
/
Main.java
File metadata and controls
102 lines (99 loc) · 3.89 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.lang.Math;
public class Main {
public static void main(String[] args) {
ArrayList<String> items;
ArrayList<Double> price;
int humans=-1;
int amount=0;
double sum2=0.0;
boolean bPrice = false;
Scanner scanner = new Scanner(System.in);
Calculator calculator = new Calculator();
items = new ArrayList<String>();
price = new ArrayList<Double>();
double d=0.0;
String s = "Что-то";
amount = 0;
System.out.println("На скольких человек необходимо разделить счёт?");
while (humans <= 1) {
try{
humans = scanner.nextInt();
} catch (InputMismatchException ex) {
System.out.println("Вы не ввели целое положительное число.");
scanner.next();
bPrice=true;
}
if ((humans == 1)&&!(bPrice)) {
System.out.println("Количество человек, введённых пользователем, равно 1. В этом случае нет смысла ничего считать и делить.");
} else if((humans <= 1)&&!(bPrice)){
System.out.println("Количество человек меньше 1. Это некорректное значение для подсчёта.");
}
bPrice=false;
}
scanner.nextLine();
while (true) {
System.out.println("Введите название продукта.");
s = scanner.nextLine();
items.add(s);
if((s.equalsIgnoreCase("Завершить"))){
break;
}
System.out.println("Введите цену продукта.");
while (!(bPrice)){
try{
d = scanner.nextDouble();
bPrice=true;
} catch (InputMismatchException ex) {
System.out.println("Вы не ввели численное значение.");
scanner.next();
}
}
scanner.nextLine();
bPrice=false;
price.add(d);
amount++;
System.out.println("Введите 'Завершить', если вы хотите произвести расчёт");
}
scanner.close();
System.out.println();
sum2=calculator.sum(amount, price, items);
calculator.finalCalcutation(sum2,humans);
}
}
class Calculator{
int round;
double am;
double sum(int amount, ArrayList<Double> price, ArrayList<String> items){
double sum = 0.0;
for (int i=0; i<amount;i++){
System.out.println(items.get(i));
am = price.get(i);
rU(am);
System.out.println("Цена: "+price.get(i)+rU(am));
sum = Double.sum(sum, (Double) price.get(i));
}
return sum;
}
void finalCalcutation(double yeah, int humans){
System.out.println("Сумма: "+yeah+rU(yeah));
System.out.println();
System.out.println("На одного человека: "+(yeah/humans)+rU(yeah/humans));
}
String rU(double eternal){
this.round=(int) eternal;
if(this.round%100==11||this.round%100==12||this.round%100==13||this.round%100==14||this.round%100==15||this.round%100==16||this.round%100==17||this.round%100==18||this.round%100==19){
return" рублей";
}else{
if(round%10==1){
return " рубль";
}else if(round%10==2||round%10==3||round%10==4){
return " рубля";
}else{
return " рублей";
}
}
}
}