Skip to content

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

Open
ralvveo wants to merge 1 commit intomainfrom
dev
Open

Калькулятор консольное приложение #1#1
ralvveo wants to merge 1 commit intomainfrom
dev

Conversation

@ralvveo
Copy link
Copy Markdown
Owner

@ralvveo ralvveo commented Sep 9, 2023

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



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("Введите корректную цену товара!");

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)

//Поиск правильного окончания слова рубль
public static String checkCorrectLetter(int OGS){
int temp = OGS % 100;
if (temp % 10 == 1 && temp != 11)
Copy link
Copy Markdown

@nasibullin1412 nasibullin1412 Sep 9, 2023

Choose a reason for hiding this comment

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

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

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 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