import java.util.ArrayList;
public class Calculator {
int people;
float total = 0;
ArrayList products = new ArrayList<>();
Calculator(int people){
this.people = people;
}
public void addProduct(Product newProduct){
products.add(newProduct);
total += newProduct.price;
}
public void print(){
System.out.println("ÐобавленнÑе ÑоваÑÑ:");
for (int i = 0; i < products.size(); i ++){
System.out.println(String.format("ÐÑодÑÐºÑ %s Ñ Ñеной в %.2f %s", products.get(i).name, products.get(i).price, rubleFormat(products.get(i).price)));
}
System.out.println(String.format("\nÐÑого: %.2f %s", total, rubleFormat(total)));
float perPerson = total / (float) people;
System.out.println(String.format("ÐолÑÑаеÑÑÑ %.2f %s Ñ Ñеловека", perPerson, rubleFormat(perPerson)));
}
public String rubleFormat(float price){
int check = (int) price;
String result = "ÐÑÐбÐаааааÐÐаÐаÐ";
if (check % 100 >= 11 && check % 100 <= 19){
result = "ÑÑблей";
}
else if (check % 10 == 1){
result = "ÑÑблÑ";
}
else if (check % 10 >= 2 && check % 10 <= 4) {
result = "ÑÑблÑ";
}
else{
result = "ÑÑблей";
}
return result;
}
}