-
Notifications
You must be signed in to change notification settings - Fork 222
Homework #99
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?
Homework #99
Changes from all commits
28e2a95
18e82af
64686f2
0d16318
42ecc41
86f031c
c2fbc1b
1e409ea
0d2043e
a5befd3
066c7c2
eaf62df
61a9d9d
3c5d748
a76c9b7
f04d0c2
7f37eee
27383aa
6d6c757
7ba8870
18fad59
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.
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,42 @@ | ||
| public class Calculator { | ||
|
|
||
| String bill = ""; | ||
| double finalPrice = 0; | ||
| int countPerson = 0; | ||
|
|
||
| double priceOfPerson = 0; | ||
|
|
||
| public void setCountPerson(int countPerson) { | ||
| this.countPerson = countPerson; | ||
| } | ||
|
|
||
| public void setBill(Product product) { | ||
| bill += (product.getNameOfProduct() + " " + product.getCost()) + "\n"; | ||
| finalPrice += product.getCost(); | ||
| } | ||
|
|
||
| public String math() { | ||
| String rubles = "руб"; | ||
| if (priceOfPerson > 10 && priceOfPerson <20 ) { | ||
| return rubles + "лей"; | ||
| } switch ((int) priceOfPerson % 10) { | ||
| case 1: { | ||
| return rubles + "ль"; | ||
| } | ||
| case 2: | ||
| case 3: | ||
| case 4: { | ||
| return rubles + "ля"; | ||
| } | ||
| default: { | ||
| return rubles + "лей"; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void calculate() { | ||
| priceOfPerson = finalPrice / countPerson; | ||
| System.out.println("Количество персон: " + countPerson + "\n" + "Общий чек: " + | ||
| "\n" + bill + "\n" + "Денег с человека:" + "\n" + String.format("%.2f", priceOfPerson) + " " + math()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,54 @@ | ||
| public class Main { | ||
| import java.util.InputMismatchException; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| static Scanner scanner = new Scanner(System.in); | ||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
|
|
||
|
|
||
| Calculator calculator = new Calculator(); | ||
| System.out.println("На скольких человек разделить счет?"); | ||
| int scanPerson; | ||
|
|
||
| while (true) { | ||
|
|
||
| if (scanner.hasNextInt()) { | ||
| scanPerson = scanner.nextInt(); | ||
| if (scanPerson == 1) { | ||
| System.out.println("Подсчет не нужен"); | ||
| System.exit(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. Лучше тут программу не заканчивать, а предлагать ввести другое значение |
||
| } else if (scanPerson < 1) { | ||
| System.out.println("Ошибка. Введите корректное значение."); | ||
| } else break; | ||
| } else { | ||
| System.out.println("Введите корректное значение"); | ||
| scanner.nextLine(); | ||
| } | ||
| } | ||
|
|
||
| calculator.setCountPerson(scanPerson); | ||
| do { | ||
| Product product = new Product(); | ||
| System.out.println("Введите название товара"); | ||
| scanner.nextLine(); | ||
| product.setNameOfProduct(scanner.nextLine()); | ||
| System.out.println("Введите стоимость товара в формате 00,00"); | ||
| product.setCost(inputPrice()); | ||
| calculator.setBill(product); | ||
| System.out.println("Завершить? Нажмите любой символ, чтобы продолжить"); | ||
| } while (!scanner.next().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. Хорошее использование do-while, молодец |
||
| calculator.calculate(); | ||
|
|
||
| } | ||
|
|
||
| static double price = 0.0; | ||
| public static double inputPrice() { | ||
| try { | ||
| price = scanner.nextDouble(); | ||
| } catch (InputMismatchException exception) { | ||
| System.out.println("Введите корректное значение"); | ||
| scanner.nextLine(); | ||
| inputPrice(); | ||
| } return price; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| public class Product { | ||
|
|
||
| private String nameOfProduct; | ||
| private double cost; | ||
|
|
||
|
|
||
| public String getNameOfProduct() { | ||
| return nameOfProduct; | ||
| } | ||
|
|
||
| public void setNameOfProduct(String nameOfProduct) { | ||
| this.nameOfProduct = nameOfProduct; | ||
| } | ||
|
|
||
| public double getCost() { | ||
| return cost; | ||
| } | ||
|
|
||
| public void setCost(double cost) { | ||
| this.cost = cost; | ||
| } | ||
|
|
||
| } |
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 не обязательны