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
66 changes: 33 additions & 33 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import java.util.Scanner;

import mypackage.Product;
import mypackage.ProductBusket;




public class Main {

public static String rubleDeclination(double numberExample) {
int rouble = (int) Math.floor(numberExample);

if (rouble >= 5 && rouble <= 20)
{
if (rouble >= 5 && rouble <= 20) {
return "рублей";
}
switch (rouble % 10)
{
switch (rouble % 10) {
case 1:
return "рубль";
case 2:
Expand All @@ -26,6 +23,7 @@ public static String rubleDeclination(double numberExample) {
return "рублей";
}
}

public static void main(String[] args) {
System.out.println(Main.class.getPackage().getName());
int numberOfGuests = 0;
Expand All @@ -47,59 +45,61 @@ public static void main(String[] args) {
}
}

ProductBusket myBusket = new ProductBusket();
ProductBusket myBusket = new ProductBusket();


while (true) {
String prodName = "";
if (myBusket.productList.size() == 0){
while (true) {
String prodName = "";
if (myBusket.productList.size() == 0) {

System.out.println("Введите название блюда");
prodName = scanner.next();
}
else {
System.out.println("Введите название блюда, если хотите добавить товар или 'завершить', если товаров больше нет.");
System.out.println("Введите название блюда");
prodName = scanner.next();
} else {
System.out.println("Введите название блюда, если хотите добавить товар или 'завершить', если товаров больше нет.");

prodName = scanner.next();
if (prodName.equalsIgnoreCase("Завершить")) {
break;
}
prodName = scanner.next();
if (prodName.equalsIgnoreCase("Завершить")) {
break;
}
}

// System.out.println("Введите название блюда.");
// String prodName = scanner.next();
// if (prodName.equalsIgnoreCase("Завершить")) {
// break;
// }
if (prodName.matches("[а-яА-Я]+")) {
while (true) {
try {
System.out.println("Введите стоимость блюда в формате рубли.копейки.");
Double prodPrice = scanner.nextDouble();
if (prodName.matches("[а-яА-Я]+")) {
while (true) {
try {
System.out.println("Введите стоимость блюда в формате рубли.копейки.");
Double prodPrice = scanner.nextDouble();
if (prodPrice > 0) {
Product a = new Product(prodName, prodPrice);
myBusket.addToBusket(a);
System.out.println("Блюдо успешно добавлено в корзину!");

break;


} catch (Exception e) {
String WrongName = scanner.next();
} else {
System.out.println("Ошибка. Неверно введена стоимость блюда. Введите снова!");
continue;
}
} catch (Exception e) {
String WrongName = scanner.next();
System.out.println("Ошибка. Неверно введена стоимость блюда. Введите снова!");
continue;
}
} else {
System.out.println("Неккоректно введено название блюда введите снова.");
}
} else {
System.out.println("Неккоректно введено название блюда введите снова.");
}
}

myBusket.displayProducts();
double result = ProductBusket.finalPrice / numberOfGuests;
double finalResult = Math.round(result * 100.0) / 100.0;
System.out.println( "Каждый гость заплатит: " + finalResult + " " + rubleDeclination(finalResult) + ".");
}
}
System.out.println("Каждый гость заплатит: " + finalResult + " " + rubleDeclination(finalResult) + ".");
}
}



Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package mypackage;

public class Product {

// Fields (instance variables)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mypackage;
import mypackage.Product;


import java.util.ArrayList;
import java.util.List;

Expand All @@ -13,7 +14,8 @@ public ProductBusket() {
this.finalPrice = 0;
this.productList = new ArrayList<>();
}
public void addToBusket(Product productExample){

public void addToBusket(Product productExample) {
productList.add(productExample);
finalPrice = finalPrice + productExample.price;

Expand All @@ -23,7 +25,7 @@ public void displayProducts() {
String message = "Добавленные товары: ";
System.out.println(message);
for (Product element : this.productList) {
element.displayInfo();
element.displayInfo();

}
}
Expand Down