Repository navigation
Калькулятор #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
base: main
Are you sure you want to change the base?
Калькулятор #1
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Calc { | ||
| static List<String> menu = new ArrayList<>(); | ||
| static double summa = 0; | ||
| public static List<String> menu(String nameb) { | ||
| menu.add(nameb); | ||
| return (menu); | ||
| } | ||
| public static Double calculator(Double summa1){ | ||
|
|
||
| summa = summa + summa1; | ||
|
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. 🍏 Лучше не использовать числа в названии переменных. Здесь можно |
||
| return (summa); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| public class Form { | ||
| public static void sum(double summa) { | ||
| int x = (int) summa % 100 / 10; | ||
| int y = (int) summa % 10; | ||
| if (summa == 1 || (y == 1 && x != 1)) { | ||
| System.out.print(" рубль"); | ||
| } else { | ||
| if ((y == 2 || y == 3 || y == 4) && x != 1) { | ||
| System.out.print(" рубля"); | ||
| } else { | ||
| System.out.print(" рублей"); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Input { | ||
|
|
||
|
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. 🍏Лишняя пустая строка |
||
|
|
||
| public static int human () { | ||
| int n; | ||
| Scanner input = new Scanner(System.in); | ||
|
|
||
| System.out.println("Привет! Я – калькулятор счета"); | ||
| while (true) { | ||
| System.out.println("На скольких человек необходимо разделить счет?"); | ||
| String str = input.next(); | ||
| n = 0; | ||
| try { | ||
| n = Integer.parseInt(str); | ||
| if (n == 1) { | ||
| System.out.println("Ошибка, Вы ввели 1"); | ||
| } else { | ||
| if (n < 1) { | ||
| System.out.println("Вы ввели отрицательное число!"); | ||
| } else { | ||
| if (n == 0) { | ||
| System.out.println("Ошибка, Вы ввели 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 { | ||
| System.out.println("Спасибо!"); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| } catch (NumberFormatException ne) { | ||
| System.out.println("Ошибка, введите число"); | ||
| } | ||
| } | ||
| return n; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| public static String name() { | ||
|
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. 🍏 Следует следить за форматированием кода, это можно делать автоматически, прожимая |
||
| Scanner input = new Scanner(System.in); | ||
| Prod p = new Prod(); | ||
|
|
||
| System.out.println("Введите название блюда и нажмите Enter. Если ввод закончен, введите \"Завершить\""); | ||
|
|
||
| p.name = input.next(); | ||
|
|
||
| return p.name; | ||
| } | ||
| public static double inp() { | ||
| Scanner input = new Scanner(System.in); | ||
| double price1 = 0; | ||
| while (true) { | ||
| System.out.println("Введите цену блюда"); | ||
| String str1 = input.next(); | ||
| try { | ||
| price1 = Double.parseDouble(str1); | ||
| if (price1 < 0) { | ||
| System.out.println("Вы ввели отрицательное число!"); | ||
| } else { | ||
| break; | ||
| } | ||
| } catch (NumberFormatException ne) { | ||
| System.out.println("Ошибка, введите число"); | ||
| } | ||
| } | ||
| return price1; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,48 @@ | ||
| //import java.util.Scanner; | ||
|
|
||
| import java.util.ArrayList; | ||
| //import java.util.Collections; | ||
|
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. 🍏Стоит удалить комментарии с ненужным кодом здесь и в других местах кода |
||
| import java.util.List; | ||
|
|
||
| //import java.Input.Input; | ||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
|
|
||
| double summa=0; | ||
|
|
||
| //boolean a1; | ||
| // double price1=0; | ||
|
|
||
| List<String> menu1 = new ArrayList<String>(); | ||
|
|
||
| Prod p = new Prod(); | ||
| int n=Input.human(); | ||
|
|
||
| while (true){ | ||
| String nameb = Input.name(); | ||
| if (nameb.equalsIgnoreCase("Завершить")) { | ||
| break; | ||
| } | ||
| p.price = Input.inp(); | ||
|
|
||
| menu1 = Calc.menu(nameb); | ||
| summa= Calc.calculator(p.price); | ||
| System.out.println("Товар добавлен"); | ||
| System.out.println("Хотите ли добавить еще один товар?"); | ||
| /////// | ||
|
|
||
| } | ||
| System.out.print("Добавленные товары: "); | ||
| System.out.println(menu1.toString().replace("[", "").replace("]", "")); | ||
|
|
||
| summa = summa/n; | ||
| System.out.print("Необходимо оплатить: "); | ||
| System.out.printf("%.2f",summa); | ||
| Form.sum(summa); | ||
| } | ||
| } | ||
| class Prod { | ||
|
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.
Owner
Author
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. Привет, Вагиз! Спасибо за замечание! Постараюсь исправить. Самостоятельно изучила обработку ошибок в Java, try-catch. Рекомендацию про организацию списков классов выполнить не могу, так как в теоретической части на это не было ни материалов, ни примеров. Если возможно, пришли пример организации списков классов. |
||
| String name = ""; // Название блюда | ||
| double price = 0; // Цена блюда | ||
| } | ||
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.
🍏Старайся оставлять пустую строку между методами класса