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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sourceCompatibility = 1.8
version = '1.0'

repositories {

}

dependencies {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/Convert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@


public class Convert {

static String convertRub(double result) {
String rub="рубл";
Comment thread
Ded-Rinat marked this conversation as resolved.

if ( result>=11 && result<=14) {
rub += "ей";
}else {
Comment thread
Ded-Rinat marked this conversation as resolved.
result %= 10;
if (result == 1) {
rub += "ь";
} else if (result >= 2 && result<= 4) {
Comment thread
Ded-Rinat marked this conversation as resolved.
rub += "я";
} else {
rub += "ей";
}
}
return rub;
}
}


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

import java.util.Scanner;

// dev branch for Y.Practicum
public class Main {


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

int countPersons;//количество человек
Scanner scanner = new Scanner(System.in);
System.out.println("На сколько человек необходимо разделить счёт?");


while (true) {

if (scanner.hasNextInt()) {
countPersons = scanner.nextInt();

if (countPersons <= 1) {
System.out.println("Некорректное значение, введите число больше 1");
} else {
break;
}
} else {
System.out.println("Ошибка,нужно ввести целочисленное число");

}
scanner.nextLine();

}

Products products = new Products();

products.TotalproductAndPrice();


double result=Products.totalPrice/countPersons;//подсчет сколько должен заплатить каждый
Comment thread
Ded-Rinat marked this conversation as resolved.

Convert convert=new Convert();
Comment thread
Ded-Rinat marked this conversation as resolved.

System.out.printf("К оплате с человека: %.2f %s ",result, Convert.convertRub(result));

}
}








58 changes: 58 additions & 0 deletions src/main/java/Products.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@


import java.util.Scanner;

public class Products {

double priceProduct;// стоимость товара
String nameProduct;// наименование товара
static double totalPrice;// общая сумма
String listProduct="Добавленные товары:";// список товаров

Scanner scan = new Scanner(System.in);


public void TotalproductAndPrice() {
Comment thread
Ded-Rinat marked this conversation as resolved.

while (true) {
System.out.println("Введите наименование товара");
nameProduct = scan.next();
System.out.println("Товар добавлен в калькулятор");
listProduct += "\n"+nameProduct;

System.out.println("Введите стоимость товара в формате рубли,копейки");
while (true) {
if (scan.hasNextDouble()) {
priceProduct = scan.nextDouble();

if (priceProduct <= 0) {
System.out.println("Стоимость д.б. больше 0, повторите ввод");

} else {
break;
}

} else {
System.out.println("Введите корректное значение в цифрах");
scan.next();
}
}
scan.nextLine();
totalPrice += priceProduct;
System.out.println("Желаете добавить еще товар? Если нет, то напишите \"завершить\"");
String input = scan.nextLine();
if (input.equalsIgnoreCase("завершить")) {
break;
}

}

System.out.println(listProduct);

}
}