Skip to content

PR#1 - #1

Open
gen530ts wants to merge 15 commits into
mainfrom
dev
Open

gen530ts wants to merge 15 commits into
mainfrom
dev

Conversation

@gen530ts

Copy link
Copy Markdown
Owner

release1

Comment thread src/main/java/MainCalc.java Outdated
} else {
scanner.next();
}
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.

🍏 Круто было бы подсказать пользователю, какие данные от него ожидаются

Comment thread src/main/java/Calc.java
System.out.println("Товар " + nameProduct + " по цене " + String.format(MainCalc.loc,"%.2f", priceProduct) + " успешно добавлен!");
goodsStr = goodsStr.concat("\n" + nameProduct);
goodsSum += priceProduct;
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.

👏 Круто, что подсказываешь пользователю, как выйти из сценария!

Comment thread src/main/java/Calc.java Outdated
double priceProduct=-1;
System.out.println("Введите название товара:");
String nameProduct= MainCalc.scanner.nextLine();
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.

🍏 Классно было бы подсказать пользователю, в каком формате от него ожидаются данные

Comment thread src/main/java/Calc.java Outdated
priceProduct = MainCalc.scanner.nextDouble();
}
if((priceProduct>0)&&(nameProduct.length()>0)){
System.out.println("Товар " + nameProduct + " по цене " + String.format(MainCalc.loc,"%.2f", priceProduct) + " успешно добавлен!");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 При печати в памяти будут создаваться промежуточные строки из-за использования оператора "+".  Можно использовать StringBuilder, который сформирует только результирующую строку. https://habr.com/ru/articles/260767/

Comment thread src/main/java/MainCalc.java Outdated
import java.util.Scanner;

public class MainCalc {
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.

🍏 Поля, которые хранят какое-то состояние, лучше не делать статическими, чтобы они корректно инициализировались и освобождали ресурсы, когда уже не нужны

Comment thread src/main/java/MainCalc.java Outdated
System.out.println("Введите количество человек");
while (true) {
if (scanner.hasNextInt()) {
int i =scanner.nextInt();

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/MainCalc.java Outdated
while (true) {
if (scanner.hasNextInt()) {
int i =scanner.nextInt();
if(i>1) return i;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Немного поехало форматирование. Для форматирования кода и удаления неиспользуемых импортов применяй следующие сочетания клавиш:
Windows: Control+Alt+L
MacOS: Command+Option+L
Больше горячих клавиш можно найти здесь: https://developer.android.com/studio/intro/keyboard-shortcuts

Comment thread src/main/java/Calc.java
public class Calc {
private double goodsSum;
private final int numPeople;
private String goodsStr = "";

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 с полями name и price. Экземпляры этого класса можно сохранить в список. Это может быть удобно, если тебе в дальнейшем потребуется цена каждого товара.

Comment thread src/main/java/Calc.java Outdated
numPeople = nPeople;
}

private String getOutStr(double sum) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Можно вынести логику форматирования в отдельный класс Formatter, чтобы ее можно было при необходимости использовать в других местах приложения

Comment thread src/main/java/Calc.java Outdated
}else {
System.out.println("Ошибка ввода данных");
MainCalc.scanner.nextLine();
//if(nameProduct.length()<0) MainCalc.scanner.nextLine();

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/MainCalc.java Outdated
public static final Locale loc = new Locale("en", "US");
private static int getInt(){
// public static final Locale loc = new Locale("en", "US");
private static int getInt(Scanner scn){

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