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

HW #66

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
yaAppolitta wants to merge 12 commits into Yandex-Practicum:master
base: master
Choose a base branch
Loading
from yaAppolitta:master
Open

HW #66

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
83a7216
Init commit
Jul 27, 2022
2616510
Change project name
Jul 27, 2022
83e4746
Merge remote-tracking branch 'origin/master'
yaAppolitta Oct 2, 2022
ba761a0
Merge remote-tracking branch 'origin/master'
yaAppolitta Oct 2, 2022
544d467
Спринт 2 . Проектная работа 1.
yaAppolitta Oct 3, 2022
9e32c9e
Merge remote-tracking branch 'origin/master'
yaAppolitta Oct 3, 2022
27c3c49
Спринт 2 . Проектная работа 1.
yaAppolitta Oct 3, 2022
df34b55
Спринт 2 . Проектная работа 1.
yaAppolitta Oct 3, 2022
bb64e7e
Спринт 2 . Проектная работа 1.
yaAppolitta Oct 4, 2022
fab258e
Спринт 2 . Проектная работа 1.
yaAppolitta Oct 4, 2022
52ba7b8
Спринт 2 . Проектная работа 1.
yaAppolitta Oct 5, 2022
d75519a
Спринт 2 . Проектная работа 1.
yaAppolitta Oct 5, 2022
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
View file Open in desktop

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

1 change: 1 addition & 0 deletions .idea/.name
View file Open in desktop

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
View file Open in desktop

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
View file Open in desktop

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
View file Open in desktop

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

18 changes: 18 additions & 0 deletions .idea/gradle.xml
View file Open in desktop

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

9 changes: 9 additions & 0 deletions .idea/misc.xml
View file Open in desktop

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
View file Open in desktop

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

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

public class Main {

public static void main(String[] args) {
// ваш код начнется здесь

// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
Scanner scanner = new Scanner(System.in);
//считываем кол-во гостей
int visitor = 0;
System.out.println ("Введите колличество гостей");
while (true) {
String str = scanner.next();
while (!isNumeric(str)) {
System.out.println("Введите колличество гостей");
Copy link

@MagicUnderHood MagicUnderHood Oct 5, 2022
edited
Loading

Choose a reason for hiding this comment

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

Можно перенести эту строчку наверх, сразу после while, тогда отсюда и перед while её можно удалить

str = scanner.next();
}
visitor = Integer.parseInt(str);
if ((visitor <= 1) | (visitor == 0)) {
System.out.println("Некорректное кол-во гостей");
System.out.println("Введите колличество гостей");
} else if (visitor > 1) {
break;
}
}
//считываем кол-во товаров
boolean enough = true;

Product list = new Product();
Calculate menu_list = new Calculate();
Copy link

@MagicUnderHood MagicUnderHood Oct 5, 2022

Choose a reason for hiding this comment

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

Для именования переменных лучше использовать верблюжий регистр, то есть menuList

while (enough) {
Copy link

@MagicUnderHood MagicUnderHood Oct 5, 2022

Choose a reason for hiding this comment

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

Можно просто прописать while(true)

System.out.println("Введите название ");
list.name = scanner.next();
System.out.println("Введите цену");
String str = scanner.next();
while (!isNumeric(str)) {
System.out.println("Введите цену с разделителем \".\" ");
str = scanner.next();
}
list.price = Double.parseDouble(str);
menu_list.getAddList(list.name, list.price);
menu_list.getListPrice(list.price);
System.out.println("Хотите ввести ещё товар?");
System.out.println("Eсли вы хотите ввести ещё товар, введите ДА");
System.out.println("Eсли вы хотите ввести ещё товар, введите Завершить ");
Copy link

@MagicUnderHood MagicUnderHood Oct 5, 2022

Choose a reason for hiding this comment

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

Наверное, тут должно быть "Если вы не хотите больше вводить товары, введите Завершить"

String answer = scanner.next();

if (answer.equalsIgnoreCase("завершить")) {
enough = false;
break;
}
}

if (!enough){
Copy link

@MagicUnderHood MagicUnderHood Oct 5, 2022

Choose a reason for hiding this comment

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

Этот if можно убрать, и переменную enough тоже. Из цикла while может быть выход, только если пользователь введет Завершить, и тогда должен будет выполниться код здесь

System.out.println("Добавленные товары:");
System.out.println(menu_list.receipt);
float pay = (float) (menu_list.pay/visitor);
String rubString = "";
int rub = (int) (pay % 10);
int rubTeen = (int) (pay % 100);
if ((rub == 0 ) || (rub == 5) || (rub == 6) || (rub == 7 ) || (rub == 8 ) || (rub == 9 ) || ((rubTeen >= 11) && (rubTeen <= 14))){
Copy link

@MagicUnderHood MagicUnderHood Oct 6, 2022

Choose a reason for hiding this comment

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

Можно упростить условие - rub == 0 || (rub >= 5 && rub <= 9) || (rubTeen >= 11 && rubTeen <= 14)

rubString = "рублей";
} else if ((rub == 2) || (rub == 4) || (rub == 3) ){
Copy link

@MagicUnderHood MagicUnderHood Oct 5, 2022

Choose a reason for hiding this comment

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

Можно упростить - rub >= 2 && rub <= 4

rubString = "рубля";
} else if (rub == 1) {
rubString = "рубль";
}

String message = "Каждый должен заплатить %.2f %s";
System.out.println(String.format(message, pay, rubString));
}
}
public static class Calculate{
String receipt = "";
double pay = 0;

public void getAddList (String name, double price) {
Copy link

@MagicUnderHood MagicUnderHood Oct 5, 2022

Choose a reason for hiding this comment

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

Этот и getListPrice методы называются "get", то есть "получить", но ничего не возвращают. Лучше назвать "addProduct" и "addPrice". Ещё можно передавать в параметре этого метода сразу объект класса Product, и из него брать имя и цену

receipt = receipt + String.format("%s %.2f \n",
name,
price);
System.out.println("Товар успешно добавлен");
}

public void getListPrice(double price){
pay = pay + price;
}
}

public static class Product {
Copy link

@MagicUnderHood MagicUnderHood Oct 5, 2022

Choose a reason for hiding this comment

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

Классы лучше в отдельный файл располагать, и тогда не надо будет делать их статическими

String name;
double price;
}

public static boolean isNumeric(String string) {
double value;

if(string == null || string.equals("")) {
return false;
}
try {
value = Double.parseDouble(string);
return true;
} catch (NumberFormatException e) {

}
return false;
}
}

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