Skip to content
Merged
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
19 changes: 19 additions & 0 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.Scanner;

public class Calculator {
float fullPrice;
int personCheck;
float priceForOne;
String rub = " Рублей";

public void endCalculator(float b, int a){
priceForOne = fullPrice / personCheck;
if (Math.floor(priceForOne) < 5) {
rub = " Рубль";
}
String.format("%.2f", priceForOne);
System.out.println("Сумма на человека: " + priceForOne + rub);
}


}
17 changes: 15 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
People addPeople = new People();
Product allProduct = new Product();
addPeople.person();
addPeople.morePerson();
allProduct.addProduct();
allProduct.addMoreProduct();

double priceForOne;
priceForOne = allProduct.fullPrice / addPeople.personCheck;
String.format("%.2f", priceForOne);
String rub = Rubend.formatter(priceForOne);
System.out.println("Сумма на человека: " + priceForOne + rub);
}
}
}

27 changes: 27 additions & 0 deletions src/main/java/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.Scanner;
public class People {
Scanner scanner = new Scanner(System.in);
int personCheck;
public void person() {
System.out.println("Введите количество на сколько человек необходимо разделить счёт");
while (true){
if (!scanner.hasNextInt()) {
System.out.println("Введите целое число, а не "+scanner.nextLine());
} else {
personCheck= scanner.nextInt();
break;
}
}
}

public void morePerson() {
while (personCheck <= 1) {
System.out.println("Некорректное значение, введите число больше 1");
person();
if (personCheck > 1){
break;
}
}

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

public class Product {
Scanner scanner = new Scanner(System.in);

String product;
String fullProduct = "Добавленные товары: ";
float price;
float fullPrice;
void addProduct() {
System.out.print("Введите название товара: ");
product = scanner.nextLine();
System.out.print("Введите стоимость товара в формате \"рубли.копейки\": ");
price = scanner.nextFloat();
System.out.println("Товар успешно добавлен!\n");
fullProduct = fullProduct + "\n" + product ;
fullPrice += price;
}
void addMoreProduct(){
String end = "Завершить";
String yes = "Да";
while (true) {
System.out.println("Хотите добавить ещё товар?\nДля продолжения введите: " + yes + "\nДля завершения введите: " + end);
product = scanner.nextLine();
product = scanner.nextLine(); // что бы не печатало то что выше 2 раза
if (yes.equalsIgnoreCase(product)){
addProduct();
continue;
}
if (end.equalsIgnoreCase(product)){
System.out.println(fullProduct);
String.format("%.2f",fullPrice);
System.out.println("Сумма товаров: " + fullPrice);
break;
}
}
}
}
73 changes: 73 additions & 0 deletions src/main/java/Rock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import java.util.Scanner;

public class Rock {
Scanner scanner = new Scanner(System.in);
int personCheck;
float fullPrice;
float priceForOne;
float price;
String product;
String fullProduct = "Добавленные товары: ";
String rub = " Рублей";

public void person() {
System.out.println("Введите количество на сколько человек необходимо разделить счёт");
while (true) {
if (!scanner.hasNextInt()) {
System.out.println("Введите целое число, а не " + scanner.nextLine());
continue;
} else {
personCheck = scanner.nextInt();
break;
}
}
}

public void morePerson() {
while (personCheck <= 1) {
System.out.println("Некорректное значение, введите число больше 1");
person();
if (personCheck > 1) {
break;
}
}
}
void addProduct() {
System.out.print("Введите название товара: ");
product = scanner.nextLine();
product = scanner.nextLine();
System.out.print("Введите стоимость товара в формате \"рубли.копейки\": ");
price = scanner.nextFloat();
System.out.println("Товар успешно добавлен!\n");
fullProduct = fullProduct + "\n" + product ;
fullPrice += price;
}
void addMoreProduct(){
String end = "Завершить";
String yes = "Да";
while (true) {
System.out.println("Хотите добавить ещё товар?\nДля продолжения введите: " + yes + "\nДля завершения введите: " + end);
product = scanner.nextLine();
product = scanner.nextLine(); // что бы не печатало то что выше 2 раза
if (yes.equalsIgnoreCase(product)){
addProduct();
continue;
}
if (end.equalsIgnoreCase(product)){
System.out.println(fullProduct);
String.format("%.2f",fullPrice);
System.out.println("Сумма товаров: " + fullPrice);
break;
}
}
}

public void endCalculator(){
priceForOne = fullPrice / personCheck;
if (Math.floor(priceForOne) < 5) {
rub = " Рубль";
}
String.format("%.2f", priceForOne);
System.out.println("Сумма на человека: " + priceForOne + rub);
}
}
30 changes: 30 additions & 0 deletions src/main/java/Rubend.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public class Rubend {
private static final String RUB = "рубль";
private static final String RUBL = "рубля";
private static final String RUBLS = "рублей";

public static String formatter(double priceForOne) {
int format = (int) Math.floor(priceForOne);
int endNumber10 = format % 10;
int endNumber100 = format % 100;
String ending ;
while (true) {


if (endNumber10 == 1 && endNumber100 != 11) {
ending = RUB;
break;

} else if ((endNumber10 >= 2 && endNumber10 <= 4) && (endNumber100 < 10 || endNumber100 >= 20)) {
ending = RUBL;
break;
}
else {
ending = RUBLS;
break;
}

}
return ending;
}
}