Skip to content
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import java.util.InputMismatchException;
import java.util.Scanner;
public class Calculator {

static void calculate(int people) {
String food = "";
double price = 0.0;

while (true) {
System.out.println("Хотите еще добавить товар?, если да то Введите название товара" +
"\nДля завершения введите 'Завершить'");
Scanner scanner = new Scanner(System.in);
String inputFood = scanner.next();

if (inputFood.equalsIgnoreCase("Завершить")) {
break;
} else {
food = food + inputFood + "\n";
price = price + getPrice();
}

}
System.out.println("Добавленные товары:\n" + food);
double result = price / people;
String temp = "Каждый человек должен заплатить %.2f" + getDeclination((int) Math.floor(result));
System.out.println(String.format(temp, result));
}


static double getPrice() {
while (true) {
System.out.println("Введите стоимость в формате: 'рубли.копейки' [10,45, 11,40]");
double inputPrice = 0;
try {
Scanner scanner = new Scanner(System.in);
inputPrice = scanner.nextDouble();
if (inputPrice <= 0){
System.out.println("Неверное значение");
} else {
return inputPrice;
}
} catch (InputMismatchException e) {
System.out.println("Неверное значение");
}
}
}

private static String getDeclination(int rouble) {

if ((rouble % 100 / 10) == 1){
return " рублей.";
}
switch (rouble % 10){
case 1:
return " рубль.";
case 2:
case 3:
case 4:
return " рубля.";
default:
return " рублей.";
}
}
}
22 changes: 18 additions & 4 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import java.util.InputMismatchException;
import java.util.Scanner;
public class Main {

public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
int people = 0;
while (people < 2) {
System.out.println("На сколько человек нужно разделить счет?");
Scanner scanner = new Scanner(System.in);
try {
people = scanner.nextInt();
if (people < 2) {
System.out.println("Неверное значение");
}
}
catch (InputMismatchException e) {
System.out.println("Неверное значение");
}
}
Calculator.calculate(people);
}
}
}