forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVvod.java
More file actions
86 lines (73 loc) · 3.09 KB
/
Vvod.java
File metadata and controls
86 lines (73 loc) · 3.09 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
import java.util.Scanner;
import java.util.regex.Pattern;
public class Vvod {
public static void main(String[] args) {
}
public static String proverkaOshibokCena(String tovar,String calcul, String rubli, int number, String soglasie) {
boolean wenttocatch = false;
Float sum =0.00f;
String rubliDlaSum = " ";
Scanner scan = new Scanner(System.in);
Float cena = 0.00f;
// String calcul = "";
while (true) {
System.out.print("Напишите стоимость товара (руб,коп): ");
do {
if (scan.hasNextFloat()) {
cena = scan.nextFloat();
if (cena>0){
wenttocatch = true;
sum = sum + cena;}else{System.out.println("Ошибка число меньше либо равно нулю. Введите данные еще раз: ");}
} else {
scan.nextLine();
System.out.println("Ошибка! Введите данные формата руб,коп ");
}
} while (!wenttocatch);
System.out.println("Напишите название товара:");
boolean prov =false;
while(!prov){
tovar = scan.next();
if (tovar.matches(".*\\d.*")){
System.out.println("Напишите название товара без цифры:");
}else prov=true;
}
float k=sum/number;
rubli = GetRubleAddition(cena);
rubliDlaSum = GetRubleAddition(k);
if (cena instanceof Float & cena>=0.01f){
calcul = calcul + String.format("%s стомистью %.2f %s.\n", tovar, cena,rubli);
String global =String.format("\nКакждый гость должен будет заплатить %.2f %s\n", k, rubliDlaSum);
System.out.println(global);
System.out.println("Добавленные товары:\n " + calcul);
System.out.println("Хотите заказать ещё? тогда напшите любой символ. Напишите: Завершить, если всё заказали");
soglasie = scan.next();
if (soglasie.equalsIgnoreCase("Завершить")) {
System.out.println("\nВ итоге Добавленные товары:\n " + calcul);
calcul = calcul + String.format("%s стомистью %.2f %s.\n", tovar, cena,rubli);
System.out.println(global);
break;
}}
cena=0.00f;}
return calcul;
}
public static String GetRubleAddition(float num)
{
int RublConvert = (int) Math.floor(num);
var preLastDigit = RublConvert % 100 / 10;
if (preLastDigit == 1)
{
return "рублей";
}
switch ( RublConvert % 10)
{
case 1:
return "рубль";
case 2:
case 3:
case 4:
return "рубля";
default:
return "рублей";
}
}
}