Repository navigation
Проектная Работа № 1 #1
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -1,22 +1,28 @@ | ||
| class Calculator { | ||
| import java.util.Scanner; | ||
|
|
||
| int friendsCount; | ||
| public class Calculator { | ||
|
|
||
| String cart = "Добавленные товары:"; | ||
| double totalPrice = 0; | ||
| public void calculator() { | ||
| Products list = new Products(); | ||
| double price = list.Price(); | ||
| Guests Guests = new Guests(); | ||
| int peopleAmount = Guests.peopleAmount(); | ||
|
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. Поскольку peopleAmount и Price - статические методы, их можно вызывать так - Guests.peopleAmount() и Products.Price(), тогда переменные list и Guests не нужны |
||
|
|
||
| Calculator(int friendsCount) { | ||
| this.friendsCount = friendsCount; | ||
| double score = price / peopleAmount; | ||
| String finalPriсe = "Общая сумма составила %.2f "; | ||
| String Deal = "\nКаждый человек должен заплатить %.2f "; | ||
| System.out.println(String.format(finalPriсe, price) + endWord(price) + "." + String.format(Deal, score) + endWord(score) + "."); | ||
| } | ||
|
|
||
| void addItem(Item item) { | ||
| totalPrice += item.price; | ||
| cart = cart + "\n" + item.name; | ||
|
|
||
| System.out.println(item.name + " в корзине"); | ||
| } | ||
|
|
||
| double divideSum() { | ||
| return totalPrice / friendsCount; | ||
| public String endWord(double a) { | ||
| int cur = (int) Math.floor(a); | ||
| if (cur % 100 > 5 && cur <= 20) { | ||
|
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. Во второй части сравнивать нужно тоже cur % 100 |
||
| return "рублей"; | ||
| } else if (cur % 10 == 1) { | ||
| return "рубль"; | ||
| } else if (cur % 10 > 1 && cur % 10 < 5) { | ||
|
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. Выражение |
||
| return "рубля"; | ||
| } | ||
| return "рублей"; | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Guests { | ||
| static int peopleAmount; | ||
| public static int peopleAmount() | ||
| { | ||
| return peopleAmount; | ||
| } | ||
| public static void guests(){ | ||
| System.out.println("Добрейший вечерочек"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("На скольких человек разделить счет?"); | ||
|
|
||
|
|
||
| while (true) { | ||
|
|
||
| if (scanner.hasNextInt()) { | ||
| peopleAmount = scanner.nextInt(); | ||
| if (peopleAmount > 1) { | ||
| break; | ||
| } | ||
| if (peopleAmount <= 1) { | ||
| System.out.println("Некорректое число, пожалуйста введите число больше 1"); | ||
| } | ||
| } else{ | ||
| System.out.println("Некорректный запрос, пожалуйста введите число больше 1"); | ||
| scanner.nextLine(); | ||
|
|
||
| } | ||
| } | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Products { | ||
|
|
||
| static double Price; | ||
| static double Price() | ||
|
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. Названия методов и переменных пишутся с маленькой буквы, только классы - с большой. Лучше методы называть глаголами, отвечая на вопрос, что он делает |
||
| { | ||
| return Price; | ||
| } | ||
|
|
||
| public static void products() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| String names = ""; | ||
|
|
||
| while (true) { | ||
| System.out.println("Введите наименование товара:"); | ||
| String name = scanner.next(); | ||
| names += "Продукт: " + name + "." + " Стоимость: "; | ||
| double price; | ||
| while (true) { | ||
| System.out.println("Введите стоимость товара в формате \"рубли,копейки\":"); | ||
| price = scanner.nextDouble(); | ||
|
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. Пользователь может ввести на вопрос про стоимость товаров вместо числа строку. Для количества человек ты обрабатываешь такую ситуацию через hasNextInt, стоит добавить обработку и для стоимости |
||
|
|
||
| if (price <=0) { | ||
| System.out.println("Некорректное значение. Попробуйте еще раз."); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| names += price + ".\n"; | ||
| Price += price; | ||
|
|
||
| System.out.println("Товар добавлен в список!"); | ||
| System.out.println("Если хотите добавить еще товар, введите \"Да\".\nЕсли хотите завершить покупку, введите \"Завершить\"."); | ||
| String add = scanner.next(); | ||
| if (add.equalsIgnoreCase("да")) { } | ||
|
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. Поскольку тело if пустое, можно этот if вообще убрать |
||
| if (add.equalsIgnoreCase("Завершить")) { | ||
| System.out.println("Добавленные товары:\n" + names); | ||
| break; | ||
| } | ||
| else; | ||
|
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 тоже нет необходимости
Owner
Author
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. Извините не могу изменить рекомендательные микромоменты потому что я на ужасных стрессах от того факта что появились 2 непонятных для меня класса которых у меня никогда в жизни не было Formatter и Item. А у меня закрыт доступ ко 2рой проектной работе которую надо сделать за 2 дня и сдать |
||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
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.
Методы лучше стараться называть глаголами, а вот классы можно существительными