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
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ dependencyResolutionManagement {
mavenCentral()
}
}
rootProject.name = "BillCalculator"
rootProject.name = "Java-Module-Project"
26 changes: 14 additions & 12 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@

class Calculator {

int friendsCount;

String cart = "Добавленные товары:";
static String cart = "Добавленные товары ";
double totalPrice = 0;
double devideSum;
int numberPeople;

Calculator(int friendsCount) {
this.friendsCount = friendsCount;
}

void addItem(Item item) {
totalPrice += item.price;
cart = cart + "\n" + item.name;
void calcul(added added) {
totalPrice = totalPrice + added.prise;
cart = cart + "\n" + added.product;
System.out.println(added.product + " - в корзине");
devideSum = totalPrice / numberPeople;

System.out.println(item.name + " в корзине");
}

double divideSum() {
return totalPrice / friendsCount;
Calculator(int numberPeople) {
this.numberPeople = numberPeople;
}
}
//


17 changes: 0 additions & 17 deletions src/main/java/Formatter.java

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/Item.java

This file was deleted.

64 changes: 37 additions & 27 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,55 @@ public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int friendCount;
int numberPeople;

while (true) {
System.out.println("На сколько человек необходимо разделить счет?");
friendCount = scanner.nextInt();

if (friendCount > 1) {
System.out.println("На скольких человек необходимо разделить счёт");
numberPeople = scanner.nextInt();
if (numberPeople > 1) {
break;
} else if (friendCount == 1) {
System.out.println(
"Нет смысла делить сумму на одного человека. Давайте попробуем ввести другое значение, которое будет больше единицы.");
} else {
System.out.println("Неверное количество друзей. Значение должно быть болье единицы, давайте попробуем еще раз.");
} else if (numberPeople <= 1) {
System.out.println("Это некорректное значение для подсчёта, повторите ввод");
}
}
System.out.println("Сейчас все сделаем");

Calculator calculator = new Calculator(friendCount);

Calculator Calculator = new Calculator(numberPeople);
double prise;
while (true) {
System.out.println("Введите название товара");
String name = scanner.next();

System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [10.45, 11.40]");
double price = scanner.nextDouble();

calculator.addItem(new Item(name, price));

System.out.println(
"Хотите добавить еще один товар? Введите любой символ для продолжения, либо 'Завершить' если больше нет товаров для добавления");
System.out.println("Введите название продукта");
String product = scanner.next();
try {
System.out.println("Введите стоимость в формате: 'рубли.копейки' 10.45, 11.40");
prise = scanner.nextDouble();

Calculator.calcul(new added(product, prise));
System.out.println("Хотите добавить ещё один товар? Введите команду завершить, для прекращения ввода. Для продлежния введите любое слово или символ");
String answer = scanner.next();

if (answer.equalsIgnoreCase("Завершить")) {
break;
}
} catch(Exception e) {
System.out.println(e.getMessage());
}
}

double result = calculator.divideSum();
Formatter formatter = new Formatter();

System.out.println(calculator.cart);
System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result));
rubleOptions RubleOptions = new rubleOptions();
double value = Calculator.devideSum;
String result = String.format("%.2f",value);
System.out.println(Calculator.cart + "\n" + "К оплате с человека " + result + RubleOptions.rubles(value));
}
}
}
// Привет, не могу исправить заглавную букву класса, выдает ошибку. Такое ощущение, что андроид студио логает.






// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости


12 changes: 12 additions & 0 deletions src/main/java/added.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class added {

String product;
double prise;

added(String product,double prise) {
this.product = product;
this.prise = prise;
}

}
//
23 changes: 23 additions & 0 deletions src/main/java/rubleOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class rubleOptions {


String rubles(double value) {
double rubles = Math.floor(value);
if (rubles == 1) {
return " рубль";
} else if (rubles %100 == 11 || rubles%100 == 12 || rubles%100 == 13 || rubles%100 == 14) {
return " рублей";
} else if (rubles % 10 == 1) {
return " рубль";
} else if (rubles % 10 >= 2 && rubles % 10 <= 4) {
return " рубля";
} else {
return " рублей";
}
}
}




//