Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
80 lines (68 loc) · 2.82 KB
/
Copy pathMain.java
File metadata and controls
80 lines (68 loc) · 2.82 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int count=0;
Goods purchases = new Goods ("",0.0);
System.out.println ("For how many people do you need to split the bill?");
count = countOfPeople();
System.out.println (count);
Scanner scanner = new Scanner(System.in);
boolean trigger = true;
do {
Goods product = new Goods("", 0.0);
System.out.println("Enter good`s name");
product.name = scanner.nextLine();
System.out.println("Enter good`s price in format ruble.penny. For example: 0.00");
while (true) {
if (scanner.hasNextDouble()) {
product.price = scanner.nextDouble();
if (product.price > 0) {
break;
} else {
System.out.println("Wrong format, pleas try again");
scanner.nextLine();
}
} else {
System.out.println("Wrong format, pleas try again");
scanner.nextLine();
}
}
purchases = Summoning.Calculate(product, purchases);
System.out.println("Do you want to add next product? If no, write \"complete\", else any phrase.");
scanner.nextLine();
String chek = scanner.nextLine();
trigger = !chek.equalsIgnoreCase("complete");
} while (trigger);
System.out.println("Purchased products:\n"+purchases.name);
double bill = purchases.price/count;
String finalPhrase1 = "%.2f рубль";
String finalPhrase2 = "%.2f рубля";
String finalPhrase3 = "%.2f рублей";
int ostatok = (int) (Math.floor(bill)%10.0);
if ((bill <=19 && bill>=11) || (ostatok>=5 && ostatok<=9)|| ostatok==0){
System.out.println(String.format(finalPhrase3, bill));
} else{
if (ostatok == 1) {
System.out.println(String.format(finalPhrase1, bill));
} else{
System.out.println(String.format(finalPhrase2, bill));
}
}
}
public static int countOfPeople (){
Scanner scanner = new Scanner(System.in);
while (true){
if (scanner.hasNextInt()) {
int x = scanner.nextInt();
if (x > 1) {
return x;
} else {
System.out.println("Invalid quantity entered, please try again.");
}
} else{
System.out.println("Invalid quantity entered, please try again.");
scanner.nextLine();
}
}
}
}