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
28 changes: 28 additions & 0 deletions src/main/java/Calculation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Calculation {
public static String everyPeoplePrice(double price ) {

String readySum = "";

double priceNoDouble = Math.floor(price);
int priceName = (int) (priceNoDouble % 10);
int priceNameUnusial = (int) (priceNoDouble % 100);

if (priceName == 1) {
readySum = "рубль.";
}
if (priceName>=2 && priceName<=4) {
readySum = "рубля.";
}
if (priceName>=5 && priceName<=9) {
readySum = "рублей.";
}
if(priceName>=10 && priceName<=20) {
readySum = "рублей.";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏priceName, который является остатком от деления на 10, никогда не будет иметь значение больше 10, следовательно - это недостижимый код

}
if(priceNameUnusial>=10 && priceNameUnusial<=20) {
readySum = "рублей.";
}
return readySum;

}
}
52 changes: 51 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Scanner scanner = new Scanner(System.in);

int person;
String menu = "";
double sum = 0;
double prisePosition;
double price;
String position;

person = PeopleNumber.count();

while (true) {
System.out.println("Введите название блюда или напишите \"завершить\" для дальнейшего подсчета:");
position = scanner.next();

if (position.equalsIgnoreCase("завершить")) {
break;
}

menu = menu + "\n" + position;


while (true) {
System.out.println("Введите цену блюда:");
scanner.nextLine();
if (scanner.hasNextDouble()) {
prisePosition = scanner.nextDouble();
if(prisePosition>0) {
sum = sum + prisePosition;
break;
} else {
System.out.println("Вы ввели некорректную цену");
}
} else {
System.out.println("Вы ввели не число");
}

}

}

price = sum/person;

System.out.println("Добавленные товары:" + menu);

String rub = Calculation.everyPeoplePrice(price);
String numberRub = String.format("%.2f", price);
System.out.println("Цена для каждого гостя: " + numberRub + " " + rub);
scanner.close();

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

public class PeopleNumber {
static int people;
public static int count() {
Scanner scan = new Scanner(System.in);
int qwest;
while (true) {
System.out.println("Введите число гостей:");
if (scan.hasNextInt()) {
qwest = Integer.parseInt(scan.nextLine());
if(qwest>1) {
break;
} else {
System.out.println("Вы ввели некорректное число");

}

} else {
System.out.println("Вы ввели не число");
scan.nextLine();
}
}
return qwest;


}
}