Skip to content
Open
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
48 changes: 47 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
import java.util.Scanner;


public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Scanner scanner = new Scanner(System.in);
String input = "";
int peopleCount = -1;
while (peopleCount <= 0 ) {
System.out.println("Введите количество гостей");
try {
input = scanner.nextLine();
peopleCount = Integer.parseInt(input);
} catch (Exception error) {
System.out.println("Пожалуйста введите корректное значение");

}
}
System.out.println("Количество человек " + peopleCount);

ProductAndPrice productAndPrice = new ProductAndPrice();
productAndPrice.Calc();

double everyCheck = productAndPrice.calculator / peopleCount;
System.out.println("Каждому нужно заплатить " + String.format("%.2f", everyCheck) + " " + detectSuffix(everyCheck) + ".");
System.out.println(productAndPrice.nameProduct);

}
public static String detectSuffix(double everyCheck) {
String rub = "";
int sumCheck1 = (int) ((Math.floor(everyCheck))%10);
switch (sumCheck1) {
case 1:
rub = "Рубль";
break;
case 2:
case 3:
case 4:
rub = "Рубля";
break;
default:
rub = "Рублей";
break;
}
int sumCheck2 = (int) ((Math.floor(everyCheck))%100);
if (11 <= sumCheck2 & sumCheck2 <= 19) {
rub = "Рублей";
}
return rub;
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/ProductAndPrice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.util.Scanner;

class ProductAndPrice {
public double calculator = 0;
public String nameProduct = "";
String product = "";

public void Calc() {
Scanner scanner = new Scanner(System.in);
String input = "";
while (true) {
System.out.println("Введите название товара");
product = scanner.nextLine();
nameProduct += product + "; \n";
double price = -1;
while (price <= 0) {
System.out.println("Введите стоимость продукта");
try {
input = scanner.nextLine();
price = Double.parseDouble(input);
if (price <= 0) {
price = -1;
continue;
}
} catch (Exception Error) {
System.out.println("Стоимость продукта должна быть больше 0. Введите стоимость ещё раз");
}
calculator += price;
}
System.out.println("Товар успешно добавлен.\nХотите ли Вы добавить ещё товар?\nЕсли нет, то нажмите \"Завершить\".");
String answer = scanner.nextLine();
if (answer.equalsIgnoreCase("Завершить")) {
break;
}
System.out.println("Добавленные товары:" + "\n" + nameProduct);
}
}
}