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/CorrectRub.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class CorrectRub {
static String getFormatRub() {

double personalCost = Main.sum/Main.quantity;
String correctRub = "";
if ((Math.floor(personalCost)%100) >= 11 && (Math.floor(personalCost)%100) <= 14) {
correctRub = "рублей";
} else {
if ((Math.floor(personalCost) % 10) == 1) {
correctRub = "рубль";
} else if ((Math.floor(personalCost) % 10) > 1 && (Math.floor(personalCost) % 10) < 5) {
correctRub = "рубля";
} else {
correctRub = "рублей";
}
}
return correctRub;
Comment thread
Forquad marked this conversation as resolved.
}
}
57 changes: 53 additions & 4 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,57 @@
import java.util.Scanner;

public class Main {
static Scanner scanner = new Scanner(System.in); //Добавляем сканер длядальнейшего использования в методах.
static String items = "";
static double sum = 0;

static int quantity=0;

public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");

int numberOfPeople = People.howMuchPeople();
whatInBill();
double personalCost = sum/numberOfPeople;
String rub = CorrectRub.getFormatRub();
printResult (personalCost, rub);
}

public static void whatInBill() {
StringBuilder builder = new StringBuilder();
System.out.println("Ну, и что ели?");
while (true) {
String input = scanner.nextLine();
if (input.equalsIgnoreCase("Завершить")) {
System.out.println("Фух! Я надеюсь вы не лопните...");
break;
}
builder.append(items+input).append("\n");
System.out.println("А сколько стоило?");
double price;
while (true) {
if (scanner.hasNextDouble()) {
price = scanner.nextDouble();
if (price < 0) {
System.out.println("Серьезно, покормили и денег дали? Давай еще раз...");
} else {
sum = price + sum;//Считаем стоимость товаров
System.out.println("Товар добавлен, общая сумма: " + sum + " руб. Что еще добавить из блюд? Если ничего, напиши 'Завершить'");
break;
}
} else {
System.out.println("Не шути со мной, кожанный, у тебя последняя попытка");
scanner.nextLine();
}
}
scanner.nextLine();
}
items=builder.toString();
}


static void printResult(double personalCost, String rub) {
System.out.println("Добавленные товары: ");
System.out.print(items);
System.out.printf("Короче, клоуны, с каждого к оплате: %.2f %s", personalCost, rub);
}
}
}
25 changes: 25 additions & 0 deletions src/main/java/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.util.Scanner;

public class People {
static Scanner scanner = new Scanner(System.in);

public static int howMuchPeople() {
System.out.println("Сколько Вас, ребят?");
while (true) {
if (scanner.hasNextInt()) {
Main.quantity = scanner.nextInt();
if (Main.quantity == 1) {
System.out.println("Ты что, дурак? Ты ешь один...Попробуй еще раз...");
} else if (Main.quantity < 1) {
System.out.println("Серьезно? Ты пересмотрелл Рикк и Морти? Богатый внутренний мир... попробуй еще раз...");
} else if (Main.quantity > 1){
break;
}
} else {
System.out.println("О боги!... Вы же не буквы или половинчатые...Кожанный, давай попробуем еще раз...");
scanner.next();
}
}
return Main.quantity;
}
}