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
5 changes: 5 additions & 0 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Calculator {
static double aveSumm (double summ, int countOfPerson){
return summ / countOfPerson;
}
}
19 changes: 19 additions & 0 deletions src/main/java/Formatting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Formatting {


static String round(double ruble){
return String.format("%.2f", ruble);
}
public static String declination(double rubles){
var deci = (int) rubles % 100 / 10;
if (deci == 1)
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это скобка должна быть строкой выше

return "рублей";
}
return switch ((int) rubles % 10) {
case 1 -> "рубль";
case 2, 3, 4 -> "рубля";
default -> "рублей";
};
}
}
5 changes: 5 additions & 0 deletions src/main/java/Good.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Good {
String name;
double value;
}

43 changes: 41 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
System.out.println("Введите количество человек, на которых необходимо разделить счет");
Scanner scanner = new Scanner(System.in);
while (!scanner.hasNextInt() && scanner.hasNext()) {
System.out.println("некорректные данные, введите еще раз количество персон. Вы ввели: " + scanner.next());
}
int personCount = scanner.nextInt();

while (personCount<=1){
System.out.println("Введенное значение неверно, введите количество человек больше 1");
personCount = scanner.nextInt();
}


String listOfGoods="";
double summOfGoods= 0.00;
System.out.println("Введите товар, который хотите добавить в счёт");
while (true){
String input = scanner.next();
if (input.equalsIgnoreCase("завершить")){
break;
}
Good position = new Good();
position.name = input;
listOfGoods += position.name + "\n";
System.out.println("Введите стоимость добавляемого товара ");
while (!scanner.hasNextDouble() && scanner.hasNext()) {
System.out.println("некорректные данные, введите еще раз сумму. Вы ввели: " + scanner.next());
}
position.value = scanner.nextDouble();
while (position.value<0){
System.out.println("Введенное значение некорректно, введите неотрицательную стоимость");
position.value = scanner.nextDouble();
}
summOfGoods+= position.value;
System.out.println("Товар "+ position.name + " добавлен. Если хотите прекратить добавление товаров, введите команду \"завершить\". Введите новый товар");
}
double aveSumm = Calculator.aveSumm(summOfGoods, personCount);
System.out.println("Добавленные товары:\n" + listOfGoods);
System.out.println("Сумма на каждого человека будет равна " + Formatting.round(aveSumm) + " " + Formatting.declination(Math.floor(aveSumm)));
}
}
}