forked from Yandex-Practicum/Java-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Сдача проекта . Попытка 2 #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
Open
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e1f6893
Remove classes
c521234
Change project name
33eee81
Привет Мир2
MaksBujanov 1842ea5
Main Ver1. Все подряд.
MaksBujanov 7f65249
Main Ver2. Все подряд.
MaksBujanov fd6cf61
Main Ver4. пишу склонение по падежам
MaksBujanov e36046e
padeg.java ver2
MaksBujanov e12a616
+ equalsIgnoreCase
MaksBujanov 0de22fb
пишем Calc
MaksBujanov d49a0dd
Победил Передачу атрибутов из другого класса
MaksBujanov 08a74ed
Победил Передачу атрибутов из другого класса
MaksBujanov 8cfe53d
Переписал Standart.java
MaksBujanov 7a09aa4
Почистил код от пробелов, комментариев, сократил условие в классе Sta...
MaksBujanov 3bb509a
Автозамена public static double getCheck и static double check
MaksBujanov d6bd8b7
01,12,2022
MaksBujanov aa86aba
calculate.addItem(new Item(productName, stoimost));
MaksBujanov b25f9a1
ошибка со скобкой?
MaksBujanov 5729c70
закомментировал не используемые методы
MaksBujanov c4d1c87
Сдаем проект. Попытка 1
MaksBujanov 507d6bb
// class Main доработка замечание 1: проверка на корректный ввод коли...
MaksBujanov 082f3a4
Склонение
MaksBujanov 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
3 changes: 3 additions & 0 deletions
.idea/.gitignore
Oops, something went wrong.
1 change: 1 addition & 0 deletions
.idea/.name
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
.idea/compiler.xml
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
.idea/gradle.xml
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
.idea/misc.xml
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
.idea/vcs.xml
Oops, something went wrong.
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
28 changes: 28 additions & 0 deletions
src/main/java/Calc.java
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,28 @@ | ||
| public class Calc { | ||
| int friends; | ||
| Calc(int friends){ | ||
| this.friends = friends; | ||
| } | ||
| public String pokupki = "Добавленные товары: " ; | ||
| static double check = 0; //автоисправление узнать что такое static | ||
|
|
||
|
|
||
| //void addItem(String productName, double stoimost){ //Передали атрибуты из Item | ||
| // check = check + stoimost; | ||
| // String pokupki = "Добавленные товары:"+ "\n" + productName; | ||
| // System.out.println(pokupki); | ||
| //} | ||
| void addItem(Item item){ //Передали объект из Item | ||
| check = check + item.stoimost; | ||
| pokupki = pokupki + "\n" + item.productName + " " + item.stoimost ; | ||
| System.out.println(pokupki); | ||
| } | ||
|
|
||
| public static double getCheck( ) { //автоисправление узнать что такое static | ||
| return check; | ||
| } | ||
| //public static String getPokupki( ) { //автоисправление узнать что такое static | ||
| // return pokupki; | ||
| //} | ||
| } | ||
| // создание методов https://practicum.yandex.ru/learn/android-developer/courses/227fb78c-0def-4f2d-9129-dd289b3b2a28/sprints/87572/topics/5c1c6f94-f9bb-472c-8bb0-bd3011cfb402/lessons/57aa24d1-7260-4e2a-b965-4e4dd2461e73/ |
22 changes: 0 additions & 22 deletions
src/main/java/Calculator.java
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
src/main/java/Formatter.java
Oops, something went wrong.
22 changes: 14 additions & 8 deletions
src/main/java/Item.java
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,10 +1,16 @@ | ||
| class Item { | ||
| public class Item { | ||
| String productName; | ||
| double stoimost; | ||
|
|
||
| String name; | ||
| double price; | ||
|
|
||
| Item(String name, double price) { | ||
| this.name = name; | ||
| this.price = price; | ||
| Item(String productName, double stoimost) { | ||
| this.productName = productName; | ||
| this.stoimost = stoimost; | ||
| } | ||
| } | ||
|
|
||
| //public String productName() { | ||
| // return productName; | ||
| //} | ||
| // public double getstoimost() { | ||
| // return stoimost; | ||
| // } | ||
| } |
95 changes: 59 additions & 36 deletions
src/main/java/Main.java
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,49 +1,72 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| import java.util.Scanner; // Добавили ввод с клавиатуры | ||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| int friendCount; | ||
| while (true) { | ||
| System.out.println("На сколько человек необходимо разделить счет?"); | ||
| friendCount = scanner.nextInt(); | ||
|
|
||
| if (friendCount > 1) { | ||
| // ваш код начнется здесь | ||
| Scanner scanner; | ||
| scanner = new Scanner(System.in); | ||
| System.out.println("Введите на скольких человек необходимо разделить счёт"); | ||
| int friends ; | ||
| while (true) { // Запускаем бесконечный цикл | ||
| //доработка замечание 1 START | ||
| //проверка на корректный ввод количества людей: 1.нечисловой ввод 2.дробное число | ||
| if (scanner.hasNextInt()) { | ||
| friends = scanner.nextInt(); //Получаем кол-во гостей от пользователя | ||
| System.out.println("Хорошо"); | ||
| }else { | ||
| System.out.println("Ошибка!!!Допустим ввод только целых чисел"); | ||
| scanner.next(); | ||
| continue; | ||
| } | ||
| //доработка замечание 1 END | ||
| if (friends > 1) { | ||
| System.out.println(friends + " Гостей"); | ||
| //return friends; | ||
| break; | ||
| } else if (friendCount == 1) { | ||
| System.out.println( | ||
| "Нет смысла делить сумму на одного человека. Давайте попробуем ввести другое значение, которое будет больше единицы."); | ||
| } else { | ||
| System.out.println("Неверное количество друзей. Значение должно быть болье единицы, давайте попробуем еще раз."); | ||
| } | ||
| else if (friends==1) { | ||
| System.out.println("нет смысла ничего считать и делить. Введите значение заново"); | ||
| } | ||
| else { | ||
| System.out.println("Это некорректное значение для подсчёта, количество гостей должно быть >1 . Введите значение "); | ||
| } | ||
| } | ||
|
|
||
| Calculator calculator = new Calculator(friendCount); | ||
|
|
||
| while (true){ | ||
| Calc calculate = new Calc(friends); | ||
| double stoimost; | ||
| while (true){ | ||
| System.out.println("Введите название товара"); | ||
| String name = scanner.next(); | ||
|
|
||
| System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [10.45, 11.40]"); | ||
| double price = scanner.nextDouble(); | ||
|
|
||
| calculator.addItem(new Item(name, price)); | ||
|
|
||
| System.out.println( | ||
| "Хотите добавить еще один товар? Введите любой символ для продолжения, либо 'Завершить' если больше нет товаров для добавления"); | ||
| String answer = scanner.next(); | ||
| String productName = scanner.next(); | ||
| System.out.println("Введите стоимость товара. Она должна быть в формате рубли.копейки, например 10.45 или 11.40."); | ||
| //доработка замечания 2 START 1.ввод букв в качестве стоимости 2. ввод отрицательной стоимости 3. любой некорректный ввод | ||
| while (true) { | ||
| if (scanner.hasNextDouble()) { | ||
| stoimost = scanner.nextDouble();//Double т.к. формат рубли,копейки | ||
| if (stoimost<0){ | ||
| System.out.println("Ошибка!!! цена не может быть отрицательной. введите стоимость заново"); | ||
| continue; | ||
| }else{ | ||
| break; | ||
| } | ||
| } else { | ||
| System.out.println("Ошибка!!! Допустим ввод только числа в формате рубли,копейки"); | ||
| scanner.next(); | ||
| continue; | ||
| } | ||
| } | ||
| //доработка замечание 2 END | ||
| calculate.addItem(new Item(productName, stoimost)); //создадим товар и применим к нему метод addItem класса Calc | ||
| System.out.println("Добавить ещё один товар? Введите 'Завершить' если больше нет товаров для добавления"); | ||
|
|
||
| if (answer.equalsIgnoreCase("Завершить")) { | ||
| if (scanner.next().equalsIgnoreCase("Завершить")) {// Сравниваем что ввел пользователь с ключевым словом Завершить без учета регистра | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| double result = calculator.divideSum(); | ||
| Formatter formatter = new Formatter(); | ||
|
|
||
| System.out.println(calculator.cart); | ||
| System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result)); | ||
| double check = Calc.getCheck();// получили общий чек с покупок | ||
| double itog = check / friends; // делим чек на всех друзей | ||
| Standart standart = new Standart();// Вызов конструктора с параметрами | ||
| System.out.println(calculate.pokupki); | ||
| System.out.println("к оплате:" + standart.round(itog) + standart.padeg(itog)); | ||
| } | ||
| } | ||
| //https://proglang.su/java/strings-equalsignorecase | ||
| //retVal = Str1.equalsIgnoreCase(Str2); |
28 changes: 28 additions & 0 deletions
src/main/java/Standart.java
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,28 @@ | ||
| public class Standart { | ||
| String padeg (double stoimost){ | ||
| double padeg = Math.floor(stoimost); | ||
| // доработка замечание 3: склонение. анализируем остатокот деления | ||
| if ( (( padeg <= 5)&&(padeg <= 20)) || padeg % 10 == 0){ | ||
| return " рублей"; | ||
| } else if (padeg == 1 || padeg % 10 == 1){ | ||
| return " рубль"; | ||
| } else if (padeg == 2 || padeg % 10 == 2 || padeg == 3 || padeg % 10 == 3 || padeg == 4 || padeg % 10 == 4){ | ||
| return " рубля"; | ||
| } | ||
| else { | ||
| return " рублей"; | ||
| } | ||
| } | ||
| String round(double itog){ | ||
| return String.format("%.2f", itog); | ||
| } | ||
| } | ||
| // Вывод суммы, которую должен заплатить каждый человек, должен быть в формате "10.45". | ||
| // Дробная часть не должна содержать больше двух чисел после запятой. | ||
| //Сумма считается в рублях. Ваша задача — обработать правильный вывод. Если сумма 1.45, | ||
| //то вы должны вывести "1.45 рубль", а если сумма будет 3.20 или 4.00, | ||
| //вы должны вывести 3.20 рубля и 4.00 рубля. | ||
| // Окончания в слове "рубль" должны зависеть от целочисленной части. | ||
|
|
||
| //https://proglang.su/java/numbers-floor | ||
| // Math.floor(f1) |
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.