Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Финальный вариант работы #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1sleepwalker1 wants to merge 7 commits into Yandex-Practicum:master from 1sleepwalker1:master
Closed
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
24 changes: 24 additions & 0 deletions src/main/java/Calculator.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

class Calculator {


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

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

}

Calculator(int numberPeople) {
this.numberPeople = numberPeople;
}
}
//


57 changes: 54 additions & 3 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,59 @@
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int numberPeople;

while (true) {

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


Calculator Calculator = new Calculator(numberPeople);
double prise;
while (true) {
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());
}
}

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 и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
}
}


12 changes: 12 additions & 0 deletions src/main/java/added.java
View file Open in desktop
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
View file Open in desktop
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 " рублей";
}
}
}




//

AltStyle によって変換されたページ (->オリジナル) /