Skip to content

ПР для проверки задания#1

Open
Aniariy wants to merge 3 commits intomainfrom
dev
Open

ПР для проверки задания#1
Aniariy wants to merge 3 commits intomainfrom
dev

Conversation

@Aniariy
Copy link
Copy Markdown
Owner

@Aniariy Aniariy commented Aug 20, 2023

ПР для проверки и замечаний.

@@ -0,0 +1,19 @@
public class Goods {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно поменять имя класса на более точное

Suggested change
public class Goods {
public class Good {

goods = new ArrayList<Goods>();
}

public void AddGoods() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Названия функций в Java принято писать с маленькой буквы:

Methods should be verbs, in mixed case with
the first letter lowercase, with the first letter of
each internal word capitalized.

Источник - Java Code Conventions https://www.oracle.com/technetwork/java/codeconventions-150003.pdf

Comment on lines +10 to +25
Scanner scanner = new Scanner(System.in);
int input = 0;
while (true){
System.out.print("На сколько человек делим счёт?:");
if (scanner.hasNextInt()) {
input = scanner.nextInt();
if (input > 1) {
guests = input;
break;
}
else System.out.println("Значение должно быть больше 1");
}
else System.out.println("Значение некорректно!!!");
String buf = scanner.nextLine();
}
goods = new ArrayList<Goods>();
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.print("Введите цену:");
if (scanner.hasNextDouble()) {
price = scanner.nextDouble();
if (price >= 0.00) break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Сравнение чисел с плавающей запятой лучше делать через специальные методы для сравнения таких чисел, например Double.compare() - https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#compare-double-double-

private int guests;
private ArrayList<Goods> goods;

public Calculator(){
Copy link
Copy Markdown

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), тогда автоматически код выправится

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