-
Notifications
You must be signed in to change notification settings - Fork 220
ПР по домашнему заданию по результатам 2 спринта #122
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
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
83a7216
Init commit
0580674
Change project name
6c18393
Merge remote-tracking branch 'origin/master'
AshZoom ab6a7a3
Merge remote-tracking branch 'origin/master'
AshZoom e22643c
Merge remote-tracking branch 'origin/master'
AshZoom b852f71
Merge remote-tracking branch 'origin/master'
AshZoom fa20498
Merge remote-tracking branch 'origin/master'
AshZoom d0d3d01
Домашнее задание по реузльтатам 2 спринта А.Шмаков
AshZoom d318a18
Исправление замечаний от 09.11.22 (Домашнее задание по результатам 2 ...
AshZoom 612491c
Исправление замечаний от 09.11.22 (Домашнее задание по результатам 2 ...
AshZoom 3c1fd83
Merge remote-tracking branch 'origin/master'
AshZoom 20a83e0
Merge remote-tracking branch 'origin/master'
AshZoom 4678bed
Merge remote-tracking branch 'origin/master'
AshZoom 1224567
Merge branch 'master' into main
AshZoom 6093590
Merge pull request #1 from AshZoom/main
AshZoom 05a9371
Merge remote-tracking branch 'origin/master'
AshZoom cc2f795
Merge remote-tracking branch 'origin/master'
AshZoom b977276
Merge remote-tracking branch 'origin/master'
AshZoom 461b194
Исправление замечаний по проеткной работе 1
AshZoom 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.
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.
50 changes: 50 additions & 0 deletions
src/main/java/EndofRUB.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,50 @@ | ||
| public class EndofRUB { | ||
|
|
||
| // Метод проверки падежа и окончания в слове руб. | ||
| // Для определения нужного падежа достаточно проверять последние 1-2 цифры числа | ||
| //Для этого выделяем их из числа с помощью Math.floor()-возвращает число ближайшее | ||
| // к аргументу слева. Если остаток будет равен 1 -окончание "рубль", если 11 - "рублей" | ||
| // аналогично с 2;3 и 4.Поэтому необходимое условие для этих цифр result % 100 >= 11 && result % 100 <= 14 | ||
|
|
||
|
|
||
| public static void endOfWord(double single) { | ||
| if ((int) Math.floor(single) % 100 >= 11 && (int) Math.floor(single) % 100 <= 14) { | ||
| System.out.printf("%.2f рублей%n",single); | ||
| } else { | ||
| switch ((int)Math.floor(single)%10) { | ||
| case 1: | ||
| System.out.printf("%.2f рубль%n",single); | ||
| break; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| System.out.printf("%.2f рубля%n",single); | ||
| break; | ||
| default: | ||
| System.out.printf("%.2f рублей%n",single); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
| //1- рубль | ||
| //2- рубля | ||
| //3- рубля | ||
| //4- рубля | ||
| //5- рублей | ||
| //6- рублей | ||
| //7- рублей | ||
| //8- рублей | ||
| //9- рублей | ||
| //10- рублей | ||
| //11- рублей | ||
| //12- рублей | ||
| //13- рублей | ||
| //14- рублей | ||
| //15- рублей | ||
| //16- рублей | ||
| //17- рублей | ||
| //18- рублей | ||
| //19- рублей | ||
| //20- рублей |
31 changes: 30 additions & 1 deletion
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,8 +1,37 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| //System.out.println("Привет Мир"); | ||
|
|
||
| // static short numberOfPeople; | ||
| String list=""; | ||
| Double result=0.00; | ||
|
|
||
| //вводим количество участников и сохраняем в переменной people | ||
|
|
||
| People.countPeople(); | ||
| while(Products.finishOfList) { | ||
| list = list + Products.inputOfProducts()+"\n"; | ||
| Products.exitOfList(); | ||
| } | ||
|
|
||
|
|
||
| //вывод данных | ||
| System.out.print("Всего добавлено в список: "+(Products.count-1)+" поз."+"\n"); | ||
| System.out.println(list); | ||
| //System.out.println(String.format("Итого: "+"%.2f"+" руб.",Products.total)); | ||
| System.out.printf("Итого: "+"%.2f"+ "руб.%n",Products.total); | ||
| System.out.println("Делим на: "+People.numberOfPeople+" участников"); | ||
| result=Products.total/People.numberOfPeople; | ||
| System.out.println("Каждый участник должен заплатить: "); | ||
| //вызываем метод правильного окончания слова 'рубли' | ||
| EndofRUB.endOfWord(result); | ||
|
|
||
|
|
||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
src/main/java/People.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,37 @@ | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class People { | ||
|
|
||
| static Short numberOfPeople;// объявляем статическую переменную число участников для передачи в класс Main | ||
|
|
||
| public static void countPeople() { | ||
| Scanner scanner=new Scanner(System.in); | ||
| System.out.println("Добрый день"); | ||
|
|
||
|
|
||
| while (true) { | ||
| System.out.println("На сколько человек разделить счёт?"); | ||
|
|
||
| if (scanner.hasNextInt()){ | ||
| numberOfPeople = scanner.nextShort(); | ||
| if (numberOfPeople > 1) { | ||
| System.out.println("Делим счёт на "+ numberOfPeople+ " гостей");//получили число участников | ||
| break; | ||
| }else{ | ||
| if (numberOfPeople <= 1) { | ||
| System.out.println("Неправильный ввод. Попробуйте ввести число участников ещё раз."); | ||
| } | ||
| } | ||
|
|
||
| }else{ | ||
| System.out.println("Неправильный ввод. Попробуйте ввести число участников в числовом формате."); | ||
| scanner.nextLine(); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
src/main/java/Products.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,61 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Products { | ||
|
|
||
|
|
||
| String name;// объявляем статическую переменную списка позиций для передачи в класс Main | ||
| Double price; | ||
| static int count = 1; | ||
| static String nameOfgoods; | ||
| static Double total=00.00; | ||
| static Boolean finishOfList=true; | ||
|
|
||
| //конструктор | ||
| public Products(String name, double price) { | ||
| this.name = name; | ||
| this.price = price; | ||
|
|
||
| } | ||
| // метод составления списка товаров | ||
| public static String inputOfProducts() { | ||
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("Укажите наименование Товара:"); | ||
| String nameOfgoods = scanner.next(); | ||
| System.out.println("Укажите стоимость Товара в формате 'рубли.копейки' (пример:10.45 или 11.40):"); | ||
|
|
||
| Double j; | ||
| while (true) { | ||
| try { | ||
| String priceOfgood = scanner.next(); | ||
| j = Double.parseDouble(priceOfgood); | ||
| if(j<0){ | ||
| System.out.println("Неправильный ввод. Попробуйте ещё раз."); | ||
| }else { | ||
| break; | ||
| } | ||
| } catch (Exception e) { | ||
| System.out.println("Неправильный ввод. Попробуйте ещё раз."); | ||
| scanner.nextLine(); | ||
| } | ||
| } | ||
|
|
||
| //записываем в nameOfgoods наименование и цену товара | ||
| nameOfgoods = String.format("Поз." + count + ": " + nameOfgoods + " " + "%.2f" + " руб.", j); | ||
| System.out.println("Товар добавлен в список " + nameOfgoods); | ||
| count++;//количество позиций в списке | ||
| total += j;//вычисляем общую стоимость всех введенных товаров | ||
| return nameOfgoods;//на выходе в name добавленный товар и его цена | ||
| } | ||
|
|
||
| //метод проверки выхода из процесса составления списка товаров | ||
|
|
||
| public static void exitOfList() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("Хотите добавить что нибудь ещё?"+" Если да, введите любой символ или слово :"); | ||
| System.out.println("Если добавить нечего введите 'завершить':"); | ||
| String add = scanner.next(); | ||
| finishOfList= !add.equalsIgnoreCase("завершить"); | ||
| } | ||
|
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-else конструкцию упростить до такой:
Author
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. Исправлено. Не знал о такой конструкции :( |
||
|
|
||
| } | ||
18 changes: 18 additions & 0 deletions
src/main/java/Test.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,18 @@ | ||
| import java.util.Scanner; | ||
|
|
||
|
|
||
| public class Test { | ||
|
|
||
| static String name; | ||
| static int age; | ||
|
|
||
| //для домашних котов | ||
| public void Test (String name, int age) { | ||
| this.name = name; | ||
| this.age = age; | ||
| } | ||
|
|
||
| //для уличных котов | ||
| public void Test() { | ||
| } | ||
| } |
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.