Skip to content
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
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = '1.0'

repositories {
}

dependencies {

}

4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Jul 23 10:15:32 MSK 2022
#Mon Feb 13 22:07:00 MSK 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
53 changes: 53 additions & 0 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Calculator {
ArrayList<String> name = new ArrayList<>();
ArrayList<Double> price = new ArrayList<>();
int countter = 0;
double sum;
double getSum() {return sum;}


public void newTovar() {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите товар № "+(countter+1)+" или \"Завершить\", чтобы завершить ввод:");
String nameInput = scanner.nextLine();
if (nameInput.equalsIgnoreCase("Завершить")) {
break;
}
System.out.println("Сколько стоит " + nameInput + "? (формат ввода: \"XXX,xx\"):");
double priceInput;
while (true) {
if (scanner.hasNextDouble()) {
priceInput = scanner.nextDouble();
scanner.nextLine();
if (priceInput < 1){
System.out.println("Введите число больше 0");
}
else {break;}}
else {
System.out.println("Некорректный ввод, попробуйте еще раз");
scanner.nextLine();
}
}
name.add(nameInput);
price.add(priceInput);
countter++;
sum += priceInput;
System.out.println("Товар №"+countter+ "\"" + nameInput + "\" успешно добавлен!");
}
}
void print() {
System.out.println("Добавленные товары: \n");
RubFormat rub = new RubFormat();
for (int i = 0; i < countter; i++) {
System.out.println(String.format("%2d ",(i + 1)) + String.format(" |%-27s|",name.get(i)) + String.format("%7.2f", price.get(i))
+ rub.format(price.get(i))+ "\n"+ "\n");
}
System.out.println("ИТОГО:" + String.format("%7.2f", sum) + rub.format(sum));
}


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

public class Count {

static int count() {
int number ;
int persons;
Scanner sc = new Scanner(System.in);
System.out.println("На скольких человек необходимо разделить счет?");
while (true) {
if (sc.hasNextInt()) {
number = sc.nextInt();
if (number == 1) {
System.out.println("Вы один, вам за все и платить!");
} else if (number < 1) {
System.out.println("Введите целое положительное число.");
} else {
persons = number;
break;
}
}
else {
System.out.println("Введите число.");
sc.nextLine();
}
}
return persons;
}
}
14 changes: 12 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ public class Main {
public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
Calculator check = new Calculator();
int getCount = Count.count();

check.newTovar();
check.print();

double checkPerOne = check.getSum()/ getCount;
RubFormat rub = new RubFormat();
System.out.println("Вас было "+ getCount +", значит с каждого по " + String.format("%.2f", checkPerOne) + rub.format(checkPerOne));

}
}
}

17 changes: 17 additions & 0 deletions src/main/java/RubFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class RubFormat {
public static String format(double input) {
int ending = ((int) input);
String rub = "рублей";
if (ending % 10 == 1) {
rub = "рубль";
}
if ((ending % 10 >= 2) && (ending % 10 <= 4)) {
rub = "рубля";
}
if ((ending % 100 >= 11) && (ending % 100 <= 20)) {
rub = "рублей";
}
return rub;
}
}