Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Задание к спринту No2 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MetelikovSergey wants to merge 3 commits into main
base: main
Choose a base branch
Loading
from dev
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
32 changes: 32 additions & 0 deletions src/main/java/Calculator.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@


public class Calculator {
public static void calculete(int countGuest) {

Product product = new Product();
System.out.println("Введите название блюда:");
while (true) {
String name;

name = Main.scanner.next();
if (name.equalsIgnoreCase("Завершить")) {
break;
} do {
product.nameProduct += name + "\n";
System.out.println("Введите стоимость товара (цифрой)");
while(!Main.scanner.hasNextDouble()){
System.out.println("Не коректный ввод цены, попробуйте еще раз.");
Main.scanner.next();
}
product.priceProduct += Main.scanner.nextDouble();
System.out.println("Чтобы закончить формирование счета введите команду \"Завершить\"\nЕсли хотите продолжить формировать счет,\n" +
"введите название блюда:");

}while (Main.scanner.hasNextDouble());
}
System.out.println(product.nameProduct + "\n" + "Общая стоимость = " +
String.format("%.2f",product.priceProduct) + " " + Formater.GetEnding((int) product.priceProduct) );
System.out.println("Сума для каждого гостя = " + String.format("%.2f",product.priceProduct / countGuest)
+" " + Formater.GetEnding((int) (product.priceProduct / countGuest)) );
}
}
22 changes: 22 additions & 0 deletions src/main/java/Formater.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Formater {
public static String GetEnding(int num)
{
int preLastDigit = num % 100 / 10;
if (preLastDigit == 1) {
return "рублей.коп";
}

switch (num%10) {
case 1:
return "рубль.коп";
case 2:
case 3:
case 4:
return "рубля.коп";
default:
return "рублей.коп";
}
}

}

27 changes: 22 additions & 5 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
public class Main {
import java.util.Scanner;

// dev branch for Y.Practicum
public class Main {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
int numberOfGuests = 0;


do {
System.out.println("Введите количество гостей\nКоличество гостей должно быть больше 1.");
while (!scanner.hasNextInt()){
System.out.println("Не коректное количество гостей, попробуйте еще раз.\nКоличество гостей должно быть больше 1." +
"\nВведите количество гостей ");
scanner.next();
}
numberOfGuests = scanner.nextInt();

}while (numberOfGuests <= 1);


Calculator.calculete(numberOfGuests);

}
}
}
4 changes: 4 additions & 0 deletions src/main/java/Product.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class Product {
String nameProduct = "";
double priceProduct;
}

AltStyle によって変換されたページ (->オリジナル) /