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

первое домашнее задание #96

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
Bivis63 wants to merge 1 commit into Yandex-Practicum:master
base: master
Choose a base branch
Loading
from Bivis63:master
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
96 changes: 96 additions & 0 deletions src/main/java/Calculate.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Calculate {
static String toComplete = "завершить";
Copy link

@MagicUnderHood MagicUnderHood Oct 27, 2022

Choose a reason for hiding this comment

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

static можно убрать


List<String> menuList = new LinkedList<>();
List<Double> priceList = new ArrayList<>();
String menu;
double price = 0;
double sum;

public void product() {

Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите название товара : ");
menu = scanner.next();
menuList.add(menu);
System.out.println("Введите цену товара в формате 'рубли.копейки' [10.45, 11.40] :");

while (!scanner.hasNextDouble()) {
System.out.println("Введите корректное значение :");
scanner.next();
}

price = scanner.nextDouble();
if (price > 0) {
priceList.add(price);
sum = sum + price;
System.out.println("Товар успешно добавлен! ");
}

while (price <= 0) {
if (price <= 0) {
Copy link

@MagicUnderHood MagicUnderHood Oct 27, 2022

Choose a reason for hiding this comment

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

В while уже проверяется это условие, if можно убрать

System.out.println("Ошибка цена не может быть отрицательной,ошибка введите цену заного");
price = scanner.nextDouble();
if (price > 0) {
priceList.add(price);
sum = sum + price;
System.out.println("Товар успешно добавлен! ");
break;
}
}
}
System.out.println("Если хотите продолжить введите - любой символ,если хотите остановиться введите 'завершить' ");
menu = scanner.next();
if (menu.equalsIgnoreCase(toComplete)) {
break;
}
}
}


public String GetRubleAddition(double num) {
int numToInt = (int) num;
double preLastDigit = num % 100 / 10;
if (preLastDigit == 1) {
Copy link

@MagicUnderHood MagicUnderHood Oct 27, 2022

Choose a reason for hiding this comment

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

Из-за того, что переменная типа double, это условие сработает только для num = 10. Если бы была int, работало бы для 11-19

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

public String GetHumanAdddition(int num) {

double preLastDigit = num % 100 / 10;
if (preLastDigit == 1) {
return "Человек";
}
switch (num % 10) {
case 1:
case 2:
case 3:
case 4:
return "Человека";
default:
return "рублей";
Copy link

@MagicUnderHood MagicUnderHood Oct 27, 2022

Choose a reason for hiding this comment

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

Кажется, тут ошибка)

}
}
}





49 changes: 47 additions & 2 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимость
Scanner scanner = new Scanner(System.in);
System.out.println("На сколько человек нужно разделить счет ?");
while (!scanner.hasNextInt()) {
System.out.println("Введите корректное значение :");
scanner.next();
}
int human = scanner.nextInt();


while (human <= 1) {
if (human < 1) {
System.out.println("Колличество человек " + human);
System.out.println("некоректное значение для подсчета.Введите колличество человек заного ");
human = scanner.nextInt();
}
if (human == 1) {
Copy link

@MagicUnderHood MagicUnderHood Oct 27, 2022

Choose a reason for hiding this comment

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

Поскольку в while может быть только human <= 1, а human < 1 проверено в верхнем if, тут можно сделать просто else к нему

System.out.println("Колличество человек " + human);
System.out.println("нет смысла ничего считать и делить.Введите колличество человек заного");
human = scanner.nextInt();
}
}
Calculate calculate = new Calculate();

calculate.product();



double check = calculate.sum / human;

System.out.println("Счет нужно разделить на : " + human + " " + calculate.GetHumanAdddition(human));
System.out.println("Список выбранных товаров: ");
for (String str : calculate.menuList) {
System.out.println(str);
}
System.out.println("Общая сумма заказа : " + String.format("%.2f", calculate.sum) + " " + calculate.GetRubleAddition(calculate.sum));
System.out.println("Каждый должен заплатить :" + String.format("%.2f", +check) + " " + calculate.GetRubleAddition(check));


}
}





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