Skip to content

Практическая работа №1 "Консольное приложение" - #87

Open
GrachevAl wants to merge 1 commit into
Yandex-Practicum:masterfrom
GrachevAl:master
Open

GrachevAl wants to merge 1 commit into
Yandex-Practicum:masterfrom
GrachevAl:master

Conversation

@GrachevAl

Copy link
Copy Markdown

No description provided.

static ArrayList<Double> price = new ArrayList<>();
static double score = 0;

public static void calculate() {

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 можно убрать, поскольку ты вызываешь метод от создаваемого объекта класса Calculate

import java.util.Scanner;

public class Calculate {
static Const aConst=new Const();

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 лучше убрать у всех полей и методов класса, необходимости в них нет

//блок заполнения листа и подсчета счета
System.out.println(aConst.ADD_PRODUCT_AND_PRICE);
String nameProduct = scanner.next();//название продукта
Double priceProduct = 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.

Пользователь может ввести на вопрос про стоимость товаров вместо числа строку. Для количества человек ты обрабатываешь такую ситуацию через hasNextInt, стоит добавить обработку и для стоимости

{
System.out.println("Вы ввели не целое число");
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.

Можешь применить в студии автоформатирование (в выбранном файле, сверху вкладка Code - Reformat Code, либо Ctrl+Alt+L), тогда автоматически код выправится.

System.out.printf("Каждый должен заплатить: %.2f Рубля%n",score1);
break;
default:
System.out.printf("Каждый должен заплатить: %.2f Рублей%n",score1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Код System.out.printf("Каждый должен заплатить: %.2f <...> %n",score1); повторяется, лучше его вынести за if-else, оставив только определение слова (можно записывать в переменную)

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