Repository navigation
prefinish #1
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
Sistem-Pack
wants to merge
1
commit into
main
Choose a base branch
from
dev
base: main
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
prefinish #1
Changes from all commits
Commits
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,35 @@ | ||
| public class Calculator { | ||
|
|
||
| double allPriceSum; | ||
| String basket; | ||
|
|
||
| public void addGoods(String newGoods, double goodsPrice) { | ||
| if (this.basket == null) { | ||
| this.basket = newGoods; | ||
| } else { | ||
| this.basket = this.basket + "\n" + ((this.basket.compareToIgnoreCase(newGoods) != 0) ? newGoods : ""); | ||
| } | ||
| this.allPriceSum = this.allPriceSum + goodsPrice; | ||
| } | ||
|
|
||
| public String correctStringCurrency(int peopleCount) { | ||
| double lastValue = (allPriceSum / peopleCount) % 100 / 10; | ||
| String retValue; | ||
| if ((int)lastValue == 1) { | ||
| return "рублей"; | ||
| } else { | ||
| switch ((int) Math.floor((allPriceSum / peopleCount) % 10)) { | ||
| case 1: | ||
| retValue = "рубль"; | ||
| break; | ||
| case 2, 3, 4: | ||
| retValue = "рубля"; | ||
| break; | ||
| default: | ||
| retValue = "рублей"; | ||
| break; | ||
| } | ||
| } | ||
| return retValue; | ||
| } | ||
| } |
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,57 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| // Объявим все что необходимо для работы | ||
| Calculator calculator = new Calculator(); | ||
| Scanner scan = new Scanner(System.in); | ||
| int peopleCount; | ||
|
|
||
| while (true) { | ||
| System.out.println("На сколько человек необходимо разделить счет?"); | ||
| try { | ||
| peopleCount = Integer.parseInt(scan.next()); | ||
| if (peopleCount < 1) { | ||
| System.out.println("Ошибка ввода попробуйте еще раз!"); | ||
| } else if (peopleCount == 1) { | ||
| System.out.println("Счет не может быть разделен на одного человека. Попробуйте еще раз!"); | ||
| } else { | ||
| break; | ||
| } | ||
| } catch (NumberFormatException ex) { | ||
| System.out.println("Ошибка ввода! Возможен только ввод целых чисел."); | ||
| } | ||
| } | ||
|
|
||
| // переменные для записи товара | ||
| double price; | ||
| String goodsName; | ||
| while (true) { | ||
| System.out.println("Введите наименование товара: "); | ||
| goodsName = scan.next(); | ||
| while (true) { | ||
| System.out.println("Введите стоимость товара: "); | ||
| try { | ||
| price = Double.parseDouble(scan.next()); | ||
|
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. Также по аналогии у |
||
| if (price <= 0) { | ||
| System.out.println("Стоимость товара не может быть отрицательной или меньше 0"); | ||
| } | ||
| break; | ||
| } catch (NumberFormatException ex) { | ||
| System.out.println("Ошибка ввода! Необходимо ввести стоимость товара в формате рубли.копейки."); | ||
| } | ||
| } | ||
| calculator.addGoods(goodsName, price); | ||
| System.out.println("Товар добавлен в корзину!"); | ||
| System.out.println("Хотите ли вы добавить еще товар?"); | ||
| if (scan.next().toLowerCase().compareTo("завершить") == 0) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| System.out.println("Добавленные товары: " + "\n" + calculator.basket); | ||
| System.out.println("Стоимость счета на каждого человека составляет: " + | ||
| String.format("%.2f", calculator.allPriceSum / peopleCount) + " " + calculator.correctStringCurrency(peopleCount)); | ||
| scan.close(); | ||
| } | ||
| } | ||
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.
У
Scannerесть удобный методhasNextInt, можно сразу узнать без дополнительных проверок возможно ли интерпретировать строку какint