Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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;
}
}

2 changes: 0 additions & 2 deletions src/main/java/Form.java

This file was deleted.

22 changes: 22 additions & 0 deletions src/main/java/Guests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.Scanner;

public class Guests {
public int guestsNum(){
int guestsNum = 0;
Scanner scanner = new Scanner(System.in);
do {
System.out.println("На какое количество человек хотите разделить счёт? (цифрой)");
if(scanner.hasNextInt()) {
guestsNum = scanner.nextInt();
if (guestsNum == 1) {
System.out.println("Нет смысла делить счёт!");
scanner.nextLine();
}
} else {
scanner.nextLine();
System.out.println("Пожалуйста, введите корректное количество гостей!");
}
} while(guestsNum<=1);
return guestsNum;
}
}
54 changes: 13 additions & 41 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Консольное приложение №1");
Guests guests = new Guests();
double totalCost;
int guestsNum;
String dishName;
String allDishName = "";
double dishPrice;
double allDishPrice = 0;
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("На какое количество человек хотите разделить счёт? (цифрой)");
guestsNum = sc.nextInt();
if (guestsNum > 1) {
break;
} else if (guestsNum == 1) {
System.out.println("Нет смысла делить счёт");
} else {
System.out.println("Введите корректное количество гостей");
}
}
while (true) {
System.out.println("Введите наименование блюда");
dishName = sc.next();
if (dishName.equalsIgnoreCase("завершить")) {
break;
} else {
allDishName += dishName + "\n";
}
System.out.println("Введите стоимость блюда цифрами");
dishPrice = sc.nextDouble();
if (dishPrice > 0) {
allDishPrice+=dishPrice;
} else {
System.out.println("Введите цену больше 0 и в нужном формате");
}
System.out.println("Блюдо добавлено в счёт.\nЕсли хотите добавить ещё блюдо в счёт - введите его название:\nЧтобы завершить список введите: Завершить");
}
String str1 = "Список блюд: " + "\n" + allDishName;
System.out.println(str1);
String str2 = "Количество гостей - " + guestsNum;
System.out.println(str2 + " чел.");
String str3 ="Сумма для каждого гостя: " + allDishPrice/guestsNum;
System.out.println(str3 + " рублей");
guestsNum = guests.guestsNum();
Calculator calculator = new Calculator();
totalCost = calculator.dishNameAndPrice();
System.out.println("Общая стоимость блюд: " + totalCost + " руб.");
System.out.println("Количество гостей: " + guestsNum + " чел.");
Rub rubles = new Rub();
rubles.endRub(guestsNum, totalCost);

}
}
}

2 changes: 0 additions & 2 deletions src/main/java/Price.java

This file was deleted.

2 changes: 0 additions & 2 deletions src/main/java/Product.java

This file was deleted.

23 changes: 23 additions & 0 deletions src/main/java/Rub.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Rub {

public void endRub (int guestsNum, double costAllDishes) {
double costForGuests;
String allDishPrice = "Итог: с каждого гостя по %.2f";
costForGuests = costAllDishes / guestsNum;
switch ((int) costForGuests % 10){
default:{
System.out.println(String.format(allDishPrice, costForGuests) + " рублей");
break;
} case (1) : {
System.out.println(String.format(allDishPrice, costForGuests) + " рубль");
break;
}
case (2) :
case (3) :
case (4) : {
System.out.println(String.format(allDishPrice, costForGuests) + " рубля");
break;
}
}
}
}