Skip to content

Калькулятор блюд - #1

Open
EidAbdel wants to merge 1 commit into
mainfrom
dev
Open

EidAbdel wants to merge 1 commit into
mainfrom
dev

Conversation

@EidAbdel

Copy link
Copy Markdown
Owner

No description provided.

this.dishesArr.add(dish);
}

public float getAmout(){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Опечатка, должно быть Amount

nit

import java.util.Objects;
import java.util.Scanner;

public class CalculateDishes {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Классы лучше называть существительными и функции глаголами. То есть, например, класс DishCalculator может иметь метод calculate()

Comment on lines +7 to +11
private ArrayList<Dish> dishesArr = new ArrayList<>();

public ArrayList<Dish> getDishesArr() {
return dishesArr;
}

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 on lines +13 to +23
public int getCountPeople() {
return this.countPeople;
}

public void setCountPeople(int countPeople) {
this.countPeople = countPeople;
}

public void addDish(Dish dish) {
this.dishesArr.add(dish);
}

@kekulta kekulta May 16, 2024 •

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 on lines +47 to +55
@Override
public String toString() {
String messenger = "Добавленные товары:\n";
for (Dish dish : this.dishesArr){
messenger = messenger + dish.getName() +'\n';
}
return messenger;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно было бы сделать отдельной функцией, не toString. toString скорее используется чтобы показать какое-то внутреннее состояние объекта, например, для логов. Здесь же мы хотим получить текст конкретного форматирования для показа пользователю.

Comment thread src/main/java/Main.java
} else {
try {
System.out.println("Ведите наименование блюда:");
String dishName = new Scanner(System.in).nextLine().trim();

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
query = new Scanner(System.in).nextLine();
}
} catch (NumberFormatException e) {
System.out.println("Некорректное цена, блюдо не был добавлен!");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Опечатка: НекорректнАЯ цена, блюдо не былО добавленО!

nit

else if (val%10==1) s="рубль";
else if (new ArrayList<Integer>(Arrays.asList(2,3,4)).contains(val%10)) s="рубля";
else s="рублей";
System.out.println(String.format("Каждый из друзей должен заплатить %.2f %s", num, s));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

String.format() здесь лишний, println сам по себе работает как format.

Comment on lines +9 to +12
if (val>=5 && val%100<=20) s="рублей";
else if (val%10==1) s="рубль";
else if (new ArrayList<Integer>(Arrays.asList(2,3,4)).contains(val%10)) s="рубля";
else s="рублей";

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 вместо каскадного if-else. Но алгоритм работает, молодец!

import java.util.ArrayList;
import java.util.Arrays;

public class printFormatRub {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Имена классов должны начинаться с большой буквы и писаться UpperCamelCase. И как я писал выше, лучше чтобы это было существительное. В данном случае можно назвать, например, RubFormatter.

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