Repository navigation
Sprint02consoleAppPaffn #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
Merged
Changes from all commits
Commits
Show all changes
6 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,16 @@ | ||
|
|
||
| import java.util.Scanner; | ||
| public class Calculator { | ||
|
|
||
| String itemNameList = ""; | ||
| int numItems; | ||
| float price; | ||
|
|
||
|
|
||
| Calculator (String itemNameList, float price, int numItems ) { | ||
| this.itemNameList = itemNameList; | ||
| this.price = price; | ||
| this.numItems = numItems; | ||
| } | ||
|
|
||
| } | ||
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,51 @@ | ||
| // dev branch for Y.Practicum | ||
|
|
||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
| Calculator calcPersonBill = new Calculator("", 0, 0); | ||
|
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. ⏫ Можно для полей класса |
||
| checkAndFormat checker = new checkAndFormat(); | ||
| //System.out.println("Привет мир!!!"); | ||
| System.out.println("На сколько человек желаете разделить счёт?"); | ||
|
|
||
| // проверка ввода на тип int | ||
| int numPerson = checker.checkPersonVal(); | ||
|
|
||
| while (true) { | ||
| System.out.println("Введите Название товара"); | ||
|
|
||
| calcPersonBill.itemNameList = calcPersonBill.itemNameList + "\n" + scanner.nextLine(); // добавляем имя в строку | ||
|
|
||
| System.out.println("Введите цену товара"); | ||
|
|
||
| calcPersonBill.price = calcPersonBill.price + checker.checkItemVal(); // Складываем полученые цены по мере ввода | ||
| //scanner.nextLine(); // специфичный метод для завершения ввода... | ||
|
|
||
| System.out.println("Товар добавлен"); | ||
| System.out.println("Еще добавим?"); | ||
|
|
||
| if ((scanner.nextLine()).equalsIgnoreCase("Завершить")) { // проверка если пользователь завершил ввод | ||
| break; | ||
| } else calcPersonBill.numItems++; | ||
| } | ||
| float eachPrice = calcPersonBill.price/numPerson; | ||
|
|
||
| System.out.print("Добавленные товары:"); | ||
| System.out.println(calcPersonBill.itemNameList); | ||
| System.out.println(" "); | ||
|
|
||
| //String totalSum = "Общая сумма товаров: %.2f"; | ||
| System.out.print("Общая сумма товаров: "); | ||
| checker.moneyUnitformat(calcPersonBill.price); // печать суммы товаров правильным с окончанием рублей | ||
|
|
||
| System.out.print("Сумма к оплате с человека: "); | ||
| checker.moneyUnitformat(eachPrice); // печать Сумма к оплате с человека правильным с окончанием рублей | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
||
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,83 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class checkAndFormat { | ||
|
|
||
|
|
||
| // Обработка слова Рубль и вывод на печать | ||
| public static void moneyUnitformat (float Munit) { | ||
| String money = ""; | ||
| //String totalSum = "Общая сумма товаров: %.2f"; | ||
|
|
||
| int iMunit = (int)Munit; | ||
| int mCh = iMunit%10; | ||
|
|
||
| if (iMunit%100>=11 && iMunit<=14) { | ||
| money = "%.2f рублей"; | ||
| System.out.println(String.format(money, Munit)); | ||
| } else { | ||
| switch (mCh) { | ||
| case 1: | ||
| money = "%.2f рубль"; | ||
| System.out.println(String.format(money, Munit)); | ||
| break; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| money = "%.2f рубля"; | ||
| System.out.println(String.format(money, Munit)); | ||
| break; | ||
| default: | ||
| money = "%.2f рублей"; | ||
| System.out.println(String.format(money, Munit)); | ||
| } | ||
| } | ||
| } | ||
| // функция проверки корректности ввода количества человек и далее вывода в main | ||
| public static int checkPersonVal() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| while (true) { | ||
| if (!scanner.hasNextInt()) { | ||
| System.out.println("Извините, но это явно не число. Введите число и попробуйте снова!"); | ||
| scanner.nextLine();} | ||
| else break; | ||
| } | ||
|
|
||
| int numPerson = scanner.nextInt(); | ||
| scanner.nextLine(); | ||
|
|
||
| while (true) { | ||
| if (numPerson <= 1) { | ||
| System.out.println("Значение не подходит, введите другое значение"); | ||
| numPerson = scanner.nextInt(); | ||
| scanner.nextLine(); // специфичный метод для завершения ввода... | ||
| } | ||
| else break; | ||
| } | ||
| return numPerson; | ||
| } | ||
|
|
||
| // функция проверки корректности ввода цены товара и далее вывода в main | ||
| public static float checkItemVal() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| while (true) { | ||
| if (!scanner.hasNextFloat()) { | ||
| System.out.println("Извините, но это явно не число. Введите число и попробуйте снова!"); | ||
| scanner.nextLine();} | ||
| else break; | ||
| } | ||
| float Item = scanner.nextFloat(); | ||
| scanner.nextLine(); // специфичный метод для завершения ввода... | ||
|
|
||
| while (true) { | ||
| if (Item < 0) { | ||
| System.out.println("Значение не подходит, введите другое значение"); | ||
| Item = scanner.nextInt(); | ||
| scanner.nextLine(); | ||
| } | ||
| else break; | ||
| } | ||
| return Item; | ||
| } | ||
|
|
||
|
|
||
| } |
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.
👍 Хорошая идея использовать отдельный класс, для хранения стейта работы программы.
⏫ Я бы посоветовал разделить логику хранения стейта и вывода верного значения "рублей" на разные классы, т.к. это две разные не связанные друг с другом логики