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
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.

123 changes: 123 additions & 0 deletions .idea/codeStyles/Project.xml

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

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.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/compiler.xml

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

15 changes: 15 additions & 0 deletions .idea/git_toolbox_prj.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.

10 changes: 10 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.

85 changes: 80 additions & 5 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,83 @@
public class Main {
import java.util.Scanner;

public class Main {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
Calculator.inputPersons();
Calculator.addProducts();
Calculator.payPeople();
}

public static class Calculator {
static double totalPrice = 0;
static String names = "";
static int persons = 0;

public static void inputPersons() {
while (true) {
System.out.println("How many persons?");
if (scan.hasNextInt()) {
persons = scan.nextInt();
if (persons <= 1) {
System.out.println("Amount of persons must be integer > 1. Try again.");
continue;
}
break;
} else {
System.out.println("Amount of persons must be integer > 1. Try again.");
scan.nextLine();
continue;
}
}
}

public static void addProducts() {
while (true) {
System.out.println("Product name: ");
String name = scan.next() + scan.nextLine();
System.out.println("Price: ");
if (scan.hasNextDouble()) {
double price = scan.nextDouble();
if (price < 0) {
System.out.println("Price must be positive double! Try again");
continue;
}
totalPrice += price;
names += name + "\n";
} else {
System.out.println("Price must be positive double! Try again");
scan.nextLine();
continue;
}
System.out.println("Product " + name + " successfully added! Enough? (yes - any symbol/no - n): ");
String answer = scan.next();
if (answer.equalsIgnoreCase("n")) {
continue;
} else {break;}
}
}

public static void payPeople() {
int ruble = (int) Math.floor(totalPrice);
int payPeople = (int) Math.floor(totalPrice/persons);
System.out.println("Вы заказали следующие продукты:\n" + names + "на сумму: " + totalPrice + " " + Calculator.payPeoples(ruble));
System.out.println("Каждый из " + persons + " человек заплатит по " + String.format("%.2f", totalPrice/persons) + " " + Calculator.payPeoples(payPeople));
}

static String payPeoples(int ruble) {
if (ruble % 100 / 10 == 1) {
return "рублей";
} else {
switch (ruble % 10) {
case 1 :
return "рубль";
case 2:
case 3:
case 4:
return "рубля";
default: return "рублей";
}
}
}
}
}
}