Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

163 changes: 159 additions & 4 deletions src/main/java/Main.java
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];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше будет использовать не массив, а ArrayList. В большинстве случаев у нас действительно будет не более 100 товаров, но наверняка мы знать не можем.


String nextPosition = AddName();
double nextPrice = AddPrice();
while (nextPrice<0){
out.println("Non-correct value for counting");
nextPrice = AddPrice();
}
int i = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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(" (рублей)");
}
}


8 changes: 8 additions & 0 deletions src/main/java/Positions.java
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;
}
}