Skip to content

Консольное приложение 1 - #1

Open
AndyRvlt wants to merge 3 commits into
mainfrom
dev
Open

AndyRvlt wants to merge 3 commits into
mainfrom
dev

Conversation

@AndyRvlt

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/main/java/Main.java Outdated
Comment on lines +18 to +30
if (Math.floor(endResalts) == 1) {
String endResaltsformat = String.format("%.2f", endResalts);
System.out.println("Итог: " + endResaltsformat + "рубль");

}
else if (Math.floor(endResalts) == 2||Math.floor(endResalts)==3||Math.floor(endResalts) ==4) {
String endResaltsformat = String.format("%.2f", endResalts);
System.out.println("Итог: " + endResaltsformat + "рубля");
}
else if(endResalts >= 5) {
String endResaltsformat = String.format("%.2f", endResalts);
System.out.println("Итог: " + endResaltsformat + " рублей");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

можно заменить с помощью конструкции switch case, для улучшения читаемости кода

Comment thread src/main/java/Main.java


// dev branch for Y.Practicum
public class Main {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Много лишних пустых строк, стоит придерживаться порядка в файлах и код стайла

Comment thread src/main/java/Main.java Outdated

endResalts = menu.allPrice / person.allpersons;

if (Math.floor(endResalts) == 1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

не корректная логика, необходимо проверять последние цифры у чисел, а в твоем случае функция Math.floor() вернет просто целое число, без знаков после запятой. Например Math.floor(51,23) вернет 51 и окончание будет "рублей", а должно быть "рубль"

Comment thread src/main/java/Menu.java
@@ -0,0 +1,46 @@
import java.util.Scanner;

class Menu {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

стоит поправить форматирование, в частности отступы для этого можно использовать хоткей ctrl+alt+L

Comment thread src/main/java/Menu.java Outdated
break;
}
System.out.println("Введите стоимость товара в формате 00,00");
double priceProduct = scan.nextDouble();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

В данном случае приложение упадет, если пользователь введет не число. Можно исправить с помощью конструкции try catch, либо с помощью проверки scan.hasNextDouble()

Comment thread src/main/java/Menu.java Outdated


System.out.println("Товар добавлен в счет. \nТовар: " + product + " Цена: " + priceProduct + "\nЕсли вы хотите продолжить выбор, то введите название товара \nЕсли выхотите завершить выбор товара, то введите команду \"Завершить\"");
allProduct=allProduct + product+"\n";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

можно использовать укороченную запись allproduct += product + "\n"

Comment thread src/main/java/Menu.java Outdated
double priceProduct = scan.nextDouble();
if (priceProduct<0 ){
System.out.println("Не коректно введена стоимость товара. \nВведите стоимость товара в формате 00,00");
priceProduct = scan.nextDouble();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread src/main/java/Person.java

System.out.println("На скольких человек необходимо разделить счёт");
while (true) {
int allperson = scanner.nextInt();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

приложение упадет, если будет не число

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