Repository navigation
Проект №1 #3
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: main2
Are you sure you want to change the base?
Проект №1 #3
Changes from all commits
8cf0f0a
b847903
682b284
99a8451
bd65169
d67ca64
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 |
|---|---|---|
| @@ -1,6 +1,20 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| People addPeople = new People(); | ||
| Product product = new Product(); | ||
| addPeople.person(); | ||
| addPeople.morePerson(); | ||
| product.addProduct(); | ||
| product.addMoreProduct(); | ||
|
|
||
| double priceForOne; | ||
| priceForOne = product.fullPrice / addPeople.personCheck; | ||
| String.format("%.2f", priceForOne); | ||
| String rub = Rubend.formatter(priceForOne); | ||
| System.out.println("Сумма на человека: " + priceForOne + rub); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //dlya pr | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import java.util.Scanner; | ||
| public class People { | ||
| Scanner scanner = new Scanner(System.in); | ||
| int personCheck; | ||
| public void person() { | ||
| System.out.println("Введите количество на сколько человек необходимо разделить счёт"); | ||
| while (true){ | ||
| if (!scanner.hasNextInt()) { | ||
| System.out.println("Введите целое число, а не "+scanner.nextLine()); | ||
| } else { | ||
| personCheck= scanner.nextInt(); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void morePerson() { | ||
| while (personCheck <= 1) { | ||
| System.out.println("Некорректное значение, введите число больше 1"); | ||
| person(); | ||
| if (personCheck > 1){ | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Product { | ||
| Scanner scanner = new Scanner(System.in); | ||
| float price =0; | ||
| String product; | ||
| String fullProduct = "Добавленные товары: "; | ||
|
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. Сохранять цены и товары можно в ArrayList в виде набора строк, а еще лучше создать специальный класс Товар, который будет хранить два значения - цена и название. Так ты сможешь создавать новые экземпляры этого класса и хранить их в листе. Это очень удобно, и это основная концепция java, как ооп языка. |
||
|
|
||
| float fullPrice; | ||
| void addProduct() { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
|
|
||
|
|
||
| do { | ||
| System.out.print("Введите название товара: "); | ||
| product = scanner.nextLine().trim(); | ||
| } while (product.isEmpty()); | ||
|
|
||
| boolean validPrice = false; | ||
| do { | ||
| System.out.print("Введите стоимость товара в формате \"рубли.копейки\": "); | ||
| String priceString = scanner.nextLine().trim(); | ||
| try { | ||
| price = Float.parseFloat(priceString); | ||
| if (price >= 0) { | ||
| validPrice = true; | ||
| } else { | ||
| System.out.println("Стоимость товара не может быть отрицательной!"); | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| System.out.println("Некорректный формат стоимости товара!"); | ||
| } | ||
| } while (!validPrice); | ||
|
|
||
| System.out.println("Товар успешно добавлен!\n"); | ||
| fullProduct += "\n" + product; | ||
| fullPrice += price; | ||
| } | ||
| void addMoreProduct(){ | ||
| String end = "Завершить"; | ||
| String yes = "Да"; | ||
| while (true) { | ||
| System.out.println("Хотите добавить ещё товар?\nДля продолжения введите: " + yes + "\nДля завершения введите: " + end); | ||
| product = scanner.nextLine(); | ||
| if (yes.equalsIgnoreCase(product)){ | ||
| addProduct(); | ||
| continue; | ||
| } | ||
| if (end.equalsIgnoreCase(product)){ | ||
| System.out.println(fullProduct); | ||
| String.format("%.2f",fullPrice); | ||
|
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. эта строчка ничего не делает. |
||
| System.out.println("Сумма товаров: " + fullPrice); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| public class Rubend { | ||
| private static final String RUB = "рубль"; | ||
| private static final String RUBL = "рубля"; | ||
| private static final String RUBLS = "рублей"; | ||
|
|
||
| public static String formatter(double priceForOne) { | ||
| int format = (int) Math.floor(priceForOne); | ||
| int endNumber10 = format % 10; | ||
| int endNumber100 = format % 100; | ||
| String ending ; | ||
| while (true) { | ||
|
|
||
|
|
||
| if (endNumber10 == 1 && endNumber100 != 11) { | ||
| ending = RUB; | ||
| break; | ||
|
|
||
| } else if ((endNumber10 >= 2 && endNumber10 <= 4) && (endNumber100 < 10 || endNumber100 >= 20)) { | ||
| ending = RUBL; | ||
| break; | ||
| } | ||
| else { | ||
| ending = RUBLS; | ||
| break; | ||
| } | ||
|
|
||
| } | ||
| return ending; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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.
строка ничего не делает, не сохраняется и не выводится.