-
Notifications
You must be signed in to change notification settings - Fork 218
Сдача калькулятора счета #93
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class List { | ||
| static double totalPrice = 0.00f; | ||
| static String listProduct = ""; | ||
| public static void requestProduct() { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| while(true) { | ||
|
|
||
|
|
||
| System.out.println("Введите название товара"); | ||
| String name = scanner.next(); | ||
| listProduct = listProduct.concat(name + ";\n"); | ||
| System.out.println("Введите цену товара"); | ||
| double price = checkFailPrice(); | ||
| totalPrice += price; | ||
| System.out.println("Товар успешно добавлен!\nЕсли хотите добавить еще товар введите любой символ.\nДля завершения создания списка напините \"Завершить\"."); | ||
| String result = scanner.next(); | ||
| if(result.equalsIgnoreCase("Завершить")){ | ||
| break; | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } | ||
| public static String whichRub(double num){ | ||
| int sum = (int)num; | ||
| sum = sum % 100; | ||
| if(10<sum && sum<15){ | ||
| return "рублeй"; | ||
| } | ||
| int sum1 = sum % 10; | ||
| switch(sum1){ | ||
| case 1: return "рубль"; | ||
| case 2: | ||
| case 3: | ||
| case 4: return "рубля"; | ||
|
|
||
| } | ||
| return "рублeй"; | ||
| } | ||
| public static void makeList() { | ||
| double priceForOne = totalPrice / People.persons; | ||
| String end = "Добавленные товары:\n%s%.2f %s должен заплатить каждый человек."; | ||
| System.out.println(String.format(end, listProduct, priceForOne,whichRub(priceForOne))); | ||
| } | ||
| public static double checkFailPrice() { | ||
| while(true) { | ||
| Scanner scanner = new Scanner(System.in); | ||
| boolean hasDouble = scanner.hasNextDouble(); | ||
| if(hasDouble) { | ||
| double trueDouble = scanner.nextDouble(); | ||
| if (trueDouble > 0) { | ||
| return trueDouble; | ||
| } else { | ||
| System.out.println("Ошибка! Введите корректную цену."); | ||
| } | ||
| } | ||
| else { | ||
| System.out.println("Ошибка! Введите корректную цену."); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| System.out.println("Привет!"); | ||
| People.howMany(); | ||
| List.requestProduct(); | ||
| List.makeList(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class People { | ||
|
|
||
| public static int persons; | ||
|
|
||
| public static void howMany(){ | ||
| System.out.println("На скольких человек необходимо разделить счёт?"); | ||
| while(true) { | ||
| Scanner scanner = new Scanner(System.in); | ||
| boolean hasInt = scanner.hasNextInt(); | ||
| if(hasInt) { | ||
| int hasPersons = scanner.nextInt(); | ||
| if (hasPersons > 1) { | ||
| persons = hasPersons; | ||
| return; | ||
| } else { | ||
| System.out.println("Ошибка! Введите корректное число."); | ||
| } | ||
| } | ||
| else { | ||
| System.out.println("Ошибка! Введите корректное число."); | ||
| } | ||
| } | ||
| } | ||
| } |
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.
Для множественного выбора лучше использовать конструкцию switch-case