Repository navigation
Expand file tree
/
Copy pathActions.java
More file actions
57 lines (52 loc) · 1.92 KB
/
Copy pathActions.java
File metadata and controls
57 lines (52 loc) · 1.92 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
import java.util.Scanner;
public class Actions {
public static double GetProductPrice(Scanner scan) {
while (true) {
System.out.println("Введите цену товара!");
if (scan.hasNextDouble()) {
double price = scan.nextDouble();
if(price <= 0)
{
System.out.println("Ошибка! Ведите цену больше 0!");
}
else
{
return price;
}
} else {
scan.nextLine();
System.out.println("Ошибка! Введите дробное число!");
}
}
}
public static int GetNumber(Scanner scan) {
while (true) {
if (scan.hasNextInt()) {
return scan.nextInt();
} else {
scan.nextLine();
System.out.println("Ошибка! Введите число!");
}
}
}
public static String GetProducts(String name, String allNames) {
allNames = allNames + name + ".\n";
return allNames;
}
public static double GetPrices(double price, double allPrice) {
allPrice += price;
return allPrice;
}
public static void ShowResult(double price) {
String result = "Цена для каждого: \"%.2f %s\"";
if (Math.floor(price) > 11 && Math.floor(price) < 15) {
System.out.println(String.format(result, price, "рублей"));
} else if (Math.floor(price) % 10 == 1) {
System.out.println(String.format(result, price, "рубль"));
} else if (Math.floor(price) % 10 > 1 && Math.floor(price) % 10 < 5) {
System.out.println(String.format(result, price, "рубля"));
} else {
System.out.println(String.format(result, price, "рублей"));
}
}
}