Skip to content

Проектная работа №1 - #1

Open
AGALODEB wants to merge 4 commits into
mainfrom
master
Open

AGALODEB wants to merge 4 commits into
mainfrom
master

Conversation

@AGALODEB

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/main/java/Calculator.java Outdated
public String getItemsAsStr(){
String info = "Добавленные товары: \n";
for (Item item: items){
info = info + item.toString() + "\n";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно использовать конструкцию info += item.toString() + "\n";

Comment thread src/main/java/App.java
import java.lang.Math;
public class App {
Scanner sc = new Scanner(System.in);
Calculator calculator = new 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.

Так как калькулятор один на всю программу, можно сделать его, его методы и поля static,чтобы не нужно было создавать его экземпляр. Тогда можно будет просто вызывать методы напрямую: Calculator:.getSum()

Comment thread src/main/java/App.java
}
else {
template = "%.2f рублей";
}

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

Comment thread src/main/java/App.java Outdated
int peopleCount = sc.nextInt();
if (peopleCount <= 1) {
System.out.println("Колличество человек должно быть больше 1");
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continue завершает итерацию цикла и начинает заново новый этап цикла. Нет смысла ставить continue в конце блока кода - даже без него итерация кода бы закончилась и начался бы новый цикл. IDE выделяет continue и подсказывает, как отрефакторить код

Comment thread src/main/java/App.java Outdated
Item item = new Item(title,price);
calculator.addItem(item);
System.out.println("Товар успешно добавлен");
System.out.println("Если это все продукты, то введите 'exit'");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно объединить два println в один. Перенос строки делается символом \n

Comment thread src/main/java/App.java Outdated
break;
}
else {
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

тоже можно обойтись без continue, потому даже без него итерация завершается в этом моменте. IDE подсвечивает continue и предлагает отрефакторить

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.

3 participants