-
Notifications
You must be signed in to change notification settings - Fork 215
Проектная работа №1. Версия 2. #68
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
base: master
Are you sure you want to change the base?
Changes from all commits
c0be808
627f662
13dfa3e
6c85efc
0ee5c73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,5 @@ repositories { | |
| } | ||
|
|
||
| dependencies { | ||
| implementation 'com.google.android.gms:play-services-analytics-impl:17.0.0' | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,29 @@ | ||
| public class Main { | ||
| static String end = "Завершить"; // проверка для завершения ввода продуктов | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| People.howPeople(); | ||
| Product.calculate(); | ||
|
|
||
| // Вывод результата | ||
| double costPerson = Product.cost / People.countPeople; | ||
| double checkCostPerson = Math.floor(costPerson); | ||
|
|
||
| System.out.println("Добавленные товары:\n" + Product.name); | ||
| System.out.printf("%.2f", costPerson); | ||
| rublesName(checkCostPerson); | ||
| } | ||
|
|
||
| public static void rublesName(double cost) { | ||
| if (cost % 10 == 1 && cost != 11 && cost % 100 != 11) { | ||
| System.out.println(" рубль."); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно в этом методе не выводить на консоль слово, а возвращать только его |
||
| } else if (cost % 10 >= 2 && cost % 10 <= 4) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| System.out.println(" рубля."); | ||
| } else { | ||
| System.out.println(" рублей."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class People { | ||
| public static int countPeople; | ||
|
|
||
| public static void howPeople() { | ||
| System.out.println("На скольких человек делим счёт?"); | ||
| while (true) { | ||
| Scanner scannerPeople = new Scanner(System.in); | ||
| boolean checkPeople = scannerPeople.hasNextInt(); | ||
| if (checkPeople) { | ||
| int passPeople = scannerPeople.nextInt(); | ||
| if (passPeople > 1) { | ||
| countPeople = passPeople; | ||
| return; // передает в переменную число людей | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно число людей сделать возвращаемым значением метода howPeople, и избавиться от переменной countPeople |
||
| } else { | ||
| System.out.println("Ошибка. Введи целое число больше 1:"); | ||
| } | ||
| } else { | ||
| System.out.println("Ошибка. Введи целое число больше 1:"); | ||
|
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Product { | ||
| static String name = ""; | ||
| static double cost; | ||
|
|
||
| public static void calculate() { | ||
| System.out.println("Как называется продукт?"); | ||
| while (true) { | ||
| Scanner scannerName = new Scanner(System.in); | ||
| String checkName = scannerName.nextLine(); | ||
| if (checkName.equalsIgnoreCase(Main.end)) { | ||
| break; | ||
| } else { | ||
| name = name + checkName + "\n"; | ||
| } | ||
|
|
||
| System.out.println("Сколько стоил продукт?"); | ||
| while (true) { | ||
| Scanner scannerCost = new Scanner(System.in); | ||
| boolean checkCost = scannerCost.hasNextDouble(); | ||
| if (checkCost) { | ||
| double passPeople = scannerCost.nextDouble(); | ||
| if (passPeople > 1) { | ||
| cost += passPeople; | ||
| System.out.println("Товар добавлен! Введите название нового товара или напишите \"Завершить\"."); | ||
| break; | ||
| } else { | ||
| System.out.println("Ошибка. Введи целое число больше 1:"); | ||
| } | ||
| } else { | ||
| System.out.println("Ошибка. Введите число;"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cost != 11иcost % 100 != 11это одно и тоже, при делении по модулю числа 11 на 100 будет всё равно 11Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это для чисел больше 100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно оставить только
cost % 100 != 11. Для числа 111cost % 100 = 11, и для числа 11cost % 100 = 11