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.

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.

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

public class List {
static double totalPrice = 0.00f;
static String listProduct = "";
public static void requestProduct() {
Scanner scanner = new Scanner(System.in);

while(true) {


System.out.println("Введите название товара");
String name = scanner.next();
listProduct = listProduct.concat(name + ";\n");
System.out.println("Введите цену товара");
double price = checkFailPrice();
totalPrice += price;
System.out.println("Товар успешно добавлен!\nЕсли хотите добавить еще товар введите любой символ.\nДля завершения создания списка напините \"Завершить\".");
String result = scanner.next();
if(result.equalsIgnoreCase("Завершить")){
break;
}

}


}
public static String whichRub(double num){
int sum = (int)num;
sum = sum % 100;
if(10<sum && sum<15){
return "рублeй";
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Для множественного выбора лучше использовать конструкцию switch-case

int sum1 = sum % 10;
switch(sum1){
case 1: return "рубль";
case 2:
case 3:
case 4: return "рубля";

}
return "рублeй";
}
public static void makeList() {
double priceForOne = totalPrice / People.persons;
String end = "Добавленные товары:\n%s%.2f %s должен заплатить каждый человек.";
System.out.println(String.format(end, listProduct, priceForOne,whichRub(priceForOne)));
}
public static double checkFailPrice() {
while(true) {
Scanner scanner = new Scanner(System.in);
boolean hasDouble = scanner.hasNextDouble();
if(hasDouble) {
double trueDouble = scanner.nextDouble();
if (trueDouble > 0) {
return trueDouble;
} else {
System.out.println("Ошибка! Введите корректную цену.");
}
}
else {
System.out.println("Ошибка! Введите корректную цену.");
}
}
}
}

7 changes: 4 additions & 3 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
public class Main {

public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
System.out.println("Привет!");
People.howMany();
List.requestProduct();
List.makeList();
}
}
26 changes: 26 additions & 0 deletions src/main/java/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.Scanner;

public class People {

public static int persons;

public static void howMany(){
System.out.println("На скольких человек необходимо разделить счёт?");
while(true) {
Scanner scanner = new Scanner(System.in);
boolean hasInt = scanner.hasNextInt();
if(hasInt) {
int hasPersons = scanner.nextInt();
if (hasPersons > 1) {
persons = hasPersons;
return;
} else {
System.out.println("Ошибка! Введите корректное число.");
}
}
else {
System.out.println("Ошибка! Введите корректное число.");
}
}
}
}