-
Notifications
You must be signed in to change notification settings - Fork 0
консольное приложение калькулятор #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/main/java/Product.java
Outdated
| String name; | ||
| double cost; | ||
|
|
||
| Product(String name , double cost) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍏 Классно, что ты создал специальный класс для описания продукта!
Обычно в java при создании кастомного класса, используемого для описания и хранения данных о каком-то объекте, переопределяются методы equals и hashcode. Они важны для сравнения объектов. Подробнее можно почитать, например, здесь:
https://javarush.com/groups/posts/2179-metodih-equals--hashcode-praktika-ispoljhzovanija
src/main/java/FormatterRub.java
Outdated
| @@ -0,0 +1,20 @@ | |||
| public class FormatterRub { | |||
|
|
|||
| public String correctEnding(double value) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Текущее решение не подходит, например, для 21, 34 и т.п.
src/main/java/Calculator.java
Outdated
|
|
||
| public class Calculator { | ||
| double sum; | ||
| Scanner scaner = new Scanner(System.in); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍏 Поля, которые используются только внутри класса, лучше делать приватными, чтобы их нельзя было изменить снаружи:
| Scanner scaner = new Scanner(System.in); | |
| private double sum; | |
| private Scanner scaner = new Scanner(System.in); |
src/main/java/Calculator.java
Outdated
| ArrayList<Product> products = new ArrayList<>(); | ||
|
|
||
|
|
||
| private String IputName() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍏 В java принято именовать методы в стиле camelCase - с маленькой буквы:
| private String IputName() | |
| private String inputName() |
src/main/java/Calculator.java
Outdated
|
|
||
| public void ShowProducts() | ||
| { | ||
| FormatterRub f = new FormatterRub();//для форматирования окончания рубля |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍏 Рекомендую давать переменным развернутые названия, это облегчает чтение кода:
| FormatterRub f = new FormatterRub();//для форматирования окончания рубля | |
| FormatterRub formatter = new FormatterRub(); |
src/main/java/Calculator.java
Outdated
| System.out.println("Добавленные товары:"); | ||
| for (Product product : products) | ||
| { | ||
| System.out.println("Товар: " + product.name + " цена: " + product.cost + " " + f.correctEnding(product.cost)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍏 При печати в памяти будут создаваться промежуточные строки из-за использования оператора "+". Можно использовать StringBuilder, который сформирует только результирующую строку, или String.format.
https://javarush.com/quests/lectures/questmultithreading.level02.lecture06
https://habr.com/ru/articles/260767/
изменены рекомендации форматирование
изменены рекомендации форматирование
для Product переопределены equals и hashCode
|
Добрый вечер. случайно опять отправил ссылку на гит а не на ПР #1
|
No description provided.