forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
52 lines (46 loc) · 2.45 KB
/
Calculator.java
File metadata and controls
52 lines (46 loc) · 2.45 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
import java.util.Scanner;
public class Calculator {
String dishName, allDishName ="Список блюд:", trailingSlashes;
double dishPrice, allDishPrice;
int priceOfDish;
Scanner scanner = new Scanner(System.in);
public double dishNameAndPrice(){
System.out.println("Введите название, а затем цену блюда");
while(true){
System.out.println("Введите название блюда:");
dishName = scanner.nextLine();
if (dishName.equalsIgnoreCase("завершить")){
break;
}
allDishName += ("\n" + dishName);
System.out.println("Введите цену блюда (в формате: рубли, копейки):");
while(true) {
if(scanner.hasNextDouble()) {
dishPrice = scanner.nextDouble();
scanner.nextLine();
if(dishPrice >=0){
allDishPrice += dishPrice;
priceOfDish = (int) dishPrice;
trailingSlashes = "";
for(int i = dishName.length(); i<= 15; i++)
{
trailingSlashes +="." ;
}
allDishName += (" " + trailingSlashes + " " + priceOfDish + " руб. " + (int) ((dishPrice * 100 - priceOfDish * 100)) + " коп.");
System.out.println("Блюдо добавлено в счёт.\nЕсли хотите добавить ещё блюдо в счёт - введите его название:\nЕсли хотите сформировать счёт введите: завершить");
break;
}else{
System.out.println("Введите цену в нужном формате!");
}
}else{
if(scanner.nextLine().equalsIgnoreCase("завершить")){
System.out.println("\nДля формирования счёта добавьте цену последнего блюда и введите: завершить");
}
System.out.println("Введите цену в нужном формате (рубли,копейки)!");
}
}
}
System.out.println(allDishName);
return allDishPrice;
}
}