Skip to content
Closed
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.

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.

20 changes: 20 additions & 0 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class Calculator {
public static String complete(float costGeneral) {
String suffix;
int hundred = (int) Math.floor(costGeneral % 100);
if (hundred <= 14 && hundred >= 11) {
suffix = " рублей ";
} else {
int ten = hundred % 10;
if (ten == 1) {
suffix = " рубль ";
} else if (ten >= 2 && ten <= 4) {
suffix = " рубля ";
} else {
suffix = " рублей ";
}

}
return suffix;
}
}
22 changes: 20 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
System.out.println("Вас приветствует Калькулятор - счётчик");
Scanner scanner1 = new Scanner(System.in);
int people;
while (true) {
System.out.println("На сколько людей разделить счет?");
if (scanner1.hasNextInt()) {
people = scanner1.nextInt();
if (people == 1) {
System.out.println("Нет смысла делить счёт на одного. Введите корректное значение гостей.");
} else if (people < 1) {
System.out.println("Вы ввели некоректное значение. Количество гостей должно быть больше одного. Попробуйте ещё раз.");
} else {
break;
}
}
}
Products.calc(people);
}
}

50 changes: 50 additions & 0 deletions src/main/java/Products.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.util.Scanner;

public class Products {
static String exit = "ЗАВЕРШИТЬ";

public static void calc(int people) {
String product;
String allProducts = "";
float costPrice;
float sumForall = 0.00f;

String close;
while (true) {
Scanner scanner2 = new Scanner(System.in);
System.out.println("Введите название товара");
product = scanner2.nextLine();
System.out.println("Товар " + product + " добавлен в счёт");
System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [пример - 10.45, 11.40]");
if (scanner2.hasNextFloat()) {
costPrice = scanner2.nextFloat();
if (costPrice > 0) {
sumForall = sumForall + costPrice;
allProducts = allProducts + product + "\n";
String sufForOne = Calculator.complete(costPrice);
String anotherOne = "Вы добавили: %s за %.2f%s\n";
System.out.printf(anotherOne, product, costPrice, sufForOne);
System.out.println("Введите любой символ, если хотите добавить товар. В противном случае введите:'ЗАВЕРШИТЬ'");
close = scanner2.next();
if (close.equalsIgnoreCase(exit)) {
break;
}
} else {
System.out.println("Сумма указана неверно");
}
} else {
System.out.println("Некорректный формат стоимости товара. Побробуйте ввести сумму ещё раз!");
}

}
String suf = Calculator.complete(sumForall);
float forOneguest = sumForall/ people;
String lastSuf = Calculator.complete(forOneguest);

System.out.println("Вы купили:\n" + allProducts + "За " + String.format("%.2f", sumForall) + suf);
System.out.println("Каждый из гостей должен заплатить: " + String.format("%.2f", forOneguest) + lastSuf);
System.out.println("Спасибо,что воспользовались нашим Калькулятором - счётчиком!");


}
}