forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
first commit in first project practicum #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
And0nata
wants to merge
3
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,49 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class CountFriends { | ||
|
|
||
| static int countFriends = 0; | ||
| static Scanner sc = new Scanner(System.in); | ||
|
|
||
| //Функция ввода количества человек | ||
| public static int inputCountFriends() { | ||
| do { | ||
| System.out.println("На скольких человек необходимо разделить счёт?"); | ||
| try { | ||
| if (sc.hasNextLine()) { | ||
| String inputLine = sc.nextLine(); | ||
| inputLine = inputLine.trim(); | ||
| countFriends = Integer.parseInt(inputLine); | ||
| } | ||
| } catch (Exception e) { | ||
| System.out.println("Ошибка: " + e.getMessage()); | ||
| } | ||
| switch (countFriends) { | ||
| case 0: | ||
| System.out.println("Введено некорректное количество человек.\n Введите еще раз!)"); | ||
| break; | ||
| case 1: | ||
| System.out.println("Нечего делить в счете оплачиваемым одним человеком.\n Введите еще раз!)"); | ||
| break; | ||
| default: | ||
| if (countFriends < 0) | ||
| System.out.println("Кхм... Попробуем еще раз!"); | ||
| else return countFriends; | ||
| } | ||
|
|
||
| } | ||
| while (true); | ||
| } | ||
|
|
||
| public static double calculate(int countFriends, double countMoney) { | ||
| return countMoney / countFriends; | ||
| } | ||
|
|
||
| public static String ruble(double manyForOne) { | ||
| int value = (int) manyForOne; | ||
| if ((value % 100 / 10) % 10 == 1 || value % 10 == 0 || value % 10 >= 5) return "рублей"; | ||
| else if (value % 10 == 1) return "рубль"; | ||
| else if (value % 10 > 1 && value % 10 < 5) return "рубля"; | ||
| else return "ошибка"; | ||
| } | ||
| } | ||
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,6 +1,15 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| Scanner sc = new Scanner(System.in); | ||
| int countFriends = CountFriends.inputCountFriends(); | ||
| Products.addProducts(); | ||
| double countMoney = Products.getSumm(); | ||
| double manyForOne = CountFriends.calculate(countFriends, countMoney); | ||
|
|
||
| System.out.println(Products.getListProducts()); | ||
| System.out.println("Каждый должен заплатить по: " + String.format("%.2f", manyForOne).replace(",", ".") + " " + CountFriends.ruble(manyForOne)); | ||
| sc.close(); | ||
| } | ||
| } |
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,59 @@ | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class Products { | ||
| static Scanner sc = new Scanner(System.in); | ||
| private static String listProducts = "Добавленные товары:"; | ||
| private static double summ = 0.00; | ||
| static String inputName; | ||
| static double price; | ||
|
|
||
| public static void addProducts() { | ||
| do { | ||
| System.out.println("Введите название товара"); | ||
| if (sc.hasNextLine()) { | ||
| inputName = sc.nextLine(); | ||
| inputName = inputName.trim(); | ||
| } | ||
| if (inputName.equalsIgnoreCase("Завершить")) { | ||
| break; | ||
| } else if (inputName.length() == 0) continue; | ||
| else { | ||
| listProducts += "\n" + inputName; | ||
| } | ||
| while (true) { | ||
| System.out.println("Введите стоимость товара цифрой"); | ||
| try { | ||
| if (sc.hasNextLine()) { | ||
| String inputLine = sc.nextLine().trim(); | ||
| double price = Double.parseDouble(inputLine); | ||
| if (price < 0) { | ||
| System.out.println("Неправильная стоимость товара"); | ||
| } else { | ||
| summ += (double) price; | ||
| break; | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| System.out.println("Ошибка: " + e.getMessage()); | ||
| } | ||
|
|
||
| } | ||
| System.out.println("Товар успешно добавлен!"); | ||
| System.out.println("Введите \"Завершить\" для завершения или любой другой символ для продолжения"); | ||
| inputName = sc.nextLine(); | ||
| inputName = inputName.trim(); | ||
| if (inputName.equalsIgnoreCase("Завершить")) break; | ||
| } while (true); | ||
| } | ||
|
|
||
| public static String getListProducts() { | ||
| return listProducts; | ||
| } | ||
|
|
||
| public static double getSumm() { | ||
| return summ; | ||
| } | ||
|
|
||
|
|
||
| } |
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.
В java принят определенный стиль форматирования кода. Если не вдаваться в подробности, то отформатировать код можно быстрой комбинаций клавиш Ctrl+Alt+L(Windows) или (⌘+⌥+L)(Mac)