Skip to content
Closed
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
27 changes: 27 additions & 0 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Calculator {
String foodName;
String totalFoodList = "";
int persons;
double foodCost;
double totalCost;
double costPerPerson;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переменная не используется, можно удалить



double foodCostCalc (int persons, double foodCost) {
this.persons = persons;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, переменная не используется, только инициализируется

this.foodCost = foodCost;
totalCost += this.foodCost;
System.out.println("Блюдо успешно добавлено в общий счет");
return totalCost;


}
String foodNameConcat (String foodName) {
this.foodName = foodName;
totalFoodList += this.foodName + "\n";
return totalFoodList;

}


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

public class Check {

String currencyAddition(double num){
double adds = num % 100;
int addsInvert = (int) (Math.floor(adds));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше сначала округлить, а потом взять остаток от деления по модулю 100
Стоит добавить if с проверкой, что addsInvert >= 11 и <=19, тогда возвращать рублей


switch (addsInvert){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А здесь добавить деление по модулю 10, чтобы брать последнюю цифру

case 1:
return "рубль";
case 2:
case 3:
case 4:
return "рубля";
default:
return "рублей";
}
}
}
59 changes: 56 additions & 3 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
import java.util.Scanner;
public class Main {

public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
int persons;
String foodName;
double foodCost;
String totalFoodList;
double totalCost;
String statement;


while (true) {
System.out.println("Введите количество участников");
Scanner input = new Scanner(System.in);
if (input.hasNextInt()) {
persons = input.nextInt();
if (persons <= 0) {System.out.println("Количество участников отрицательно или равно нулю. Попробуйте еще раз.");}
else if (persons == 1) {System.out.println("Нет необходимости делить счет");}
else if (persons >0) {break;}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно здесь поставить просто else, потому что с предыдущими проверками тут members >0 будет всегда true

}

else {System.out.println("Вы ввели неверные данные. Попробуйте еще раз.");}

}

Calculator calculating = new Calculator();


while (true) {
Scanner dishesInput = new Scanner (System.in);
System.out.println("Что Вы с друзями заказали ?");

foodName = dishesInput.next();
totalFoodList = calculating.foodNameConcat(foodName);
System.out.println("Сколько стоило это блюдо ?");


if (dishesInput.hasNextDouble()) {
foodCost = dishesInput.nextDouble();
totalCost = calculating.foodCostCalc(persons,foodCost);
System.out.println("Это все ? Завершить/Нет");
statement = dishesInput.next();
if (statement.equalsIgnoreCase("Завершить")) {
break;
}
}

else {System.out.println("Что-то не так со стоимостью блюда. Попробуйте еще раз.");}

}


Check cur = new Check();

System.out.println("Ваш заказ: " + "\n" + totalFoodList);
System.out.println("Ваш общий счет: " + String.format("%,.2f", totalCost) + " " + cur.currencyAddition(totalCost) );
System.out.println("Каждый должен оплатить " + String.format("%,.2f", (totalCost/persons)) + " " + cur.currencyAddition(totalCost/persons));

}
}