/
EugenyCh7
/
JavaAndScalaLessons
Обзор
Документация
Войти
/
EugenyCh7
/
JavaAndScalaLessons
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
JavaTest/src/ch2/ex15/Invoice.java
41 строка
1 KB
Eugeny Chekmarev
IDEA update
15 июн 2021, 21:11
15 июн 2021, 21:11
47fadf9
Код
Авторство
О чём код?
package ch2.ex15; import java.util.ArrayList; public class Invoice { public static class Item { private String description; private int quality; private double unitPrice; public Item(String description, int quality, double unitPrice) { this.description = description; this.quality = quality; this.unitPrice = unitPrice; } public double price() { return quality * unitPrice; } public String format() { return String.format("\"%s\" : %d * %f = %f", description, quality, unitPrice, price()); } } private ArrayList<Item> items = new ArrayList<>(); public void add(Item item) { items.add(item); } public void report() { double total = 0.0; for (Item item : items) { System.out.println(item.format()); total += item.price(); } System.out.printf("Итого к оплате: %f\n", total); } }