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.

123 changes: 123 additions & 0 deletions .idea/codeStyles/Project.xml

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

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.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/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.

9 changes: 9 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.

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ repositories {
}

dependencies {
implementation 'com.google.android.gms:play-services-analytics-impl:17.0.0'
}
27 changes: 24 additions & 3 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
public class Main {
static String end = "Завершить"; // проверка для завершения ввода продуктов

public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
People.howPeople();
Product.calculate();

// Вывод результата
double costPerson = Product.cost / People.countPeople;
double checkCostPerson = Math.floor(costPerson);

System.out.println("Добавленные товары:\n" + Product.name);
System.out.printf("%.2f", costPerson);
rublesName(checkCostPerson);
}

public static void rublesName(double cost) {
if (cost % 10 == 1 && cost != 11 && cost % 100 != 11) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cost != 11 и cost % 100 != 11 это одно и тоже, при делении по модулю числа 11 на 100 будет всё равно 11

@artemyarovikov artemyarovikov Oct 6, 2022

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Это для чисел больше 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.

Можно оставить только cost % 100 != 11. Для числа 111 cost % 100 = 11, и для числа 11 cost % 100 = 11

System.out.println(" рубль.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно в этом методе не выводить на консоль слово, а возвращать только его

} else if (cost % 10 >= 2 && cost % 10 <= 4) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cost % 10 повторяется несколько раз, можно посчитать 1 раз, записать в переменную и использовать её.
Ещё в эту ветку попадают числа 12, 13 и 14, а должно быть для них "рублей"

System.out.println(" рубля.");
} else {
System.out.println(" рублей.");
}
}
}



25 changes: 25 additions & 0 deletions src/main/java/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.util.Scanner;

public class People {
public static int countPeople;

public static void howPeople() {
System.out.println("На скольких человек делим счёт?");
while (true) {
Scanner scannerPeople = new Scanner(System.in);
boolean checkPeople = scannerPeople.hasNextInt();
if (checkPeople) {
int passPeople = scannerPeople.nextInt();
if (passPeople > 1) {
countPeople = passPeople;
return; // передает в переменную число людей

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно число людей сделать возвращаемым значением метода howPeople, и избавиться от переменной countPeople

} else {
System.out.println("Ошибка. Введи целое число больше 1:");
}
} else {
System.out.println("Ошибка. Введи целое число больше 1:");

}
}
}
}
37 changes: 37 additions & 0 deletions src/main/java/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.Scanner;

public class Product {
static String name = "";
static double cost;

public static void calculate() {
System.out.println("Как называется продукт?");
while (true) {
Scanner scannerName = new Scanner(System.in);
String checkName = scannerName.nextLine();
if (checkName.equalsIgnoreCase(Main.end)) {
break;
} else {
name = name + checkName + "\n";
}

System.out.println("Сколько стоил продукт?");
while (true) {
Scanner scannerCost = new Scanner(System.in);
boolean checkCost = scannerCost.hasNextDouble();
if (checkCost) {
double passPeople = scannerCost.nextDouble();
if (passPeople > 1) {
cost += passPeople;
System.out.println("Товар добавлен! Введите название нового товара или напишите \"Завершить\".");
break;
} else {
System.out.println("Ошибка. Введи целое число больше 1:");
}
} else {
System.out.println("Ошибка. Введите число;");
}
}
}
}
}