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 README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Пустой репозиторий для работы с Java кодом в Android Studio
Курсовая работа Шаймарданов Марсель
54 changes: 54 additions & 0 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.util.Scanner;

public class Calculator {
static int persons = 0;
static String menuSum = "";
static double priceSum = 0;
public static void calculator() {
Scanner scanner = new Scanner(System.in);
System.out.println("Введите количество человек:");
while (true) {
if (scanner.hasNextInt()) {
persons = scanner.nextInt();
if (persons < 2) {
System.out.println("Введите число больше 1");
} else {
break;
}
} else {
System.out.println("Введите целое число ");
scanner.next();
}
}
while (true) {
System.out.println("Введите название товара или введите 'Завершить', что бы выйти");
scanner.nextLine();
String menu = scanner.nextLine();
if (menu.equalsIgnoreCase("Завершить")) {
System.out.println("Товар успешно добавлен.");
break;
}
menuSum += menu + "\n";
while (true) {
System.out.println("Введите цену товара:");
if (scanner.hasNextDouble()) {
double price = scanner.nextDouble();
if (price > 0) {
priceSum += price;
break;
} else {
System.out.println("Введите число больше 0");
}
} else {
System.out.println("Введите число");
scanner.next();
}
}
}
}
}





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

static double rubAverage = Calculator.priceSum / Calculator.persons;

public static String formatRub(){
int priceRemainder = (int)Math.floor(rubAverage);
if (priceRemainder % 10==1)
return " рубль";
else if (priceRemainder % 10==2 || priceRemainder % 10==3 || priceRemainder % 10==4)
return " рубля";
else
return " рублей";
}





}
9 changes: 6 additions & 3 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Calculator.calculator();
String formatText = "Добавленные товары:\n%sКаждый человек должен заплатить: %.2f %s\n";
System.out.printf(formatText, Calculator.menuSum, FormatRub.rubAverage, FormatRub.formatRub());

}
}
}