Repository navigation
Сдача задания #63
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?
Сдача задания #63
Changes from all commits
2300099
6f5f667
3f07dd6
e37b7cc
8e8d475
8eee531
a31a658
8db1c18
3feceb3
32eca36
5f49544
c87ee8c
3f7c908
4a74d0a
7354a50
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,163 @@ | ||
| import java.io.PrintStream; | ||
| import java.util.Scanner; | ||
| public class Main { | ||
|
|
||
| public static Scanner in = new Scanner(System.in); | ||
| public static PrintStream out = System.out; | ||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| int persons = InputInt(); | ||
| Positions[] pos = new Positions[100]; | ||
|
|
||
| String nextPosition = AddName(); | ||
| double nextPrice = AddPrice(); | ||
| while (nextPrice<0){ | ||
| out.println("Non-correct value for counting"); | ||
| nextPrice = AddPrice(); | ||
| } | ||
| int i = 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. Лучше использовать такой нейминг, чтобы по названию было понятно, что переменная означает. |
||
| while (!(nextPosition.equalsIgnoreCase("Завершить") || nextPosition.equalsIgnoreCase("end"))) { | ||
| out.println("The dish has been added successfully!\nDo you want to add one more?"); | ||
| pos[i] = new Positions(nextPosition, nextPrice); | ||
| nextPosition = AddName(); | ||
| if (!(nextPosition.equalsIgnoreCase("Завершить") || nextPosition.equalsIgnoreCase("end"))) { | ||
| nextPrice = AddPrice(); | ||
| while (nextPrice<0){ | ||
| out.println("Non-correct value for counting"); | ||
| nextPrice = AddPrice(); | ||
| } | ||
| } | ||
| i += 1; | ||
| } | ||
|
|
||
| for (int j = 0; j < i; j++) | ||
| out.println(j + 1 + ") " + pos[j].name + " --- " + pos[j].price + " rubles"); | ||
| double sum = 0; | ||
| for (int j = 0; j < i; j++) | ||
| sum += pos[j].price; | ||
| out.print("Total sum: " + String.format("%.2f", sum)); | ||
| Ending(sum); | ||
| out.print(("Everyone has to pay: ") + String.format("%.2f", sum / persons)); | ||
| Ending((sum / persons)); | ||
|
|
||
| //далее дополнительная фича | ||
|
|
||
| out.println("Do you want to correct the list"); | ||
| String choice = in.next(); | ||
| int check = 0; | ||
| while (check == 0) { | ||
| if (choice.equalsIgnoreCase("Да") || choice.equalsIgnoreCase("Yes")) { | ||
| int del = 1; | ||
| while (del != 0) { | ||
| del = (int) AddCorrections(); | ||
| if (del > 0 && del < i) { | ||
| for (int y = del - 1; y < i - 1; y++) { | ||
| pos[y] = pos[y + 1]; | ||
| } | ||
| pos[i] = null; | ||
| i--; | ||
| for (int j = 0; j < i; j++) | ||
| out.println(j + 1 + ") " + pos[j].name + " --- " + pos[j].price + " rubles"); | ||
| double sum1 = 0; | ||
| for (int j = 0; j < i; j++) | ||
| sum1 += pos[j].price; | ||
| out.println("Total sum: " + String.format("%.2f", sum1)); | ||
| Ending(sum1); | ||
| out.println(("Everyone has to pay: ") + String.format("%.2f", sum1 / persons)); | ||
| Ending((sum1 / persons)); | ||
| } else if (del < 0) | ||
| out.println("The number cannot be less than zero"); | ||
| else if (del > i) | ||
| out.println("Non-correct value"); | ||
| } | ||
| out.println("Great! See you later"); | ||
| check = 1; | ||
| } else if (choice.equalsIgnoreCase("Нет") || choice.equalsIgnoreCase("No")) { | ||
| out.println("Great! See you later"); | ||
| check = 1; | ||
| } else { | ||
| out.println("Please, enter Yes/No"); | ||
| choice = in.next(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static int InputInt() { | ||
| //самодеятельность, проще сделать как для double, но зато сам | ||
| out.println("How many people should the bill be divided into?"); | ||
| String enter = in.next(); | ||
| int persons0 = 0, flag = 0, flag2 = 0; | ||
| while (flag == 0) { | ||
| for (int t = 0; t < enter.length(); t++) { | ||
| if (enter.charAt(t) < '0' || enter.charAt(t) > '9') { | ||
| flag2 += 1; | ||
| } | ||
| } | ||
| if (flag2 == 0) { | ||
| int st = 1; | ||
| for (int r = enter.length() - 1; r >= 0; r--) { | ||
| persons0 += ((int) enter.charAt(r) - 48) * st; | ||
| st *= 10; | ||
| } | ||
| if (persons0 >= 1) | ||
| flag = 1; | ||
| } | ||
| if (flag == 0) { | ||
| out.println("Non-correct value for counting\nPlease enter the correct value"); | ||
| enter = in.next(); | ||
| } | ||
| flag2 = 0; | ||
| } | ||
| return persons0; | ||
| } | ||
|
|
||
| public static boolean IsDouble(String input) { | ||
| double price; | ||
| try { | ||
| price = Double.parseDouble(input); | ||
| return true; | ||
| } catch (NumberFormatException e) { | ||
| return false; | ||
| } | ||
| } | ||
| public static boolean IsInt(String inp) { | ||
| int price; | ||
| try { | ||
| price = Integer.parseInt(inp); | ||
| return true; | ||
| } catch (NumberFormatException e) { | ||
| return false; | ||
| } | ||
| } | ||
| public static double AddCorrections(){ | ||
| out.println("Enter the number of the dish you want to delete, If you have finished editing, enter 0"); | ||
| String inp = in.next(); | ||
| while (!IsInt(inp)){ | ||
| out.println("Non-correct value for counting\nPlease enter the correct value"); | ||
| inp = in.next(); | ||
| } | ||
| return Integer.parseInt(inp); | ||
| } | ||
| public static double AddPrice(){ | ||
| out.println("Enter the price of the dish in the format rub,kop"); | ||
| String input = in.next(); | ||
| while (!IsDouble(input)){ | ||
| out.println("Non-correct value for counting\nPlease enter the correct value"); | ||
| input = in.next(); | ||
| } | ||
| return Double.parseDouble(input); | ||
| } | ||
| public static String AddName(){ | ||
| out.println("Enter the name of the dish"); | ||
| return in.next(); | ||
| } | ||
| public static void Ending (double coast){ | ||
| int price = (int) coast; | ||
| if (price%10 == 1 && price%100!=11) | ||
| out.println(" (рубль)"); | ||
| else if (price%10<=4 && price%10>=2 && (price%100)/10!=2) | ||
| out.println(" (рубля)"); | ||
| else | ||
| out.println(" (рублей)"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| public class Positions { | ||
| String name; | ||
| double price; | ||
| Positions(String dishName, double dishPrice){ | ||
| name = dishName; | ||
| price = dishPrice; | ||
| } | ||
| } |
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.
Лучше будет использовать не массив, а ArrayList. В большинстве случаев у нас действительно будет не более 100 товаров, но наверняка мы знать не можем.