Skip to content

Калькулятор консольное приложение #1 - #1

Open
ralvveo wants to merge 1 commit into
mainfrom
dev
Open

ralvveo wants to merge 1 commit into
mainfrom
dev

Conversation

@ralvveo

@ralvveo ralvveo commented Sep 9, 2023

Copy link
Copy Markdown
Owner

Калькулятор консольное приложение #1

Comment thread src/main/java/Calculator.java


public class Calculator {
public static final Scanner scanner = new Scanner(System.in);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 scanner не используется за пределами класса, значит можно убрать static и поменять модификатор на private

}

//Проверка ввода корректной цены
public static double checkInputPrice(){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏static лучше убрать, советую почитать про static дополнительно

Comment on lines +16 to +17


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Внутри методов лучше не оставлять пустые строки



System.out.println("\nТовар успешно добавлен! \n");
Product prod = new Product(nameOfProduct, priceOfProduct);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏Это поле, как и класс Product больше нигде не используется, значит они не нужны в коде

Comment on lines +36 to +37
if (isDouble(userInput)) {
userInputDouble = Double.parseDouble(userInput);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏Ты 2 раза парсишь Double, лучше так не делать, а перестроить код так, чтобы это пришлось делать только 1 раз, например вытащить код из isDouble сюда и при ошибке выводить сообщение System.out.println("Введите корректную цену товара!");

Comment thread src/main/java/Main.java
int temp = OGS % 100;
if (temp % 10 == 1 && temp != 11)
return "ь";
else if ((temp % 10 == 2 || temp % 10 == 3 || temp % 10 == 4) && (temp != 12 && temp != 13 && temp!= 14))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏(temp % 10 == 2 || temp % 10 == 3 || temp % 10 == 4) эквивалентно (temp % 10 > 0 && temp % 10 < 5), (temp != 12 && temp != 13 && temp!= 14 эквивалентно (temp<12 || temp > 14)

Comment thread src/main/java/Main.java
//Поиск правильного окончания слова рубль
public static String checkCorrectLetter(int OGS){
int temp = OGS % 100;
if (temp % 10 == 1 && temp != 11)

@nasibullin1412 nasibullin1412 Sep 9, 2023 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏Когда много if/else лучше использовать не ifы, а switch

Comment thread src/main/java/Main.java
while (true) {

String userInput = scanner.next();
if (isInt(userInput)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏Тоже самое замечание, что и с isDouble

Comment thread src/main/java/Main.java
Comment on lines +81 to +86






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