forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculation.java
More file actions
33 lines (26 loc) · 1.21 KB
/
Calculation.java
File metadata and controls
33 lines (26 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Iterator;
import java.util.Map;
public class Calculation {
//Процедура третей части
static void calculationOutput(int quantity, Map receipt){
float perCost;
int intPerCost;
String sRubOne = "рубль";
String sRubls = "рубля";
String sMoreRubls = "рублей";
System.out.println("Добавленные товары:");
Iterator<Map.Entry<String, Float>> iterator = receipt.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<String, Float> entry = iterator.next();
String product = entry.getKey();
Float cost = entry.getValue();
System.out.println(product + " стоит " + cost);
}
perCost = Main.totalCost / quantity;
if (perCost * (double)(quantity) < Main.totalCost){
perCost += 0.01f;
}
intPerCost = (int) Math.ceil(perCost);
System.out.println(String.format("Общая стоимость счета " + Main.totalCost + ", каждый должен внести %.2f %s или %d %s", perCost, Main.GetRubls(intPerCost), intPerCost, Main.GetRubls(intPerCost)));
}
}