Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

13.10.22 #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kamberbattch wants to merge 3 commits into Yandex-Practicum:master
base: master
Choose a base branch
Loading
from kamberbattch:master
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
View file Open in desktop

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
View file Open in desktop

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
View file Open in desktop

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
View file Open in desktop

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
View file Open in desktop

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
View file Open in desktop

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
View file Open in desktop

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
View file Open in desktop

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
View file Open in desktop
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 "рублей";
}
}
}
}
}
}

AltStyle によって変換されたページ (->オリジナル) /