Skip to content

Калькулятор меню 2.0, по правкам#2

Open
wpwpwpwp wants to merge 5 commits intomainfrom
master
Open

Калькулятор меню 2.0, по правкам#2
wpwpwpwp wants to merge 5 commits intomainfrom
master

Conversation

@wpwpwpwp
Copy link
Owner

No description provided.

totalList = totalList + "\n" + productName;
price = scanPrice.nextFloat();
totalPrice = totalPrice + price;
System.out.println("Вы успешно добавили товар " + productName + " стоимостью: " + price + ". Вы хотите добавить что-то ещё?");

Choose a reason for hiding this comment

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

Тут лучше дописать "Введите Завершить, чтобы закончить ввод", иначе пользователь не поймёт, что следует ввести для выхода

case 13:
case 12:
case 14:
rublWord = "рублей";

Choose a reason for hiding this comment

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

Поскольку в if выше мы уже определяем окончание только для чисел 11-14, switch и даже переменную rubli можно убрать, оставив только строчку rublWord = "рублей";

case 7:
case 8:
case 9:
case 0:

Choose a reason for hiding this comment

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

Cлучаи с 5 до 0 можно объединить, написав просто default

}
}
System.out.println("Добавленные товары: " + totalList + "\nИтоговая цена в рублях: " + totalPrice);
System.out.println("Каждый человек должен заплатить: "+String.format("%.2f",finalPrice)+" "+rublWord); }

Choose a reason for hiding this comment

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

Молодец, что не дублируешь этот код, оставив в switch только определение окончания слово рубль, это хорошее решение

totalPrice = totalPrice + price;
System.out.println("Вы успешно добавили товар " + productName + " стоимостью: " + price + ". Вы хотите добавить что-то ещё?");
finalPrice = totalPrice / howPeople;
if ((int) finalPrice % 100 >= 11 && (int) finalPrice % 100 <= 14) {

Choose a reason for hiding this comment

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

Можно код для определения окончания слова рубль вынести в отдельную функцию, тогда её можно будет использовать ещё и при выводе Итоговой цены в рублях, и даже стоимости товара

int howManyPeople = 1;
Calculate calculator = new Calculate();
System.out.println("На сколько человек необходимо разделить счет?");
while (true) {

Choose a reason for hiding this comment

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

Можно отформатировать код, в студии в выбранном файле сверху вкладка Code - Reformat Code, либо Ctrl+Alt+L, тогда автоматически код выправится, проставятся правильные отступы

}
else {
howManyPeople = scanner.nextInt();
{

Choose a reason for hiding this comment

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

Эта скобка и её пара - лишние, можно удалить

} else {
System.out.println("Неверное количество друзей. Значение должно быть болье единицы, давайте попробуем еще раз.");
}
int howManyPeople = 1;

Choose a reason for hiding this comment

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

Значение 1 не используется, можно его здесь не инициализировать

while (true) {
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextInt() == false) {
howManyPeople = -1;

Choose a reason for hiding this comment

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

В твоей реализации можно эту строчку убрать, поскольку проверка howManyPeople < 1 будет выполнена только в случае scanner.hasNextInt() == false

System.out.println("На сколько человек необходимо разделить счет?");
while (true) {
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextInt() == false) {

Choose a reason for hiding this comment

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

Можно писать вместо scanner.hasNextInt() == false просто !scanner.hasNextInt()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants