Repository navigation
Практическая работа по первому спринту, правка1 #2
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
Merged
Changes from all commits
Commits
Show all changes
4 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,45 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Goods { // Создаем класс со статическими переменными, хранящие сумму заказа и названия товаров | ||
| String name; | ||
| double price; | ||
| static double sum = 0; | ||
| static String names = ""; | ||
|
|
||
| public Goods(String n, double p) { | ||
| price = p; | ||
| name = n; | ||
| sum += price; | ||
| names += "\n" + name; | ||
| } | ||
|
|
||
| public static void calculator() { // метод для добавления товаров | ||
| Scanner scanner = new Scanner(System.in); | ||
| String check = "0"; | ||
| while (check.toLowerCase() != "завершить") { | ||
| if (check.toLowerCase().equals("завершить")) break; | ||
| else { | ||
| String name; | ||
| double price = -1; | ||
| while (price < 0) { | ||
| System.out.println("Введите название товара:"); | ||
| name = scanner.next(); | ||
| System.out.println("Введите стоимость товар:"); | ||
| while (!scanner.hasNextDouble()) { | ||
| scanner.next(); | ||
| System.out.println("Что-то не так, попробуйте еще раз, но с цифрами!"); | ||
| } | ||
| price = scanner.nextDouble(); | ||
| if (price > 0) { | ||
| Goods nnew = new Goods(name, price); | ||
| break; | ||
| } else { | ||
| System.out.println("Неверный ввод! попробуйте еще раз"); | ||
| } | ||
| } | ||
| System.out.println("Желаете продолжить? Для выхода введите 'завершить'"); | ||
| check = scanner.next(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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,6 +1,60 @@ | ||
|
|
||
| import java.util.Scanner; | ||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| int persons = countPersons(); | ||
| Goods.calculator(); | ||
| double part = Goods.sum / persons; | ||
| System.out.println("Добавленные товары:" + Goods.names + "\n"); | ||
| System.out.println("Сумма товаров " + String.format("%.2f", Goods.sum) + " " + howToWriteRubles(Goods.sum)); | ||
| System.out.println("Каждый должен заплатить " + String.format("%.2f", part) + " " + howToWriteRubles(part)); | ||
| } | ||
|
|
||
| public static int countPersons() { //метод для подсчета числа посетителей | ||
|
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. 🍏 |
||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("На сколько человек нужно разделить счет?"); | ||
| int persons = 0; | ||
| while (persons <= 1) { | ||
| while(!scanner.hasNextInt()){ | ||
| scanner.next(); | ||
| System.out.println("Что-то не так, попробуйте еще раз, но с цифрами!"); | ||
| } | ||
| persons = scanner.nextInt(); | ||
| if (persons > 1) { | ||
| break; | ||
| } else { | ||
| System.out.println("Неверное значение, попробуйте еще раз!"); | ||
| } | ||
| } | ||
| return persons; | ||
| } | ||
|
|
||
|
|
||
| public static String howToWriteRubles(double p){ //метод для определения падежа слова "рубль" | ||
| int rubles = (int) (p % 100); | ||
| String write = ""; | ||
|
|
||
| if (rubles >= 11 && rubles <= 19){ | ||
| write = "рублей"; | ||
| } else { | ||
| rubles %= 10; | ||
| switch (rubles) { | ||
| case 1: | ||
| write = "рубль"; | ||
| break; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| write = "рубля"; | ||
| break; | ||
| case 5: | ||
| case 6: | ||
| case 7: | ||
| case 8: | ||
| case 9: | ||
| case 0: | ||
| write = "рублей"; | ||
| } | ||
| } | ||
| return write; | ||
| } | ||
| } | ||
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.
🍏 Необязательно их было делать
static. По хорошему, один объект классаGoodдолжен был соответствовать одному товару, а методcalculatorлучше было сделать классомCalculatorс методомcalculate(названия классов - существительные, названия методов - желательно глаголы).