import java.util.ArrayList;
import java.util.Scanner;
public class Calc {
ArrayList pList = new ArrayList();
double sum = 0; // ÐÐ¾Ð»Ð½Ð°Ñ ÑÑмма вÑеÑ
ÑоваÑов
static String inputStop= "завеÑÑиÑÑ";
// Class functions
public void startCalc(){
Scanner pScanner = new Scanner(System.in);
String str = ""; // Commodity name
double price = 0; // Commodity price
boolean flag = false;
while(!flag){
System.out.println("ÐведиÑе название ÑоваÑа");
str = pScanner.next();
boolean correctInput = false;
System.out.println("ÐведиÑе ÑоимоÑÑÑ ÑоваÑа \"" + str +"\" в ÑоÑмаÑе ÑÑбли.копейки' [10.45, 11.40]");
while(!correctInput){
if(pScanner.hasNextDouble()){
price = pScanner.nextDouble();
if(price>0) {
correctInput = true;
pList.add(new Commodity(str, price));
}
else{
System.out.println("Цена не Ð¼Ð¾Ð¶ÐµÑ Ð±ÑÑÑ Ð¾ÑÑиÑаÑелÑной или нÑлевой, введиÑе еÑе Ñаз");
}
}
else{
System.out.println("ÐевеÑнÑй ÑоÑмаÑ, попÑобÑйÑе Ñнова");
pScanner.next();
}
}
System.out.println("Ð¢Ð¾Ð²Ð°Ñ ÑÑпеÑно добавлен, Ñ
оÑиÑе пÑодолжиÑÑ? \n Ð´Ð»Ñ Ð·Ð°Ð²ÐµÑÑÐµÐ½Ð¸Ñ Ð²Ð²ÐµÐ´Ð¸Ñе \"завеÑÑиÑÑ\" ");
str = pScanner.next();
if(str.equalsIgnoreCase(inputStop)) break;// ÐÑÑ
одим, еÑли введено завеÑÑиÑÑ
}
}
public void showAllCommodities(){
System.out.println("ÐобавленнÑе ÑоваÑÑ:");
this.sum = 0; // ÐеÑед ÑаÑÑеÑом обнÑлим ÑÑÐ¼Ð¼Ñ ÑоваÑов на вÑÑкий ÑлÑÑай
for ( Commodity i:pList){
i.showCommodity();
sum+= i.price; //СÑÐ°Ð·Ñ ÑÑммиÑÑем ÑÑоимоÑÑÑ,
// ÑÑÐ¾Ð±Ñ Ð½Ðµ пÑогонÑÑÑ Ñикл по вÑоÑÐ¾Ð¼Ñ ÑÐ°Ð·Ñ Ð¾ÑделÑной ÑÑнкÑией
}
}
public void calculate(int personQuantity){
double money = this.sum/personQuantity;
System.out.println(String.format("ÐаждÑй плаÑÐ¸Ñ Ð¿Ð¾ %.2f %s",money,this.getWordEnd(money)));
}
public String getWordEnd(double num){
num = Math.floor(num);
int ost = (int)(num % 100);
if(ost>10 && ost <=14) return "ÑÑблей";
else ost =(int)(num % 10);
switch (ost){
case 1:
return "ÑÑблÑ";
case 2:
case 3:
case 4:
return "ÑÑблÑ";
default:
return "ÑÑблей";
}
}
public void releaseArray(){
for (Commodity c:this.pList) {
c.name="";
c.price=0;
}
this.pList.clear();
}
}