Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

commit HW#1

Open
solo300m wants to merge 3 commits intomain from
dev
Open

commit HW #1
solo300m wants to merge 3 commits intomain from
dev

Conversation

@solo300m
Copy link
Owner

@solo300m solo300m commented Aug 21, 2023

Это Pull Request задачи 2 спринта.

import java.util.List;

public class Calculator {
private List<Product>list = new ArrayList<Product>();
Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

Список продуктов может быть final, так как нигде не изменяет своего значения (то есть не присваивается новый список)

Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

Также можно не указвать явно тип два раза, то есть если слева уже указан , то справа это можно опустить, чтобы сделать код более лакончиным

return ((double)Math.round(sum * 100)) / 100;
}
public double calcPastPay(){
if(this.person > 0)
Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

По идее эта проверка всегда будет true, так как в программе еще до этого проверяется, что количество больше нуля. Но в целом имеет место быть)

System.out.println("На сколько персон необходимо поделить счет: ");
Scanner scanner = new Scanner(System.in);
int countPerson = 0;
// String nameProduct = "";
Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

Можно смело удалять неиспользуемые строки, они только ухудшают восприятие кода)

System.out.println("Количество человек не может быть отрицательным или равным нулю!");
}else if(countPerson == 1){
System.out.println("Нет смысла в работе программы при количестве персон равном 0");
}else {
Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

Все, что в этом else, можно было бы вынести в отдельный метод, чтобы немного разгрузить main, а также чтобы не было сильной вложенности кода. (сначала в if, потом в while, это создает лишние отступы)

boolean check = false;
String strPrice = "";
while (!check) {
System.out.print("-> ");
Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

Здесь можно было бы дописать текст, что программа ждет ввода стоимости продукта, это было бы немного более юзер френдли

}
}
price = Double.parseDouble(strPrice);
Product product = new Product(tmp,price);
Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

Этот объект нигде не используется, так как ниже строчкой создается точно такой же новый

rez = true;
}else if(i == '.'){
countPoint++;
}else if(!Character.isDigit(i) && i != '.'){
Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

Условие i != '.' всегда будет true, так как оно проверяется на один if выше. i равное точке никогда не дойдет до этого ифа, можно смело удалять. Аналогичная история и с !Character.isDigit(i). Поэтому этот блок можно сделать просто через else, без if

}
if(countPoint <= 1){
return rez;
}else{
Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

Здесь можно пропустить else:

if (countPoint > 1) {
 rez = false;
}
return rez;

this.price = price;
}

public String getName() {
Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

Можно не создавать геттеров и сеттеров, если они не требуются извне. Из всех здесь и ниже, понадобился лишь getPrice

// String nameProduct = "";
double price = 0.0;
String next = "";
Calculator calc = null;
Copy link

@Anna-Malinina Anna-Malinina Aug 22, 2023

Choose a reason for hiding this comment

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

Необязательно писать инициализаторы явно. По умолчанию double имет значение 0, строка и объект null


Calculator calc = null;

countPerson = scanner.nextInt();
Copy link

@Anna-Malinina Anna-Malinina Aug 24, 2023

Choose a reason for hiding this comment

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

В этом месте стоило бы выполнять проверку с помощью метода scanner.nextInt(), который возвращает булевое значение в зависимости от того, сможет ли он введенное число распознать как инт или нет. Либо использовать блок try-catch. Тогда не будет такого краша:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@Anna-Malinina Anna-Malinina Anna-Malinina left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /