Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 125 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,132 @@
import java.util.Scanner;

// dev branch for Y.Practicum
public class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Введите количество гостей");
int guestNum ;


while (true){
while (!scanner.hasNextInt()){
scanner.next();
System.out.println("Введите количетсво гостей числом!!!");

}
int guests =scanner.nextInt();
if (guests>1){
System.out.println("Количество гостей = "+guests);
guestNum =guests;
break;
}
if (guests==1){
System.out.println("Нет смысла ничего считать и делить.\nВведите корректное количество гостей");
}
else {
System.out.println("Введите корректное количество гостей");

}
}


while (true){
System.out.println("Введите название товара ");
String good =scanner.next();
if (good.equalsIgnoreCase("завершить")){
break;
}//111
else{
System.out.println("Введите цену для "+good+" в формате \"рубли,копейки\"");

while (true){
while (!scanner.hasNextDouble()){
scanner.next();
System.out.println("Введите цену в правильном формате!!!");
}

double price = scanner.nextDouble();
if (price<=0){
System.out.println("Цена не может быть отрицательной,введите корректную цену");
}else{
Goods.add(good,price);
System.out.println(good+" Успешно добавлен");
Goods.check();
System.out.println("Хотите добавить еще один товар? Для окончания покупки напечайте \"Завершить\" ");
break;
}
}

}




}
Goods.check();
double payEach =Goods.priceTotal/guestNum;


System.out.println("Сумма к оплате каждого гостя: "+payEach+" "+Convert.ending(payEach));






Comment on lines +72 to +77

Choose a reason for hiding this comment

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

🍏 Лучше не оставлять пустые строки, лишние комментарии для компактности

// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");

}
}

class Goods {

static String goodsList="";
static Double priceTotal=0.0;


static void add(String name, double priceName){
String rubName =Convert.ending(priceName);
goodsList=goodsList+"\n"+name+" "+"Цена: "+priceName+" "+rubName;
priceTotal+=priceName;

}
static void check(){
System.out.println("Добавленные товары: "+goodsList);
System.out.println("ОБщая сумма: "+priceTotal+" "+Convert.ending(priceTotal));
if (priceTotal ==0&&goodsList.equals("")){System.out.println("Вы не выбрали товар");}//1111

Choose a reason for hiding this comment

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

А вот это полезное сообщение. Не все об этом заботятся) 👍

}


}

class Convert {

static String ending(double number){

double numRound = Math.floor(number);
double leftOver= Math.floor(numRound)%10;
if(Math.floor(numRound)%100>=11&&Math.floor(numRound)%100<=19){
Comment on lines +109 to +111

Choose a reason for hiding this comment

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

🍏 Можно же один раз округлить (и в идеале привести к целочисленному типу) int numRound = (int) Math.floor(number)

Затем уже использовать в проверках
if(numRound %100>=11&&numRound %100<=19)

return "рублей";
}
else{
if(leftOver==1){
return "рубль";
}
else if (leftOver>=2&&leftOver<=4){
return "рубля";
}
else if (leftOver>=5&&leftOver<=9){
return "рублей";
}else{
return "рублей";
}
Comment on lines +113 to +125

Choose a reason for hiding this comment

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

🍏 Можно использовать автоформатирование, чтобы должным образом выровнять отступы
Комбинации клавиш:
Windows: Ctrl + Alt + L
Linux: Ctrl + Shift + Alt + L
macOS: Option + Command + L

Copy link
Owner Author

@Bugrov1 Bugrov1 Feb 15, 2023

Choose a reason for hiding this comment

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

Спасибо. Это полезно для меня будет.

}

}



}