Skip to content

Первая домашка: 4 попытка - #1

Open
ShKeril wants to merge 5 commits into
mainfrom
dev
Open

ShKeril wants to merge 5 commits into
mainfrom
dev

Conversation

@ShKeril

@ShKeril ShKeril commented Nov 7, 2023

Copy link
Copy Markdown
Owner

No description provided.

@ShKeril

ShKeril commented Nov 7, 2023

Copy link
Copy Markdown
Owner Author

Не знаю можно ли предыдущие комиты удалить да и нужно ли

@ShKeril

ShKeril commented Nov 7, 2023

Copy link
Copy Markdown
Owner Author
  1. Обработка некорректных данных - честно говоря думал что функция NextInt() NextFloat() как бы подразумевают такую проверку иначе они мало чем отличаются от nextLine(). Ощущение что эти функции недоделаны
  2. По второму пункту сделал двойное деление по модулю вместо проверки диапазона. результат тот же но красивее

Comment thread src/main/java/Main.java Outdated
}
}

class Calculation {

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 принято каждый класс располагать в отдельном файле

Comment thread src/main/java/Main.java Outdated

Calculation calculation = new Calculation(numberPersons);

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/Main.java Outdated
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
public void main(String[] args) {

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 void main(String[] args) {
public static void main(String[] args) {

https://javarush.com/groups/posts/modifikator-static-java

Comment thread src/main/java/Main.java Outdated
} else {
while (true) {
if (scanner.hasNextDouble()) {
double amount = scanner.nextDouble();

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
double amount = scanner.nextDouble();
double price = scanner.nextDouble();

Comment thread src/main/java/Main.java

System.out.println("На сколько человек необходимо разделить счёт?");

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.

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

Comment thread src/main/java/Main.java Outdated
while (true) {
if (scanner.hasNextDouble()) {
double amount = scanner.nextDouble();
if (amount > 1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Товар может стоить и рубль, я бы предложила использовать сравнение с 0

Comment thread src/main/java/Main.java

System.out.println("Введите название товара и его стоимость");

while (true) {

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 Outdated

class Calculation {

String productList = "Добавленные товары:";

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/Main.java Outdated
break;
}

return String.format("%.2f", result) + ending;

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
return String.format("%.2f", result) + ending;
return String.format("%.2f %s", result, ending);

Comment thread src/main/java/Calculation.java Outdated
}

public void addProduct(String product, double price) {
productList = productList + "\n" + String.format("%s стоимость: %.2f %s", product, price, getEnding(price));

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
productList = productList + "\n" + String.format("%s стоимость: %.2f %s", product, price, getEnding(price));
productList = String.format("%s\n%s стоимость: %.2f %s", productList, product, price, getEnding(price));

Comment thread src/main/java/Main.java Outdated
System.out.println("Введите стоимость товара (руб,коп).");
try {
double price = scanner.nextDouble();
if (price > 1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Числа, больше 0 до 1 включительно тоже сичтаются положительными, и может быть товар с ценой в 1 рубль или 50 копеек

@ShKeril ShKeril changed the title Первая домашка: 2 попытка Первая домашка: 4 попытка Nov 11, 2023
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