Repository navigation
Первая проектная работа - #1
Open
AlexandraRik wants to merge 3 commits into
Open
AlexandraRik wants to merge 3 commits into
AlexandraRik wants to merge 3 commits into
Conversation
| Dish.sum += price; | ||
| System.out.println("Товар успешно добавлен!\nНужно записать еще одно блюдо? Да/Завершить"); | ||
| String answer = scanner.next(); | ||
| if (answer.equalsIgnoreCase(stopWord) == true) { |
There was a problem hiding this comment.
Необязательно проверять на равенство true/false.
Можно и так записать
if (answer.equalsIgnoreCase(stopWord)) {
break;
}
Comment on lines
+67
to
+74
| static double sum = 0; // Переменная для итоговой суммы счета | ||
| static String products=""; //Переменная для списка продуктов | ||
|
|
||
| Dish(String nameOfProducts, double sumOfProducts){ | ||
| sum = sumOfProducts; | ||
| products = nameOfProducts; | ||
|
|
||
| } |
There was a problem hiding this comment.
Если переменные статичные и открытые, то нет смысла присваивать им значение через конструктор. Да и в целом нет смысла от конструктора - он все равно не используется.
Или, если все же использовать конструктор, для создания объекта класса Dish и присваивания первичных значений, то эти переменные можно объявить как приватные и не статичные. А доступ к записи и чтению их значений, обеспечить дополнительными методами. Так будет наиболее корректно
Например
class Dish{
private double sum = 0; // Переменная для итоговой суммы счета
private String products=""; //Переменная для списка продуктов
Dish(String nameOfProducts, double sumOfProducts){
sum = sumOfProducts;
products = nameOfProducts;
}
public double getSum() {
return sum;
}
public void setSum(double sum) {
this.sum = sum;
}
public String getProducts() {
return products;
}
public void setProducts(String products) {
this.products = products;
}
}
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.
Первая практическая задача Яндекс.Практикум
Деление счета по гостям