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

Практическая No1 #1

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

Open
Zombainer wants to merge 4 commits into main
base: main
Choose a base branch
Loading
from dev
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
21 changes: 21 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,21 @@
public class Calculator {
void calcul(double result, int people) {
// Результат

result = result / people;

// Oкончание
String rubles;
if (result % 10 == 1 && result % 100 != 11) {
rubles = "рубль";
} else if (result % 10 >= 2 && result % 10 <= 4 && (result % 100 < 10 || result % 100 > 20)) {
rubles = "рубля";
} else {
rubles = "рублей";
}


String format = "Каждый человек должен по: %.2f %s.";
System.out.println(String.format(format, result, rubles));
}
}
61 changes: 60 additions & 1 deletion src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,65 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Scanner scanner = new Scanner(System.in);
String list = "";
double result = 0.00;
double price = 0;
int people = 0;

// Кол-во людей

System.out.println("Количество людей для разделения счёта: ");
while (true) {
if (scanner.hasNextInt()) {
people = scanner.nextInt();
if (people > 1) {
break;
} else {
System.out.println("Введено не корректное количество людей.");
}
} else {
System.out.println("Введено не корректное значение, введите количество людей.");
}
scanner.nextLine();
}

// Стоймость и название товаров

while (true) {
System.out.println("Ведите название товара, если закончили перечислять, напишите \"Завершить\". ");
String product = scanner.next();
if (product.equalsIgnoreCase("завершить")) {
break;
}
System.out.println("Ведите cтоймость товара: ");
while (true) {
if (scanner.hasNextDouble()) {
price = scanner.nextDouble();
if (price > 1) {
break;
} else if (price <= 1) {
System.out.println("Введено некорректное значение, попробуйте снова. ");
}
} else {
System.out.println("Введено некорректное значение, попробуйте снова. ");
scanner.next();
}

}

System.out.println("Товар добавден.");
list = list.concat(product).concat("\n");
result = result + price;
}
System.out.println("Добавленные товары: \n" + list);

// Калькулятор

Calculator calculator = new Calculator();
calculator.calcul(result, people);

scanner.close();
}
}

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