-
Notifications
You must be signed in to change notification settings - Fork 222
Проектная работа №1 #110
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
Gera-sim
wants to merge
3
commits into
Yandex-Practicum:master
Choose a base branch
from
Gera-sim:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Проектная работа №1 #110
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calculator { | ||
| String products = "\n"; //Аккумулируем товары | ||
| String prodName; //Наименование 1 шт из сканера | ||
| String exit = "завершить"; // Команда прерывания | ||
| String exitMessage = "Программа завершена"; // Сообщение после прерывания | ||
| double price = 0.00; //цена 1 шт вводимая пользователем | ||
| double sum = 0.00; // сумма | ||
| int countProducts; // Количество введенных товаров | ||
|
|
||
| public void consoleProducts() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| while (true) { | ||
| System.out.printf("Введите название товара или '%s' для выхода\n", exit); | ||
| prodName = scanner.next(); | ||
| if (prodName.equalsIgnoreCase(exit)) { | ||
| System.out.println(exitMessage); | ||
| break; | ||
| } | ||
| while (true) { | ||
| System.out.println("Введите стоимость товара в формате рубли.копейки. Например: 10,45"); | ||
| if (scanner.hasNextDouble()) { | ||
| price = scanner.nextDouble(); | ||
| if (price > 0.00) { | ||
| countProducts++; | ||
| products = products + prodName + " "; | ||
| sum += price; | ||
| break; | ||
| } | ||
| } else { | ||
| System.out.println("Ошибка ввода стоимости"); | ||
| scanner.next(); | ||
| } | ||
| } | ||
| System.out.println("Товар успешно добавлен."); | ||
| } | ||
| double bill = sum / Main.persons; | ||
| System.out.printf("Введены следующие товары, в количестве %d шт.:", countProducts); | ||
| System.out.print(products + "\n"); | ||
| System.out.println("Сумма на одного человека: " + String.format("%.2f", bill) + " " + rubles(bill)); | ||
| } | ||
|
|
||
| public String rubles(double a) { | ||
| int rub = (int) Math.floor(a); | ||
| if (rub % 100 > 5 && rub <= 20) { | ||
| return "рублей"; | ||
| } else if (rub % 10 == 1) { | ||
| return "рубль"; | ||
| } else if (rub % 10 > 1 && rub % 10 < 5) { | ||
| return "рубля"; | ||
| } | ||
| return "рублей"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| public class Main { | ||
|
|
||
| public static int persons; | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
|
|
||
| Persons.enterPersons(); | ||
|
|
||
| Calculator calculator = new Calculator(); | ||
| calculator.consoleProducts(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Persons { | ||
|
|
||
| public static void enterPersons() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("На скольких человек разделить счёт?\nВведите количество посетителей от 2 до 1000"); | ||
|
|
||
| while (true) { | ||
| if (scanner.hasNextInt()) { | ||
| Main.persons = scanner.nextInt(); | ||
|
|
||
| if (Main.persons > 1 && Main.persons < 1000) { | ||
| System.out.printf("Введено %d посетителей\n", Main.persons); | ||
| break; | ||
| } | ||
| } else { | ||
| System.out.println("Ошибка ввода. Попробуйте ещё раз."); | ||
| scanner.next(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Лучше количество человек возвращать как результат метода enterPersons, в Main его передавать в метод consoleProducts, а переменную Main.persons убрать. Так код будет более прозрачным