Skip to content

Conversation

@SvetlanaIlchenko
Copy link
Owner

No description provided.

Copy link

@SeveNChaK SeveNChaK left a comment

Choose a reason for hiding this comment

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

В файлах код прыгает, отступы не одинаковые - рекомендую использовать встроенные форматтер. Если ты программируешь в IDE от JetBrains, то можешь пройтись по всем файлам и нажать комбинацию (Windows: Shift + Ctrl + Alt + L, MacOS: Shift + Option + Command + L), затем выбрать, какую часть кода хочешь изменить, и выполнить команду. Среда разработки автоматически сделает нужные отступы и переносы (как она это делает можно изменить в настройках, но дефолтные значения вполне нормальные).

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Scanner scanner = new Scanner(System.in);

Choose a reason for hiding this comment

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

⏫ Переменная не используется, ее можно удалить

product.nameRequest1();
product.checkingThePrice();
product.nameRequest2();
String transfer = "\n";

Choose a reason for hiding this comment

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

⏫ Тоже не используется

import java.util.Scanner;

public class Calculator {
String name1;

Choose a reason for hiding this comment

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

⏫ Неинформативное название, рекомендую назвать, например, productNames

public class Calculator {
String name1;
String name2;
double price1;

Choose a reason for hiding this comment

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

⏫ Неинформативное название, рекомендую назвать, например, priceSum


public class Calculator {
String name1;
String name2;

Choose a reason for hiding this comment

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

⏫ Можно не делать полем класса, так как переменная используется только внутри метода nameRequest2, поэтмоу ее можно объявлять там внутри

String name1;
String name2;
double price1;
double price2;

Choose a reason for hiding this comment

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

⏫ Можно не делать полем класса, так как переменная используется только внутри метода checkingThePrice, поэтмоу ее можно объявлять там внутри

if (name2.equalsIgnoreCase("завершить")){
break;
} else {
name1 = name1 + ", " + transfer + name2;

Choose a reason for hiding this comment

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

⏫ Так как String является неизменяемым объектом, то при каждом сложении строк создаются новые объекты, что расходует память. Для таких случаев лучше использовать StringBuilder

void checkingThePrice() {
while (true) {
System.out.println("Введите стоимость товара");
price2 = scanner.nextDouble();

Choose a reason for hiding this comment

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

⚠️ Не хватает проверок на некорректный ввод, поэтмоу приложение падает, если ввести строку или не в том формате. Можно использовать scanner.hasNextDouble() для проверки, перед чтением nextDouble().


while (true) {
System.out.println("На скольких человек необходимо разделить счет?");
countPersons = scanner.nextInt();

Choose a reason for hiding this comment

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

⚠️ Тут тоже не хваатет првоерки на некорректный ввод. Можно использовать scanner.hasNextInt()


void formatter() {
Person count = new Person();
Calculator calculator = new Calculator();

Choose a reason for hiding this comment

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

⚠️ Из-за того, что ты создаешь здесь новые экемпляры классов Person и Calculator, в них нет посчитанных ранее тобой данных, поэтому склоняется не правильно.
Лучше нужное число передать параметром на вход метода, а результат вернуть сразу из метода, а не записывать в переменную: String formatter(double priceOnEachPerson) { ... }.
Полученный double можно привести к int: int priceInt = (int) double;.
А потом уже проверять priceInt твоим условием, но в switch надо поправить на switch (priceInt % 10)

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