package visitor;
public class Client {
static List<Equipment> shop = new ArrayList<Equipment>();
/**
* @param args
*/
public static void main
(String[] args
) {
FloppyDisk fdisk1 = new FloppyDisk("3.5");
fdisk1.setDisountPrice(8);
fdisk1.setNetPrice(10);
shop.add(fdisk1);
Card videoCard1 = new Card("GeForce1");
videoCard1.setDisountPrice(80);
videoCard1.setNetPrice(100);
shop.add(videoCard1);
Card videoCard2 = new Card("GeForce2");
videoCard2.setDisountPrice(100);
videoCard2.setNetPrice(120);
shop.add(videoCard2);
Card motherCard1 = new Card("Asus");
motherCard1.setDisountPrice(200);
motherCard1.setNetPrice(250);
shop.add(motherCard1);
Chassis sys1 = new Chassis("AMD");
FloppyDisk fdisk2 = new FloppyDisk("3.5");
fdisk1.setDisountPrice(9);
fdisk1.setNetPrice(11);
sys1.Add(fdisk2);
Card videoCard3 = new Card("GeForce MX");
videoCard3.setDisountPrice(50);
videoCard3.setNetPrice(55);
sys1.Add(videoCard3);
Card motherCard2 = new Card("Gigabyte");
motherCard2.setDisountPrice(200);
motherCard2.setNetPrice(250);
sys1.Add(motherCard2);
shop.add(sys1);
/* ... и т.д. другие товары... */
PricingVisitor priceVisitor = new PricingVisitor();
VisitShop(priceVisitor);
System.
out.
println("Полная стоимость товаров магазина: " +
priceVisitor.getTotal());
InventoryVisitor countVisitor = new InventoryVisitor();
VisitShop(countVisitor);
System.
out.
println("На данный момент магазин располагает:");
System.
out.
println("Флопиков - " +
countVisitor.getFloppyNum() + " штук,");
System.
out.
println("Видео и материнских плат - " +
countVisitor.getCardNum() + " штук,");
System.
out.
println("Системных блоков - " +
countVisitor.getChassisNum() + " штук");
}
public static void VisitShop(EquipmentVisitor v) {
Iterator<Equipment> assortment = shop.iterator();
while (assortment.hasNext()) {
assortment.next().Accept(v);
}
}
}