Skip to content
Open

е #5

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
24 changes: 14 additions & 10 deletions src/main/java/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
public class Calculator {
ArrayList<String> name = new ArrayList<>();
ArrayList<Double> price = new ArrayList<>();
int count = 1;
int countter = 0;
double sum;
double getSum() {return sum;}


public void newTovar() {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите товар № "+(count)+" или \"Завершить\", чтобы завершить ввод:");
System.out.println("Введите товар № "+(countter+1)+" или \"Завершить\", чтобы завершить ввод:");
String nameInput = scanner.nextLine();
if (nameInput.equalsIgnoreCase("Завершить")) {
break;
Expand All @@ -22,23 +22,27 @@ public void newTovar() {
while (true) {
if (scanner.hasNextDouble()) {
priceInput = scanner.nextDouble();
break;
} else {
scanner.nextLine();
if (priceInput < 1){
System.out.println("Введите число больше 0");
}
else {break;}}
else {
System.out.println("Некорректный ввод, попробуйте еще раз");
}
scanner.nextLine();
}
}
name.add(nameInput);
price.add(priceInput);
count++;
countter++;
sum += priceInput;
System.out.println("Товар №"+count+ "\"" + nameInput + "\" успешно добавлен!");
System.out.println("Товар №"+countter+ "\"" + nameInput + "\" успешно добавлен!");
}

}
void print() {
System.out.println("Добавленные товары: \n"+"\n"+"\n");
System.out.println("Добавленные товары: \n");
RubFormat rub = new RubFormat();
for (int i = 0; i < count; i++) {
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");
}
Expand Down
32 changes: 12 additions & 20 deletions src/main/java/Count.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
import java.util.Scanner;

public class Count {
public static int count() {

static int count() {
int number ;
int persons;
int number;
Scanner sc = new Scanner(System.in);
System.out.println("На скольких человек необходимо разделить счет?");
while (true) {
System.out.println("На скольких человек необходимо разделить счет?");
while (true) {
if (sc.hasNextInt()) {
number = sc.nextInt();
break;
}
else {
sc.next();
System.out.println("Некорректный ввод, попробуйте еще раз");
}
}
if (sc.hasNextInt()) {
if (number < 1) {
System.out.println("Некорректный ввод, попробуйте еще раз");
} else if (number == 1) {
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;
}


}

}
9 changes: 4 additions & 5 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ public class Main {
public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости

Count guestCount = new Count();
Calculator check = new Calculator();
int getCount = Count.count();

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

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

}
}


31 changes: 11 additions & 20 deletions src/main/java/RubFormat.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
public class RubFormat {
String format(double input) {
String rub;
int ending = (int) input % 100;
switch (ending % 10) {
case 1: {
rub = " рубль";
break;
}
case 2:
case 3:
case 4:
{rub = " рубля";
break;}
default : {
rub = " рублей";
break;
}
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;
}
}