Skip to content

Commit c62daa8

Browse files
committed
первый комит
1 parent c521234 commit c62daa8

10 files changed

Lines changed: 298 additions & 3 deletions

File tree

‎.idea/.gitignore‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/codeStyles/Project.xml‎

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/codeStyles/codeStyleConfig.xml‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/compiler.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/gradle.xml‎

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/misc.xml‎

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/vcs.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/main/java/Calculator.java‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.lang.Math;
2+
public class Calculator {
3+
Product product;
4+
double fullPrice = 0;
5+
String listOfProducts = "";
6+
double fullPriceSharing = 0;
7+
String rubles = "";
8+
9+
Calculator(Product product) {
10+
this.product = product;
11+
}
12+
13+
void addProduct (Product product) {
14+
fullPrice += product.getPrice();
15+
listOfProducts += product.getName() + "\n";
16+
}
17+
18+
double everyonePays (int persons){
19+
fullPriceSharing = fullPrice / persons;
20+
return fullPriceSharing;
21+
}
22+
23+
String ending (double fullPriceSharing){
24+
if (Math.floor(fullPriceSharing) >= 11 && Math.floor(fullPriceSharing) <=19){
25+
rubles = "Рублей";
26+
}
27+
else {
28+
switch ((int) Math.floor(fullPriceSharing % 10)) {
29+
case 1:
30+
rubles = "Рубль";
31+
break;
32+
case 2:
33+
case 3:
34+
case 4:
35+
rubles = "Рубля";
36+
break;
37+
default:
38+
rubles = "Рублей";
39+
break;
40+
}
41+
}
42+
return rubles;
43+
}
44+
}

‎src/main/java/Main.java‎

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,72 @@
1+
import java.util.Scanner;
2+
13
public class Main {
24

35
public static void main(String[] args) {
4-
// ваш код начнется здесь
5-
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
6-
System.out.println("Привет Мир");
6+
Scanner scanner = new Scanner(System.in);
7+
8+
int numberOfPersons = 0;
9+
String name = "";
10+
double price = 0.0;
11+
Product random = new Product(name, price);
12+
Calculator calc = new Calculator(random);
13+
14+
while (true) {
15+
System.out.println("На скольких человек нужно разделить счёт?");
16+
if (scanner.hasNextInt()) {
17+
numberOfPersons = scanner.nextInt();
18+
19+
if (numberOfPersons > 1) {
20+
break;
21+
} else if (numberOfPersons == 1) {
22+
System.out.println("Вы один, счёт делить не нужно)");
23+
} else {
24+
System.out.println("Некорректное значение");
25+
}
26+
}
27+
else{
28+
System.out.println("Некорректное значение");
29+
scanner.nextLine();
30+
}
31+
}
32+
33+
System.out.println("Введите название продукта");
34+
scanner.nextLine();
35+
name = scanner.nextLine();
36+
37+
while (true) {
38+
System.out.println("Введите стоимость продукта в формате XX,XX");
39+
if(scanner.hasNextDouble()) {
40+
price = scanner.nextDouble();
41+
if(price >= 0) {
42+
Product UserInput = new Product(name, price);
43+
calc.addProduct(UserInput);
44+
45+
System.out.println("Продукт успешно добавлен");
46+
System.out.println("Не хотите добавить еще один продукт?");
47+
System.out.println("Введите название продукта или");
48+
System.out.println("Введите \"Завершить\", чтобы завершить процесс добавления товаров");
49+
scanner.nextLine();
50+
String answer = scanner.nextLine();
51+
if (answer.equalsIgnoreCase("завершить")) {
52+
break;
53+
} else {
54+
name = answer;
55+
}
56+
}
57+
else{
58+
System.out.println("Некорректное значение");
59+
scanner.nextLine();
60+
}
61+
}
62+
else{
63+
System.out.println("Некорректное значение");
64+
scanner.nextLine();
65+
}
66+
}
67+
calc.everyonePays(numberOfPersons);
68+
calc.ending(calc.fullPriceSharing);
69+
System.out.println("Добавленные товары:\n" + calc.listOfProducts);
70+
System.out.println(String.format("Каждый должен заплатить %.2f" + " %s", calc.fullPriceSharing, calc.rubles));
771
}
872
}

‎src/main/java/Product.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Product {
2+
double price;
3+
String name;
4+
5+
Product(String name, double price){
6+
this.name = name;
7+
this.price = price;
8+
}
9+
String getName (){
10+
return this.name;
11+
}
12+
double getPrice (){
13+
return this.price;
14+
}
15+
}
16+

0 commit comments

Comments
 (0)