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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
public class Calculator {

String bill = "";
double finalPrice = 0;
int countPerson = 0;

double priceOfPerson = 0;

public void setCountPerson(int countPerson) {
this.countPerson = countPerson;
}

public void setBill(Product product) {
bill += (product.getNameOfProduct() + " " + product.getCost()) + "\n";
finalPrice += product.getCost();
}

public String math() {
String rubles = "руб";
if (priceOfPerson > 10 && priceOfPerson <20 ) {
return rubles + "лей";
} switch ((int) priceOfPerson % 10) {
case 1: {
return rubles + "ль";
}
case 2:
case 3:
case 4: {
return rubles + "ля";
}

Choose a reason for hiding this comment

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

Фигурные скобки в switch не обязательны

default: {
return rubles + "лей";
}
}
}

public void calculate() {
priceOfPerson = finalPrice / countPerson;
System.out.println("Количество персон: " + countPerson + "\n" + "Общий чек: " +
"\n" + bill + "\n" + "Денег с человека:" + "\n" + String.format("%.2f", priceOfPerson) + " " + math());
}
}
54 changes: 50 additions & 4 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,54 @@
public class Main {
import java.util.InputMismatchException;
import java.util.Scanner;

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


Calculator calculator = new Calculator();
System.out.println("На скольких человек разделить счет?");
int scanPerson;

while (true) {

if (scanner.hasNextInt()) {
scanPerson = scanner.nextInt();
if (scanPerson == 1) {
System.out.println("Подсчет не нужен");
System.exit(0);

Choose a reason for hiding this comment

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

Лучше тут программу не заканчивать, а предлагать ввести другое значение

} else if (scanPerson < 1) {
System.out.println("Ошибка. Введите корректное значение.");
} else break;
} else {
System.out.println("Введите корректное значение");
scanner.nextLine();
}
}

calculator.setCountPerson(scanPerson);
do {
Product product = new Product();
System.out.println("Введите название товара");
scanner.nextLine();
product.setNameOfProduct(scanner.nextLine());
System.out.println("Введите стоимость товара в формате 00,00");
product.setCost(inputPrice());
calculator.setBill(product);
System.out.println("Завершить? Нажмите любой символ, чтобы продолжить");
} while (!scanner.next().equalsIgnoreCase("Завершить"));

Choose a reason for hiding this comment

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

Хорошее использование do-while, молодец

calculator.calculate();

}

static double price = 0.0;
public static double inputPrice() {
try {
price = scanner.nextDouble();
} catch (InputMismatchException exception) {
System.out.println("Введите корректное значение");
scanner.nextLine();
inputPrice();
} return price;
}
}
23 changes: 23 additions & 0 deletions src/main/java/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Product {

private String nameOfProduct;
private double cost;


public String getNameOfProduct() {
return nameOfProduct;
}

public void setNameOfProduct(String nameOfProduct) {
this.nameOfProduct = nameOfProduct;
}

public double getCost() {
return cost;
}

public void setCost(double cost) {
this.cost = cost;
}

}