Repository navigation
Conversation
faritowich
reviewed
Jan 8, 2024
| if(str.equalsIgnoreCase("Да")) { | ||
| calculator.addProduct(); | ||
| } | ||
| } |
There was a problem hiding this comment.
По хорошему надо выносить всю логику из класса Main. Этот класс обычно призван только стартануть программу, а все остальное должно быть сделано в специальных классах, как сейчас сделано с другими классами
|
|
||
| public class Formater { | ||
|
|
||
| Scanner scanner = new Scanner(System.in); |
| private int numberOfPeople; | ||
| private double totalCost = 0; | ||
| private ArrayList<String> listOfProducts; | ||
| private ArrayList<Double> costOfProducts; |
There was a problem hiding this comment.
numberOfPeople, listOfProducts и costOfProducts - final
Owner
Author
|
Вынес из main все действия. Оставил только создание класса Calcualtor и его метод void start(), который запускает программу. Так же доработал метод checkRes(double) в классе Formater. До этого программа неправильно выводило слово для чисел оканчивающихся на 11-14. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Добавил класс Calculator, в котором хранятся общая цена, количество людей, список товаров и список их цен:
double totalCost, int numberOfPeople, ArrayList listOfProducts, ArrayList costOfProducts.
Записан метод show(), который выводит все товары и итоговую сумму, которую должен оплатить каждый из людей.
Методы addProduct() и addProductCost() записывают название продукта и его цену соответственно.
Добавлен так же класс Formater с методами scanInt(), scanDouble(), checkRes() для проверки корректного ввода с консоли целочисленного значения, значения с плавающей точкой и проверкой падежа для слова "рубль" в итоговом выводе.