-
Notifications
You must be signed in to change notification settings - Fork 218
Спринт 2 Калькулятор #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Спринт 2 Калькулятор #121
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
|
|
||
|
|
||
| double foodCostCalc (int persons, double foodCost) { | ||
| this.persons = persons; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } | ||
| 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)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лучше сначала округлить, а потом взять остаток от деления по модулю 100 |
||
|
|
||
| switch (addsInvert){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 "рублей"; | ||
| } | ||
| } | ||
| } | ||
| 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;} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Переменная не используется, можно удалить