Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
89 lines (78 loc) · 3.17 KB
/
Copy pathMain.java
File metadata and controls
89 lines (78 loc) · 3.17 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
import java.util.Scanner;
public class Main {
static Scanner scan = new Scanner(System.in);
static Scanner scan1 = new Scanner(System.in);
static Scanner scan2 = new Scanner(System.in);
static Scanner scan3 = new Scanner(System.in);
static int people;
static Double productPrice;
public static void main(String[] args) {
Calculation calculation = new Calculation();
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
people();
while(true){
addProduct();
System.out.println("You want add another product? Input 'finish' if - No, else any symbol");
String finish = scan3.nextLine();
if(finish.equalsIgnoreCase("finish")){
break;
}
}
System.out.println("You order: " + calculation.calculationNameProduct());
System.out.println("Your price per guest: " + calculation.calculationPriceProduct() / people + " ' " + makeEnding(productPrice) + ".penni'");
}
public static int people(){
while (true) {
System.out.println("How guest?");
if (scan.hasNextInt()) {
people = scan.nextInt();
if (people > 1) {
break;
} else if (people == 1) {
System.out.println("nothing to share");
} else {
System.out.println("invalid input");
scan.nextInt();
}
}else{
System.out.println("invalid input");
scan.nextInt();
}
}
return people;
}
public static Product addProduct(){
Product product = new Product();
String productName;
System.out.println("Input name product");
productName = scan1.nextLine();
product.setNameProduct(productName);
System.out.println("you added " + productName);
while(true){
System.out.println("Input price product into format: 'rubles.penni' [10,45]");
if(scan2.hasNextDouble()){
productPrice = scan2.nextDouble();
if(productPrice > 0){
System.out.println("Price product: " + productPrice);
product.setPriceProduct(productPrice);
break;
}else {
System.out.println("invalid input");
scan2.next();
}
}else {
System.out.println("invalid input");
scan2.next();
}
}return product;
}
public static String makeEnding(Double productPrice){
if(Math.round(productPrice)%10 == 1 && Math.round(productPrice)%100 != 11){
return "ruble";
}else if((Math.round(productPrice)%10) <= 4 && (Math.round(productPrice)%100 >= 2) && (Math.round(productPrice)%100)/10 != 2){
return "rubles";
} else return "rubles";
}
}