Skip to content
Open
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
59 changes: 44 additions & 15 deletions src/main/java/Calc.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,73 @@
import java.util.Scanner; //вторая проверка
import java.util.InputMismatchException;
import java.util.Scanner;

public class Calc {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Как видишь, я не могу прокомментировать твой код, так как он уже есть в ветке master и в PR его не видно.
Тебе не нужно вливать ветку, до того как я проверю все.
Тебе необходимо откатить ветку master до того состояния, когда в нее не был влит этот PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Если сам не справишься, обратись за помощью к наставнику/це. И исправляй критические замечания.



public static int howManyPersons() {
Scanner scanner = new Scanner(System.in);
int numberOfPersons = 0;
System.out.println("На скольких людей разделить счет?");
while(true){
numberOfPersons = scanner.nextInt();
int numberOfPersons = 0;
try {
numberOfPersons = scanner.nextInt();
} catch (InputMismatchException e){
System.out.println("Некорректный ввод. Введите количество персон");
scanner.nextLine();
}
if(numberOfPersons > 1) {
scanner.close();
break;
return numberOfPersons;
}
else {
System.out.println("Некорректный ввод. Введите количество персон");
}
System.out.println("Некорректный ввод. Введите количество персон");
}
return numberOfPersons;
}



public static String getProduct() {
String encoding = System.getProperty("console.encoding", "utf-8");
String priceList;
priceList = "Добавленные товары:\n";
String product = "";
float price = 0f;
float sum = 0f;
Scanner scanner = new Scanner(System.in, encoding);
int quantityPerson = howManyPersons();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите название товара");
product = scanner.nextLine();
while(true) {
product = scanner.nextLine();
if(product.trim().length() == 0) {
System.out.println("Кажется вы забыли ввести название товара, попробуйте ещё раз");
}
else {
break;
}
}
System.out.println("Введите стоимость товара");
price = scanner.nextFloat();
while(true) {
try {
price = scanner.nextFloat();
} catch (InputMismatchException e) {
System.out.println("Некорректный ввод. Введите стоимость товара");
scanner.nextLine();
continue;
}
if(price > 0) {
break;
}
else {
System.out.println("Некорректный ввод. Введите стоимость товара");
}
}
scanner.nextLine();
priceList += String.format("%s - %.2f\n", product, price);
priceList += String.format("%s - %.2f %s\n", product, price, wordRuble(price));
sum += price;
System.out.println("Товар успешно добавлен, если хотите завершить введите\"завершить\"");
System.out.println("Товар успешно добавлен, если хотите завершить введите \"завершить\"");
if(scanner.nextLine().toLowerCase().equals("завершить")){
String ruble = wordRuble(sum);
sum = (sum / howManyPersons());
sum = (sum / quantityPerson);
priceList += String.format("Каждый должен заплатить %.2f %s\n ", sum, wordRuble(sum));
break;
}
Expand All @@ -60,4 +89,4 @@ else if (intRuble % 10 >= 5 && intRuble % 10 <= 9 || intRuble % 10 == 0)
return"рублей";
return null;
}
}
}