Skip to content

Rychkov PW1 - #84

Open
Saharok1209 wants to merge 4 commits into
Yandex-Practicum:masterfrom
Saharok1209:master
Open

Saharok1209 wants to merge 4 commits into
Yandex-Practicum:masterfrom
Saharok1209:master

Conversation

@Saharok1209

Copy link
Copy Markdown

Привет, это моя проектная работа№1

public String calculationNameProduct(){
for (int i = 0; i < product.getNameProduct().size(); i++) {
allProducts = allProducts + " " + product.getNameProduct().get(i);
}return allProducts;

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), тогда автоматически код выправится

Comment thread src/main/java/Main.java
System.out.println("Your price per guest: " + calculation.calculationPriceProduct() / people + " 'rubles.penni'");

}
public static int people(){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Студия подсказывает, что возвращаемый тип функции никак не используется, тогда можно его убрать, или всё-таки использовать. Методы лучше называть с глаголом, например, readPeople или getPeople (это если возвращаемый результат будет использоваться)

Comment thread src/main/java/Main.java
}
return people;
}
public static Product addProduct(){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Студия подсказывает, что возвращаемый тип функции никак не используется, тогда можно его убрать, или всё-таки использовать

@@ -0,0 +1,22 @@
import java.util.ArrayList;

public class Product {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Класс содержит информацию не о продукте, а обо всех продуктах, так что можно назвать его Menu или хотя бы Products

import java.util.ArrayList;

public class Product {
static ArrayList<String> nameProduct = new ArrayList<>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Поскольку в этой переменной хранится не имя одного продукта, а все продукты, лучше ее назвать productNames


public class Product {
static ArrayList<String> nameProduct = new ArrayList<>();
static ArrayList<Double> priceProduct = new ArrayList<>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Аналогично с nameProduct

Product.priceProduct.add(priceProduct);
}

public ArrayList<String> getNameProduct() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Методы возвращают список имен продуктов, поэтому тоже лучше переименовать понятнее

Comment thread src/main/java/Main.java
}
}else{
System.out.println("invalid input");
scan.nextInt();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Здесь нужен просто scan.next();, иначе приложение упадет, поскольку мы проверили, что !scan.hasNextInt()

Comment thread src/main/java/Main.java

if(Math.round(productPrice)%10 == 1 && Math.round(productPrice)%100 != 11){
return "ruble";
}else if((Math.round(productPrice)%10) <= 4 && (Math.round(productPrice)%100 >= 2) && (Math.round(productPrice)%100)/10 != 2){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Повторяющийся код Math.round(productPrice) и Math.round(productPrice)%10, Math.round(productPrice)%100 можно вынести в переменные

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