-
Notifications
You must be signed in to change notification settings - Fork 0
Не бейте сильно пишу первый раз в жизни :( #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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| public class Calc { | ||
| String productNameC = ""; | ||
|
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. Названия productName вполне достаточно для понимания зачем оно нужно |
||
| static double finalCost = 0; | ||
| static double finalCostEach = 0; | ||
|
|
||
| public void productCalc(String name, double price) { | ||
| if (price <= 0) { | ||
| System.out.println("Вы ошиблись.\nПопробуйте ещё!"); | ||
| } else { | ||
| finalCost = finalCost + price; | ||
| productNameC = productNameC + name + "\n"; | ||
| System.out.println("Добавили! Едем дальше!"); | ||
| } | ||
| } | ||
|
|
||
| public void finCountDown(int guestNumber) { | ||
| System.out.println("Добавлено:\n" + productNameC); | ||
| finalCostEach = finalCost / guestNumber; | ||
| System.out.println("С каждого:\n" + String.format("%.2f", finalCostEach) + FormRub.priceForm2()); | ||
| System.out.println("Всего:\n" + String.format("%.2f", finalCost) + FormRub.priceForm1()); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| public class FormRub { | ||
|
|
||
| public static String priceForm1() { | ||
| if ((int)(Calc.finalCost % 100 / 10) == 1){ | ||
| return " рублей."; | ||
| } | ||
| if ((int) (Calc.finalCost % 10) == 1) { | ||
| return " рубль."; | ||
| } else if ((int) (Calc.finalCost % 10) == 2 || (int) (Calc.finalCost % 10) == 3 || (int) (Calc.finalCost % 10) == 4) { | ||
|
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. Как совет, ты можешь парой строчек выше завести переменную типа |
||
| return " рубля."; | ||
| } | ||
| return " рублей."; | ||
| } | ||
|
|
||
| public static String priceForm2() { | ||
| if ((int)(Calc.finalCostEach % 100 / 10) == 1){ | ||
| return " рублей."; | ||
| } | ||
| if ((int) (Calc.finalCostEach % 10) == 1) { | ||
| return " рубль."; | ||
| } else if ((int) (Calc.finalCostEach % 10) == 2 || (int) (Calc.finalCostEach % 10) == 3 || (int) (Calc.finalCostEach % 10) == 4) { | ||
| return " рубля."; | ||
| } | ||
| return " рублей."; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Gests { | ||
|
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. Если предполагалось, что название класса переводится как "Гость", то тут опечатка
Owner
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. Да нет , я пока писал неслолько раз создавал похожие классы. |
||
| public static int guestNumber; | ||
| public static void Gest() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("На какое количество человек разделить счет?"); | ||
| guestNumber = 0; | ||
| while(true) | ||
| if (scanner.hasNextInt()) { | ||
| guestNumber = scanner.nextInt(); | ||
| if (guestNumber <= 1) { | ||
| System.out.println("Слишком маленькое число попробуйте еще"); | ||
| } else { | ||
| return; | ||
| } | ||
| }else{ | ||
| System.out.println("Это не число"); | ||
| scanner.nextLine(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| Gests.Gest(); | ||
| Talk.Talking(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Talk { | ||
| public static void Talking() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| Calc calculator = new Calc(); | ||
| while (true) { | ||
| System.out.println("Введите название товара"); | ||
| String name = scanner.next(); | ||
| System.out.println("Введите стоимость"); | ||
| if (scanner.hasNextDouble()) { | ||
| double price = scanner.nextDouble(); | ||
| calculator.productCalc(name, price); | ||
| System.out.println("Добавим еще? Введите любой символ.\nЕсли нет напишите \"Завершить\""); | ||
| } else { | ||
| System.out.println("Ошибка попробуй еще!"); | ||
| } | ||
| String end = scanner.next(); | ||
| if (end.trim().equalsIgnoreCase("завершить")) { | ||
| calculator.finCountDown(Gests.guestNumber); | ||
| System.out.println("Кониек"); | ||
| break; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| } |