forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Проектная работа №1 #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
Open
vochikk
wants to merge
4
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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,11 @@ | ||
| public class Calculator { | ||
| double totalPrice; | ||
| int numberOfPerson; | ||
| double priceToPayment; | ||
|
|
||
| public void calculate(double totalPrice, int numberOfPerson){ | ||
| this.numberOfPerson = numberOfPerson; | ||
| this.totalPrice = totalPrice; | ||
| priceToPayment = totalPrice / numberOfPerson; | ||
| } | ||
| } |
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,32 @@ | ||
| public class Formater { | ||
| String rubl; | ||
|
|
||
| public String declination(double num){ | ||
| double numToFormat = Math.floor(num); | ||
| double lastDigit = numToFormat % 10; //отделяем последнюю цифру | ||
| numToFormat /= 10; //готовим число для отделения еще одной цифры | ||
| double secondToLastDigit = numToFormat % 10; //отделяем предпоследнюю цифру | ||
|
|
||
| if (secondToLastDigit == 1){ | ||
| return rubl = "рублей"; | ||
| } else { | ||
| switch (String.valueOf(lastDigit)) { | ||
| case "1": | ||
| return rubl = "рубль"; | ||
| case "2": | ||
| return rubl = "рубля"; | ||
| case "3": | ||
| return rubl = "рубля"; | ||
| case "4": | ||
| return rubl = "рубля"; | ||
| default: | ||
| return rubl = "рублей"; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public String rounding(double price){ | ||
| return String.format("%.2f", price); | ||
| } | ||
| } | ||
|
|
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,13 @@ | ||
| public class ListOfProduct { | ||
| String listToByu = ""; | ||
| String nameOfProduct; | ||
| double price; | ||
|
|
||
| public String addToProductList(String nameOfProduct, double price){ | ||
| this.nameOfProduct = nameOfProduct; | ||
| this.price = price; | ||
| Formater formater = new Formater(); | ||
| return listToByu = listToByu + (nameOfProduct + " - " + formater.rounding(price) + " " | ||
| + formater.declination(price) + "\n"); | ||
| } | ||
| } |
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,80 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| // dev branch for Y.Practicum | ||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| Formater formater = new Formater(); //объект для форматирования скланения во всей программе | ||
|
|
||
|
|
||
| System.out.println("На сколько человек необходимо разделить счет"); | ||
| int numberOfPerson; | ||
| while (!scanner.hasNextInt()){ | ||
| System.out.println("Некорректный ввод,повторите попытку"); | ||
| scanner.next(); | ||
| } | ||
| numberOfPerson = scanner.nextInt(); | ||
|
|
||
| while (true){ | ||
| if (numberOfPerson <= 1){ | ||
| System.out.println("Некорректный ввод,повторите попытку"); | ||
| while (!scanner.hasNextInt()){ | ||
| System.out.println("Некорректный ввод,повторите попытку"); | ||
| scanner.next(); | ||
| } | ||
| numberOfPerson = scanner.nextInt(); | ||
|
|
||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| System.out.println("Счет необходимо разделить на " + numberOfPerson); | ||
|
|
||
| Calculator calculator = new Calculator(); //объект для проведения расчетов | ||
| calculator.numberOfPerson = numberOfPerson; | ||
|
|
||
| ListOfProduct listOfProducts = new ListOfProduct(); //объект для хранения списка покупок | ||
| while (true){ | ||
| System.out.println("Введите название товара или команду завершить"); | ||
| listOfProducts.nameOfProduct = scanner.next(); | ||
|
|
||
| String conditionToExit = "завершить"; | ||
| if (conditionToExit.equalsIgnoreCase(listOfProducts.nameOfProduct)){ | ||
| break; | ||
| } | ||
|
|
||
| System.out.println("Введите цену на товар"); | ||
| while (!scanner.hasNextDouble()){ | ||
| System.out.println("Некорректный ввод,повторите попытку"); | ||
| scanner.next(); | ||
| } | ||
| listOfProducts.price = scanner.nextDouble(); | ||
|
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. И тут только метод проверки - |
||
| while (listOfProducts.price < 0){ | ||
| System.out.println("Некорректный ввод, повторите попытку"); | ||
| while (!scanner.hasNextDouble()){ | ||
| System.out.println("Некорректный ввод,повторите попытку"); | ||
| scanner.next(); | ||
| } | ||
| listOfProducts.price = scanner.nextDouble(); | ||
| } | ||
|
|
||
| listOfProducts.listToByu = listOfProducts.addToProductList(listOfProducts.nameOfProduct, listOfProducts.price); | ||
|
|
||
| System.out.println("Товар успешно добавлен"); | ||
| calculator.totalPrice = calculator.totalPrice + listOfProducts.price; | ||
| } | ||
|
|
||
| if (calculator.totalPrice == 0){ | ||
| System.out.println("У Вас нет покупок"); | ||
| } else { | ||
| String rubl = formater.declination(calculator.totalPrice); | ||
| System.out.println("Вы купили:" + "\n" + listOfProducts.listToByu + "На сумму: " | ||
| + formater.rounding(calculator.totalPrice) + " " + rubl); | ||
|
|
||
| calculator.calculate(calculator.totalPrice, numberOfPerson); | ||
| System.out.println("Каждому необходимо заплатить по: " + formater.rounding(calculator.priceToPayment) + " " | ||
| + formater.declination(calculator.priceToPayment)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
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.
Тут соотвественно тоже самое