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
19 changes: 19 additions & 0 deletions src/main/java/Formatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


public class Formatter {
static String a = "";
static void FormatterRubles() {
int floor = (int) Math.floor(Main.sumMain);
if (floor % 100 >= 11 && floor % 100 <= 14) {
a = "рублей";
} else if (floor % 10 == 1) {
a = "рубль";
} else if (floor % 10 >= 2 && floor % 10 <= 4) {
a = "рубля";
} else if (floor % 10 >= 5 && floor % 10 <= 8) {
a = "рублей";
}else if (floor % 9 == 0) {
a = "рублей";
} else if (floor % 10 == 0) {
a = "рублей";
}}}
37 changes: 34 additions & 3 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
static double sumMain = 0;
static String strProductsMain = "";
private static int humans;

public static void main(String[] args) {
System.out.println("Hello world!");
}
}
Scanner scanner = new Scanner(System.in);
System.out.println("На сколько человек необходимо разделить счет?");
while (true) {
System.out.println("Введите целое число");
try {
humans = scanner.nextInt();
} catch (InputMismatchException e) {
System.out.println("Не целое число");
scanner.nextLine();
}
if (humans > 1) {
break;
} else if (humans == 1) {
System.out.println("Нет смысла ничего считать и делить :-)");
return;
} else {
System.out.println("Некорректное значение для подсчёта!");
}
}
Products.productCount();
strProductsMain += Products.strProducts;
System.out.println("Добавленные товары: " + strProductsMain);
sumMain += Products.sum;
sumMain = sumMain / humans;
String result = String.format("%.2f", sumMain);
Formatter.FormatterRubles();
System.out.println("Всем необходиомо заплатить по " + result + " " + Formatter.a + ".");
scanner.close();}}
64 changes: 64 additions & 0 deletions src/main/java/Products.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 Products {
static String strProducts = "";
static double sum = 0;
static double productPrice;
static void productCount() {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Хотите добавить товар?");
String productInput = scanner.next();
switch (productInput.toLowerCase()) {
case "да":
while (true) {
System.out.println("Введите название товара.");
String productName = scanner.next();
strProducts = strProducts.concat("\n").concat(productName);
while (true) {
System.out.println("Введите стоимость товара.");
try {
productPrice = scanner.nextDouble();
}catch (InputMismatchException b){
System.out.println("Введено не число.");
scanner.nextLine();
}
if (productPrice > 0) {
break;
} else if (productPrice < 0) {
System.out.println("Стоимость не может быть отрицательной!");
}
}
System.out.println("Товар добавлен!");
sum = sum + productPrice;
System.out.println("Хотите добавить еще товар? (Введите \"Завершить\" ,чтобы завершить процесс добавления товаров.)");
String productInput2 = scanner.next();
switch (productInput2.toLowerCase()) {
case "да":
break;
case "нет":
return;
case "завершить":
return;
default:
while (true) {
System.out.println("Введите \"Да\" ,чтобы добавить товар.\nВведите \"Завершить\" ,чтобы завершить процесс добавления товаров.");
String productInput3 = scanner.next();
if (productInput3.equalsIgnoreCase("да")) {
break;
} else if (productInput3.equalsIgnoreCase("Завершить")) {
return;
} else {
}
}
}
}
case "нет":
return;
default:
System.out.println("Введите да или нет!");
}
}
}
}