Skip to content
Closed
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions src/main/java/GetRubleAddition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Rubles {
public static String GetRubleAddition(int num) {
int preLastDigit = num % 100 / 10;
if (preLastDigit == 1) {
return "рублей";
}
switch (num % 10) {
case 1:
return "рубль";
case 2:
case 3:
case 4:
return "рубля";
default:
return "рублей";
}
}
}
36 changes: 36 additions & 0 deletions src/main/java/GroceryList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.Scanner;

class GroceryList {

public static double Product(Scanner nameProduct) {

double sum = 0.0;
StringBuilder products = new StringBuilder(("Добавить блюда")); //Обьявить блюда

while (true) {
String name;
System.out.println("Введите название блюда. Либо напишите 'Завершить'."); // Ввести название блюда
name = nameProduct.next();

if (name.equalsIgnoreCase("Завершить")) { //Подсчет итога
System.out.println(products);
break;
}

double price;
System.out.println("Введите стоимость блюда"); // Ввести стоимость
while (!nameProduct.hasNextDouble()) {
System.out.println("Введите стоимость блюда в формате: 11,11");
nameProduct.next();
}
price = nameProduct.nextDouble();

if (price > 0) {
products.append("\n").append(name).append(" по цене ").append(price);
sum += price;
System.out.println("Блюдо добавлено");
}
}
return sum;
}
}
31 changes: 26 additions & 5 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
// dev branch for Y.Practicum
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
Scanner scanner = new Scanner(System.in);
System.out.println("На сколько персон разделить счет?"); //Количество людей

while (true) {
if (!scanner.hasNextInt()) {
System.out.println("Введите целое число.");
scanner.next();
}
int people = scanner.nextInt();
if (people == 1) {
System.out.println("Хотите разделить свою еду?\nДобавьте больше людей!");
}
if (people < 1) {
System.out.println("Неправильное количество!\nВведите положительное целое число!");
}
if (people > 1) {
System.out.println("Давайте подсчитаем!");
Double value = GroceryList.Product(scanner) / people;
String result = String.format("%.2f", value);
System.out.println("Сумма с человека: " + result + " " + Rubles.GetRubleAddition((int) Math.floor(value)));
break;
}
}
}
}
}