Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 28.76 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.util.Calendar;
  3. import java.util.Date;
  4. import java.util.GregorianCalendar;
  5. import java.util.HashMap;
  6. import java.util.Iterator;
  7.  
  8. import com.menonthemoon.lagerVerwaltung.Configuration;
  9. import com.menonthemoon.lagerVerwaltung.Product;
  10. import com.menonthemoon.lagerVerwaltung.ProductGroup;
  11. import com.menonthemoon.lagerVerwaltung.Stock;
  12. import com.menonthemoon.lagerVerwaltung.StockException;
  13. import com.menonthemoon.lagerVerwaltung.StockManager;
  14.  
  15. public class Test {
  16.     private static String c = ":> ";
  17.  
  18.     static double nPrices[] = {40.0 , 70.0, 10.0, 50.0, 75.0, 100.0, 120.0, 330.0, 100.0, 140.0, 120.0, 100.0, 50.0, 220.0, 180.0, 50.0, 40.0, 50.0, 70.0, 20.0, 20.0};
  19.     static double salesPrices[] = {80.0, 140.0, 15.0, 75.0, 110.0, 150.0, 180.0, 550.0, 140.0, 180.0, 165.0, 140.0, 90.0, 340.0, 210.0, 90, 70.0, 80.0, 110.0, 40.0, 40.0};
  20.     static double warehouseCharges[] = {1.0, 1.0, 0.5, 10.0, 20.0, 0.5, 0.5, 1.0, 1.0, 2.0, 2.0, 0.5, 0.5, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 0.5, 0.5};
  21.    
  22.     private static Product[] products = {
  23.             new Product("Samsung Rx1213 CD-Laufwerk", "CD-Rom 52x",new BigDecimal(nPrices[0]),salesPrices[0],warehouseCharges[0]), // #0
  24.             new Product("BD-R/BD-RE Laufwerk SATA LG BH08LS, Blu-ray, Bulk ",
  25.                     "Schwarz",new BigDecimal(nPrices[1]),salesPrices[1],warehouseCharges[1]),
  26.             new Product("Mitsubishi F12 Floppy-Laufwerk", "Floppy Disc"),
  27.             // - cases
  28.             new Product("Chieftech Mini Tower", "Small PC-case",new BigDecimal(nPrices[2]),salesPrices[2],warehouseCharges[2]),
  29.             new Product("Chieftech Big Tower", "Big PC-case",new BigDecimal(nPrices[3]),salesPrices[3],warehouseCharges[3]),
  30.             // - processors
  31.             new Product("AMD Athlon (S-AM2+)",
  32.                     "Prozessor AMD Athlon X2 7850 Black Edition, 2,8GHz, Dual-Core, S-AM2+, Tray",new BigDecimal(nPrices[4]),salesPrices[4],warehouseCharges[4]),
  33.             new Product("Intel Atom D510 (Dual-Core) / 1,67 GHz",
  34.                     "Intel Atom, Engery efficient", new BigDecimal(nPrices[5]),salesPrices[5],warehouseCharges[5]),
  35.             // - hdd
  36.             new Product("Seagate, 320 GB HDD, SSD", "SolidStateDisk", new BigDecimal(nPrices[6]),salesPrices[6],warehouseCharges[6]),
  37.             new Product("Western Digital, 1 TB HDD, SATA", "A lot of space",new BigDecimal(nPrices[7]),salesPrices[7],warehouseCharges[7]),
  38.             // - mainboard
  39.             new Product("S-462 ASROCK K7S41GX", "AMD Mainboard, Socket 462",new BigDecimal(nPrices[8]),salesPrices[8],warehouseCharges[8]),
  40.             new Product("GIGABYTE GA-P55-UD5, ATX", // #10
  41.                     "INTEL Mainboard, Socket 1156",new BigDecimal(nPrices[9]),salesPrices[9],warehouseCharges[9]),
  42.             // - RAM
  43.             new Product("DDR3-RAM", "4GB",new BigDecimal(nPrices[10]),salesPrices[10],warehouseCharges[10]),
  44.             new Product("DDR2-RAM", "4GB",new BigDecimal(nPrices[11]),salesPrices[11],warehouseCharges[11]),
  45.             // -graficsCard
  46.             new Product("PCI-E 2.0 ASUS Extreme AH4350", "PCI-e",new BigDecimal(nPrices[12]),salesPrices[12],warehouseCharges[12]),
  47.             new Product("AGP 8x MATROX QID, 128MB", "AGP",new BigDecimal(nPrices[13]),salesPrices[13],warehouseCharges[13]),
  48.             // -cooling
  49.             new Product("COOLER MASTER Hyper 212 Plus", "Socket 1156",new BigDecimal(nPrices[14]),salesPrices[14],warehouseCharges[14]),
  50.             new Product("CORSAIR A50 Performance", "Socket 462",new BigDecimal(nPrices[15]),salesPrices[15],warehouseCharges[15]),
  51.             // -acSupply
  52.             new Product("510 Watt, ZIPPY P2G-6510P, 2HE, EPS12V", "510 Watt",new BigDecimal(nPrices[16]),salesPrices[16],warehouseCharges[16]),
  53.             new Product("ATX 600 Watt, ENERMAX PRO87+, 80Plus-Gold",
  54.                     "ATX 600 Watt",new BigDecimal(nPrices[17]),salesPrices[17],warehouseCharges[17]),
  55.             // -networking
  56.             new Product("PCI Intel PRO/100GT", "PCI, 10/100 MBit",new BigDecimal(nPrices[18]),salesPrices[18],warehouseCharges[18]),
  57.             new Product("PCI-E INTEL Pro 1000 ", "PCI-E, 10/100/1000 MBit",new BigDecimal(nPrices[19]),salesPrices[19],warehouseCharges[19]) // #20
  58.  
  59.     };
  60.     private static int[] amounts = { 12, 15, 6, 17, 22, 8, 13, 4, 11, 7, 12,
  61.             25, 34, 7, 9, 22, 23, 39, 21, 6, 11 };
  62.     private static Stock stock;
  63.  
  64.     public static String addProducts() {
  65.         boolean retVal = true;
  66.         for (int i = 0; i < products.length; i++) {
  67.             retVal &= testAdd(products[i], amounts[i]);
  68.         }
  69.         // increase amount:
  70.         retVal &= testAdd(products[0], amounts[0]);
  71.         retVal &= testAdd(products[20], 0);
  72.         retVal &= testAdd(products[5], -1) == false;
  73.         return retVal ? "SUCCESS" : "FAIL";
  74.     }
  75.  
  76.     public static boolean testAdd(Product p, int a) {
  77.         Integer oldVal, newVal;
  78.         try {
  79.             oldVal = stock.add(p, a);
  80.         } catch (StockException e) {
  81.             return false;
  82.         }
  83.         if (oldVal == null) {
  84.             oldVal = new Integer(0);
  85.         }
  86.         newVal = stock.getStock(p);
  87.         if (newVal.intValue() == oldVal.intValue() + a) {
  88.             return true;
  89.         }
  90.         return false;
  91.     }
  92.  
  93.     public static String testTake() {
  94.         Integer before, after;
  95.         before = stock.getStock(products[0]);
  96.         try {
  97.             stock.take(products[0], 1);
  98.         } catch (StockException e) {
  99.             // TODO Auto-generated catch block
  100.         }
  101.         after = stock.getStock(products[0]);
  102.         if (after.intValue() == before.intValue() - 1) {
  103.             return "SUCCESS";
  104.         }
  105.         return "FAIL";
  106.     }
  107.  
  108.     public static String testRemove() {
  109.         try {
  110.             if (stock.getStock(products[0]) != null) {
  111.                 stock.remove(products[0]);
  112.  
  113.             }
  114.             if (stock.getStock(products[0]) == null) {
  115.                 stock.add(products[0], amounts[0]);
  116.                 return "SUCCESS";
  117.             }
  118.         } catch (StockException e) {
  119.         }
  120.         return "FAIL";
  121.     }
  122.    
  123.     public static String testOrdering() {
  124.         Product p = products[0];
  125.        
  126.         /*
  127.          * Import one product to the stock at 22.12.2010  
  128.          */
  129.         int initialStock = stock.getStock(p);
  130.         Date importDate = new GregorianCalendar(2010, Calendar.DECEMBER, 22).getTime();
  131.         int importAmount = 1;
  132.         System.out.print("\tImport a product at "+importDate.toString());
  133.         try {
  134.             stock.importProduct(p, importAmount, importDate);
  135.         } catch (StockException e1) {
  136.             System.out.println("[error] Fehler beim import: "+e1.getMessage());
  137.         }
  138.         int modifiedStock = stock.getStock(p, new GregorianCalendar(2010, Calendar.DECEMBER, 23).getTime());
  139.         String result = (modifiedStock == initialStock + importAmount) ? "SUCCESS" : "FAIL";
  140.         System.out.println("\t"+result);
  141.        
  142.         try {
  143.             Date exportDate = new GregorianCalendar(2010,Calendar.DECEMBER, 23).getTime();
  144.             // export exportAmount products from the stock at exportDate
  145.             System.out.print("\tExport a product with enough items in stock at "+exportDate.toString());
  146.             stock.exportProduct(p, 10, exportDate);
  147.             System.out.println("\tSUCCESS");
  148.            
  149.             System.out.println("\tExport a product with too little items in stock at "+exportDate.toString());
  150.             stock.exportProduct(p, 1000, exportDate);
  151.         } catch (StockException e) {
  152.             System.out.print("\t[error] "+e.getMessage());
  153.         }
  154.        
  155.         return "SUCCESS";
  156.     }
  157.    
  158.     public static String testMove() {
  159.         /*
  160.          * Move one product from a stock to another stock
  161.          */
  162.         Product p = products[1];
  163.         Stock affiliate = StockManager.sharedInstance().getAffiliateStocks().iterator().next();
  164.         int initialMainStock = stock.getStock(p);
  165.        
  166.         int intialAffiliateStock = affiliate.getStock(p);
  167.         int amountToMove = 3;
  168.         if(!StockManager.sharedInstance().getAffiliateStocks().isEmpty()) {
  169.             try {
  170.                 stock.moveProduct(p, amountToMove, affiliate, null);
  171.             } catch(StockException e) {
  172.                 System.out.println(c + "Das Produkt kann nicht verschoben werden: "+e.getMessage());
  173.             }
  174.         }
  175.        
  176.         int postMainStock = stock.getStock(p);
  177.         int postAffiliateStock = affiliate.getStock(p);
  178.        
  179.         System.out.println("\tInitial main stock amount of product: "+initialMainStock +
  180.                 "; Post-Move amount of product: "+postMainStock);
  181.        
  182.         System.out.println("\tInitial affiliate stock amount of product: "+intialAffiliateStock +
  183.                 "; Post-Move amount of product: "+postAffiliateStock);
  184.        
  185.         return (postMainStock == initialMainStock - amountToMove && postAffiliateStock == intialAffiliateStock + amountToMove) ?
  186.                 "SUCCESS" : "FAIL";
  187.     }
  188.  
  189.     public static void main(String[] args) {
  190.         performAssignment2();
  191.     }
  192.  
  193.     private static void performAssignment2() {
  194.         String welcome = "=========================================================================\n"
  195.             + "OOP (VL Objektorientierte Programmierung)\n"
  196.             + "\tAufgabe #2\n"
  197.             + "Gruppe:\n"
  198.             + "\t229\n"
  199.             + "Teilnehmer:\n"
  200.             + "\tALEXANDER WOLF e0102124@student.tuwien.ac.at\n"
  201.             + "\tDANIEL REICHHARD e0025792@student.tuwien.ac.at\n"
  202.             + "\tAUGUST NIKOLAUS KAMPFER e0326465@student.tuwien.ac.at\n"
  203.             + "=========================================================================\n";
  204.        
  205.         System.out.println(welcome);
  206.        
  207.         // create a new main stock and one affiliate stock
  208.         StockManager sm = StockManager.sharedInstance();
  209.         sm.setMainStock(new Stock());
  210.         sm.addAffiliateStock(new Stock());
  211.        
  212.         stock = sm.getMainStock();
  213.  
  214.         System.out.println("TEST: Adding products\t\t" + addProducts());
  215.         System.out.println("TEST: Taking products\t\t" + testTake());
  216.         System.out.println("TEST: Removing products\t\t" + testRemove());
  217.         System.out.println("TEST: Importing product at a given date\t\t");
  218.         System.out.println(testOrdering());
  219.         System.out.println("TEST: Moving products from one stock to another one\t\t");
  220.         System.out.println(testMove());
  221.        
  222.         Product p = products[0];
  223.        
  224.        
  225.        
  226.        
  227.         ProductGroup g1 = new ProductGroup("Internal Optical Drives");
  228.         g1.add(products[0]);
  229.         g1.add(products[20]);
  230.         stock.add(g1);
  231.         try {
  232.             System.out.println(c
  233.                     + "Entferne Produkt aus dem Lager, alter Bestand war: "
  234.                     + stock.remove(products[0]));
  235.         } catch (StockException e) {
  236.             System.out.println(e.getMessage());
  237.         }
  238.         Configuration c1 = new Configuration("Business Desktop PC, small",999.0,9.0);
  239.         c1.add(products[1], 1);
  240.         c1.add(products[2], 1);
  241.         c1.add(products[3], 1);
  242.         c1.add(products[4], 1);
  243.         c1.add(g1, 12);
  244.  
  245.         System.out.println(c + "Konfiguration: " + c1.getName()
  246.                 + " wurde erstellt und enth√§lt folgende Produkte:");
  247.         HashMap<Product, Integer> productMap = c1.getConfiguration();
  248.         Iterator<Product> it = productMap.keySet().iterator();
  249.         while (it.hasNext()) {
  250.             Product p1 = it.next();
  251.             System.out.println(c + "\t" + p1.getName() + " ("
  252.                     + productMap.get(p1) + " Stk.; Lagerbestand: "
  253.                     + stock.getStock(p1) + ")");
  254.         }
  255.     }
  256.  
  257.     private static void performAssignment1() {
  258.         String welcome = "=========================================================================\n"
  259.                 + "OOP (VL Objektorientierte Programmierung)\n"
  260.                 + "\tAufgabe #1\n"
  261.                 + "Gruppe:\n"
  262.                 + "\t229\n"
  263.                 + "Teilnehmer:\n"
  264.                 + "\tALEXANDER WOLF e0102124@student.tuwien.ac.at\n"
  265.                 + "\tDANIEL REICHHARD e0025792@student.tuwien.ac.at\n"
  266.                 + "\tAUGUST NIKOLAUS KAMPFER e0326465@student.tuwien.ac.at\n"
  267.                 + "=========================================================================\n";
  268.  
  269.         String taskA = "A.)  Anlegen von Produkten, wobei jedes Produkt einen eindeutigen \n\tNamen und eine Beschreibung erhaelt.\n";
  270.         String taskB = "B.)  Erhoehen und Verringern des Lagerbestandes (= Anzahl der vorhandenen\n\tStuecke)sowie Abfragen des Lagerbestandes und aller weiteren \n\tDaten zu einem Produkt.\n";
  271.         String taskB1 = "B.1)  Der Lagerbestand von einigen Produkten wird entsprechend verringert\n";
  272.         String taskC = "C/D/E) \n\tAnlegen von Produktgruppen (wie z.B. Prozessoren, Festplatten und Hauptspeicher).\n"
  273.                 + "\tZuordnen von Produkten und Produktgruppen zu (anderen) Produktgruppen \n\t(wie z.B. von X zur Produktgruppe DVD-Brenner und von DVD-Brenner \n\tzur Produktgruppe Optische Laufwerke), wobei Produkte und Produktgruppen auch \n\tmehreren (anderen) Produktgruppen zugeordnet sein koennen.\n"
  274.                 + "\tAuflisten aller Produkte einer Produktgruppe einschlieszlich Lagerbestand, \n\twobei auch alle Produkte aller zugeordneten Produktgruppen aufgelistet werden \n\t(z.B. auch der DVD-Brenner X in der Auflistung von Optische Laufwerke)\n";
  275.         String taskF = "F.)  Anlegen von Konfigurationen, die gegebene Stueckzahlen bestimmter Produkte \n\tunter neuen Namen zusammenfassen (wie z.B. 1 Gehaaeuse G, 1 Mainboard M, 2 \n\tHauptspeicher R und 2 Festplatten H zur Konfiguration Komplettsystem1)\n";
  276.         String taskG = "G.)  Abfragen des Lagerbestands fuer eine Konfiguration, wobei ermittelt wird,\n\twie viele entsprechend konfigurierte Geraete aus dem Lagerbestand zusammengebaut werden koennen.\n";
  277.         String taskH = "H.)  Verringern des Lagerbestands aller Produkte, die fuer eine bestimmte \n\tAnzahl an Geraeten einer bestimmten Konfiguration benoetigt werden\n";
  278.  
  279.         System.out.println(welcome);
  280.         System.out.println(c + "Erstellung einer Lagerinstanz.\n");
  281.         // Create the new Stock
  282.         Stock stock = new Stock();
  283.  
  284.         // Create all available products
  285.         // - internal drives
  286.         System.out.println(c + taskA);
  287.         Product p1 = new Product("Samsung Rx1213 CD-Laufwerk", "CD-Rom 52x");
  288.         System.out.println(c + "Produkt: " + p1.getName() + " wurde erstellt");
  289.  
  290.         Product p21 = new Product(
  291.                 "BD-R/BD-RE Laufwerk SATA LG BH08LS, Blu-ray, Bulk ", "Schwarz");
  292.         System.out.println(c + "Produkt: " + p21.getName() + " wurde erstellt");
  293.  
  294.         Product p2 = new Product("Mitsubishi F12 Floppy-Laufwerk",
  295.                 "Floppy Disc");
  296.         System.out.println(c + "Produkt: " + p2.getName() + " wurde erstellt");
  297.  
  298.         // - cases
  299.         Product p3 = new Product("Chieftech Mini Tower", "Small PC-case");
  300.         System.out.println(c + "Produkt: " + p3.getName() + " wurde erstellt");
  301.         Product p4 = new Product("Chieftech Big Tower", "Big PC-case");
  302.         System.out.println(c + "Produkt: " + p4.getName() + " wurde erstellt");
  303.  
  304.         // - processors
  305.         Product p5 = new Product("AMD Athlon (S-AM2+)",
  306.                 "Prozessor AMD Athlon X2 7850 Black Edition, 2,8GHz, Dual-Core, S-AM2+, Tray");
  307.         System.out.println(c + "Produkt: " + p5.getName() + " wurde erstellt");
  308.         Product p6 = new Product("Intel Atom D510 (Dual-Core) / 1,67 GHz",
  309.                 "Intel Atom, Engery efficient");
  310.         System.out.println(c + "Produkt: " + p6.getName() + " wurde erstellt");
  311.         // -hdd
  312.         Product p7 = new Product("Seagate, 320 GB HDD, SSD", "SolidStateDisk");
  313.         System.out.println(c + "Produkt: " + p7.getName() + " wurde erstellt");
  314.         Product p8 = new Product("Western Digital, 1 TB HDD, SATA",
  315.                 "A lot of space");
  316.         System.out.println(c + "Produkt: " + p8.getName() + " wurde erstellt");
  317.         // -mainboard
  318.         Product p9 = new Product("S-462 ASROCK K7S41GX",
  319.                 "AMD Mainboard, Socket 462");
  320.         System.out.println(c + "Produkt: " + p9.getName() + " wurde erstellt");
  321.         Product p10 = new Product("GIGABYTE GA-P55-UD5, ATX",
  322.                 "INTEL Mainboard, Socket 1156");
  323.         System.out.println(c + "Produkt: " + p10.getName() + " wurde erstellt");
  324.  
  325.         // -RAM
  326.         Product p11 = new Product("DDR3-RAM", "4GB");
  327.         System.out.println(c + "Produkt: " + p11.getName() + " wurde erstellt");
  328.         Product p12 = new Product("DDR2-RAM", "4GB");
  329.         System.out.println(c + "Produkt: " + p12.getName() + " wurde erstellt");
  330.  
  331.         // -graficsCard
  332.         Product p13 = new Product("PCI-E 2.0 ASUS Extreme AH4350", "PCI-e");
  333.         System.out.println(c + "Produkt: " + p13.getName() + " wurde erstellt");
  334.         Product p14 = new Product("AGP 8x MATROX QID, 128MB", "AGP");
  335.         System.out.println(c + "Produkt: " + p14.getName() + " wurde erstellt");
  336.  
  337.         // -cooling
  338.         Product p15 = new Product("COOLER MASTER Hyper 212 Plus", "Socket 1156");
  339.         System.out.println(c + "Produkt: " + p15.getName() + " wurde erstellt");
  340.         Product p16 = new Product("CORSAIR A50 Performance", "Socket 462");
  341.         System.out.println(c + "Produkt: " + p16.getName() + " wurde erstellt");
  342.  
  343.         // -acSupply
  344.         Product p17 = new Product("510 Watt, ZIPPY P2G-6510P, 2HE, EPS12V",
  345.                 "510 Watt");
  346.         System.out.println(c + "Produkt: " + p17.getName() + " wurde erstellt");
  347.         Product p18 = new Product("ATX 600 Watt, ENERMAX PRO87+, 80Plus-Gold",
  348.                 "ATX 600 Watt");
  349.         System.out.println(c + "Produkt: " + p18.getName() + " wurde erstellt");
  350.  
  351.         // -networking
  352.         Product p19 = new Product("PCI Intel PRO/100GT", "PCI, 10/100 MBit");
  353.         System.out.println(c + "Produkt: " + p19.getName() + " wurde erstellt");
  354.         Product p20 = new Product("PCI-E INTEL Pro 1000 ",
  355.                 "PCI-E, 10/100/1000 MBit");
  356.         System.out.println(c + "Produkt: " + p20.getName()
  357.                 + " wurde erstellt\n");
  358.  
  359.         /*
  360.          * Add the products to the stock and set their amount number
  361.          */
  362.         System.out.println(c + taskB);
  363.         try {
  364.             stock.add(p1, 12);
  365.        
  366.         System.out.println(c + "Lagerbestand von: " + p1.getName() + " auf \""
  367.                 + stock.getStock(p1) + "\" erh√∂ht");
  368.         stock.add(p2, 15);
  369.         System.out.println(c + "Lagerbestand von: " + p2.getName() + " auf \""
  370.                 + stock.getStock(p2) + "\" erh√∂ht");
  371.         stock.add(p3, 6);
  372.         System.out.println(c + "Lagerbestand von: " + p3.getName() + " auf \""
  373.                 + stock.getStock(p3) + "\" erh√∂ht");
  374.         stock.add(p4, 17);
  375.         System.out.println(c + "Lagerbestand von: " + p4.getName() + " auf \""
  376.                 + stock.getStock(p4) + "\" erh√∂ht");
  377.         stock.add(p5, 22);
  378.         System.out.println(c + "Lagerbestand von: " + p5.getName() + " auf \""
  379.                 + stock.getStock(p5) + "\" erh√∂ht");
  380.         stock.add(p6, 8);
  381.         System.out.println(c + "Lagerbestand von: " + p6.getName() + " auf \""
  382.                 + stock.getStock(p6) + "\" erh√∂ht");
  383.         stock.add(p7, 13);
  384.         System.out.println(c + "Lagerbestand von: " + p7.getName() + " auf \""
  385.                 + stock.getStock(p7) + "\" erh√∂ht");
  386.         stock.add(p8, 4);
  387.         System.out.println(c + "Lagerbestand von: " + p8.getName() + " auf \""
  388.                 + stock.getStock(p8) + "\" erh√∂ht");
  389.         stock.add(p9, 11);
  390.         System.out.println(c + "Lagerbestand von: " + p9.getName() + " auf \""
  391.                 + stock.getStock(p9) + "\" erh√∂ht");
  392.         stock.add(p10, 7);
  393.         System.out.println(c + "Lagerbestand von: " + p10.getName() + " auf \""
  394.                 + stock.getStock(p10) + "\" erh√∂ht");
  395.         stock.add(p11, 12);
  396.         System.out.println(c + "Lagerbestand von: " + p11.getName() + " auf \""
  397.                 + stock.getStock(p11) + "\" erh√∂ht");
  398.         stock.add(p12, 25);
  399.         System.out.println(c + "Lagerbestand von: " + p12.getName() + " auf \""
  400.                 + stock.getStock(p12) + "\" erh√∂ht");
  401.         stock.add(p13, 34);
  402.         System.out.println(c + "Lagerbestand von: " + p13.getName() + " auf \""
  403.                 + stock.getStock(p13) + "\" erh√∂ht");
  404.         stock.add(p14, 7);
  405.         System.out.println(c + "Lagerbestand von: " + p14.getName() + " auf \""
  406.                 + stock.getStock(p14) + "\" erh√∂ht");
  407.         stock.add(p15, 9);
  408.         System.out.println(c + "Lagerbestand von: " + p15.getName() + " auf \""
  409.                 + stock.getStock(p15) + "\" erh√∂ht");
  410.         stock.add(p16, 22);
  411.         System.out.println(c + "Lagerbestand von: " + p16.getName() + " auf \""
  412.                 + stock.getStock(p16) + "\" erh√∂ht");
  413.         stock.add(p17, 23);
  414.         System.out.println(c + "Lagerbestand von: " + p17.getName() + " auf \""
  415.                 + stock.getStock(p17) + "\" erh√∂ht");
  416.         stock.add(p18, 39);
  417.         System.out.println(c + "Lagerbestand von: " + p18.getName() + " auf \""
  418.                 + stock.getStock(p18) + "\" erh√∂ht");
  419.         stock.add(p19, 21);
  420.         System.out.println(c + "Lagerbestand von: " + p19.getName() + " auf \""
  421.                 + stock.getStock(p19) + "\" erh√∂ht");
  422.         stock.add(p20, 6);
  423.         System.out.println(c + "Lagerbestand von: " + p20.getName() + " auf \""
  424.                 + stock.getStock(p20) + "\" erh√∂ht");
  425.         stock.add(p21, 11);
  426.         System.out.println(c + "Lagerbestand von: " + p21.getName() + " auf \""
  427.                 + stock.getStock(p21) + "\" erh√∂ht\n");
  428.  
  429.         System.out.println(c + taskB1);
  430.  
  431.         stock.take(p1, 2);
  432.         System.out
  433.                 .println(c + "Lagerbestand von: " + p1.getName()
  434.                         + " wurde auf \"" + stock.getStock(p1)
  435.                         + "\" verringert");
  436.  
  437.         stock.take(p7, 7);
  438.         System.out
  439.                 .println(c + "Lagerbestand von: " + p7.getName()
  440.                         + " wurde auf \"" + stock.getStock(p7)
  441.                         + "\" verringert");
  442.  
  443.         stock.take(p13, 21);
  444.         System.out.println(c + "Lagerbestand von: " + p13.getName()
  445.                 + " wurde auf \"" + stock.getStock(p13)
  446.                 + "\" verringert\n");
  447.  
  448.         System.out.println(c + taskC);
  449.  
  450.         // Create the product-groups and add the corresponding products
  451.         ProductGroup g1 = new ProductGroup("Internal Optical Drives");
  452.         g1.add(p1);
  453.         g1.add(p21);
  454.         System.out.println(c + "Produktgruppe \"" + g1.getName()
  455.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  456.         Iterator<Product> it = g1.getProducts().iterator();
  457.         while (it.hasNext()) {
  458.             Product p = it.next();
  459.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  460.                     + stock.getStock(p) + ")");
  461.         }
  462.         System.out.print("\n");
  463.  
  464.         ProductGroup g2 = new ProductGroup("Internal Magnetic Drives");
  465.         g2.add(p2);
  466.         System.out.println(c + "Produktgruppe \"" + g2.getName()
  467.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  468.         it = g2.getProducts().iterator();
  469.         while (it.hasNext()) {
  470.             Product p = it.next();
  471.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  472.                     + stock.getStock(p) + ")");
  473.         }
  474.         System.out.print("\n");
  475.  
  476.         // -internal Drives
  477.         ProductGroup g3 = new ProductGroup("Internal Drives");
  478.         g3.add(g1);
  479.         g3.add(g2);
  480.         System.out.println(c + "Produktgruppe \"" + g3.getName()
  481.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  482.         it = g3.getProducts().iterator();
  483.         while (it.hasNext()) {
  484.             Product p = it.next();
  485.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  486.                     + stock.getStock(p) + ")");
  487.         }
  488.         System.out.print("\n");
  489.  
  490.         // -case-products
  491.         ProductGroup g4 = new ProductGroup("Cases");
  492.         g4.add(p3);
  493.         g4.add(p4);
  494.         System.out.println(c + "Produktgruppe \"" + g4.getName()
  495.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  496.         it = g4.getProducts().iterator();
  497.         while (it.hasNext()) {
  498.             Product p = it.next();
  499.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  500.                     + stock.getStock(p) + ")");
  501.         }
  502.         System.out.print("\n");
  503.  
  504.         ProductGroup g5 = new ProductGroup("AMD");
  505.         g5.add(p5);
  506.         System.out.println(c + "Produktgruppe \"" + g5.getName()
  507.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  508.         it = g5.getProducts().iterator();
  509.         while (it.hasNext()) {
  510.             Product p = it.next();
  511.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  512.                     + stock.getStock(p) + ")");
  513.         }
  514.         System.out.print("\n");
  515.  
  516.         ProductGroup g6 = new ProductGroup("INTEL");
  517.         g6.add(p6);
  518.         System.out.println(c + "Produktgruppe \"" + g6.getName()
  519.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  520.         it = g6.getProducts().iterator();
  521.         while (it.hasNext()) {
  522.             Product p = it.next();
  523.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  524.                     + stock.getStock(p) + ")");
  525.         }
  526.         System.out.print("\n");
  527.  
  528.         // -processors
  529.         ProductGroup g7 = new ProductGroup("CPU");
  530.         g7.add(g5);
  531.         g7.add(g6);
  532.         System.out.println(c + "Produktgruppe \"" + g7.getName()
  533.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  534.         it = g7.getProducts().iterator();
  535.         while (it.hasNext()) {
  536.             Product p = it.next();
  537.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  538.                     + stock.getStock(p) + ")");
  539.         }
  540.         System.out.print("\n");
  541.  
  542.         // -hddÔøΩs
  543.         ProductGroup g8 = new ProductGroup("HDD");
  544.         g8.add(p7);
  545.         g8.add(p8);
  546.         System.out.println(c + "Produktgruppe \"" + g8.getName()
  547.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  548.         it = g8.getProducts().iterator();
  549.         while (it.hasNext()) {
  550.             Product p = it.next();
  551.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  552.                     + stock.getStock(p) + ")");
  553.         }
  554.         System.out.print("\n");
  555.  
  556.         // -mainboards
  557.         ProductGroup g9 = new ProductGroup("Mainboards");
  558.         g9.add(p9);
  559.         g9.add(p10);
  560.         System.out.println(c + "Produktgruppe \"" + g9.getName()
  561.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  562.         it = g9.getProducts().iterator();
  563.         while (it.hasNext()) {
  564.             Product p = it.next();
  565.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  566.                     + stock.getStock(p) + ")");
  567.         }
  568.         System.out.print("\n");
  569.  
  570.         ProductGroup g10 = new ProductGroup("DDR3");
  571.         g10.add(p11);
  572.         System.out.println(c + "Produktgruppe \"" + g10.getName()
  573.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  574.         it = g10.getProducts().iterator();
  575.         while (it.hasNext()) {
  576.             Product p = it.next();
  577.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  578.                     + stock.getStock(p) + ")");
  579.         }
  580.         System.out.print("\n");
  581.  
  582.         ProductGroup g11 = new ProductGroup("DDR2");
  583.         g11.add(p12);
  584.         System.out.println(c + "Produktgruppe \"" + g11.getName()
  585.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  586.         it = g11.getProducts().iterator();
  587.         while (it.hasNext()) {
  588.             Product p = it.next();
  589.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  590.                     + stock.getStock(p) + ")");
  591.         }
  592.         System.out.print("\n");
  593.  
  594.         // -RAM
  595.         ProductGroup g12 = new ProductGroup("Memory");
  596.         g12.add(g10);
  597.         g12.add(g11);
  598.         System.out.println(c + "Produktgruppe \"" + g12.getName()
  599.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  600.         it = g12.getProducts().iterator();
  601.         while (it.hasNext()) {
  602.             Product p = it.next();
  603.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  604.                     + stock.getStock(p) + ")");
  605.         }
  606.         System.out.print("\n");
  607.  
  608.         // -gfxCard
  609.         ProductGroup g13 = new ProductGroup("Graficscard");
  610.         g13.add(p13);
  611.         g13.add(p14);
  612.         System.out.println(c + "Produktgruppe \"" + g13.getName()
  613.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  614.         it = g13.getProducts().iterator();
  615.         while (it.hasNext()) {
  616.             Product p = it.next();
  617.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  618.                     + stock.getStock(p) + ")");
  619.         }
  620.         System.out.print("\n");
  621.  
  622.         // -cooling
  623.         ProductGroup g14 = new ProductGroup("Cooling");
  624.         g14.add(p15);
  625.         g14.add(p16);
  626.         System.out.println(c + "Produktgruppe \"" + g14.getName()
  627.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  628.         it = g14.getProducts().iterator();
  629.         while (it.hasNext()) {
  630.             Product p = it.next();
  631.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  632.                     + stock.getStock(p) + ")");
  633.         }
  634.         System.out.print("\n");
  635.  
  636.         // -acSupply
  637.         ProductGroup g15 = new ProductGroup("Power Supply");
  638.         g15.add(p17);
  639.         g15.add(p18);
  640.         System.out.println(c + "Produktgruppe \"" + g15.getName()
  641.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  642.         it = g15.getProducts().iterator();
  643.         while (it.hasNext()) {
  644.             Product p = it.next();
  645.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  646.                     + stock.getStock(p) + ")");
  647.         }
  648.         System.out.print("\n");
  649.  
  650.         ProductGroup g16 = new ProductGroup("100 MBit");
  651.         g16.add(p19);
  652.         System.out.println(c + "Produktgruppe \"" + g16.getName()
  653.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  654.         it = g16.getProducts().iterator();
  655.         while (it.hasNext()) {
  656.             Product p = it.next();
  657.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  658.                     + stock.getStock(p) + ")");
  659.         }
  660.         System.out.print("\n");
  661.  
  662.         ProductGroup g17 = new ProductGroup("1000 MBit");
  663.         g17.add(p20);
  664.         System.out.println(c + "Produktgruppe \"" + g17.getName()
  665.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  666.         it = g17.getProducts().iterator();
  667.         while (it.hasNext()) {
  668.             Product p = it.next();
  669.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  670.                     + stock.getStock(p) + ")");
  671.         }
  672.         System.out.print("\n");
  673.  
  674.         // -networking
  675.         ProductGroup g18 = new ProductGroup("Networking");
  676.         g18.add(g16);
  677.         g18.add(g17);
  678.         System.out.println(c + "Produktgruppe \"" + g18.getName()
  679.                 + "\" wurde erstellt und enth√§lt folgende Produkte:");
  680.         it = g18.getProducts().iterator();
  681.         while (it.hasNext()) {
  682.             Product p = it.next();
  683.             System.out.println(c + "\t" + p.getName() + " (Lagerbestand: "
  684.                     + stock.getStock(p) + ")");
  685.         }
  686.         System.out.print("\n");
  687.         } catch (StockException e1) {
  688.         }
  689.         System.out.println(c + taskF);
  690.  
  691.         Configuration c1 = new Configuration("Business Desktop PC, small", 999.00, 9.00);
  692.         c1.add(p21, 1);
  693.         c1.add(p2, 1);
  694.         c1.add(p3, 1);
  695.         c1.add(p5, 1);
  696.         c1.add(p7, 2);
  697.         c1.add(p9, 1);
  698.         c1.add(p1, 2);
  699.         c1.add(p13, 2);
  700.         c1.add(p15, 1);
  701.         c1.add(p18, 1);
  702.         c1.add(p20, 2);
  703.  
  704.         stock.add(c1);
  705.         System.out.println(c + "Konfiguration: " + c1.getName()
  706.                 + " wurde erstellt und enth√§lt folgende Produkte:");
  707.         HashMap<Product, Integer> productMap = c1.getConfiguration();
  708.         for (Product p : productMap.keySet()) {
  709.             System.out.println(c + "\t" + p.getName() + " ("
  710.                     + productMap.get(p) + " Stk.; Lagerbestand: "
  711.                     + stock.getStock(p) + ")");
  712.         }
  713.         System.out.print("\n");
  714.  
  715.         System.out.println(c + taskG);
  716.  
  717.         System.out.println(c + "\"" + stock.getStock(c1)
  718.                 + "\"" + " " + "\"" + c1.getName() + "\""
  719.                 + " k√∂nnen erstellt werden.\n");
  720.  
  721.         System.out.println(c + taskH);
  722.         System.out.println(c + "Entferne Konfiguration \"" + c1.getName()
  723.                 + "\" 2x");
  724.         try {
  725.             stock.take(c1, 2);
  726.         } catch (StockException e) {
  727.             // TODO Auto-generated catch block
  728.             e.printStackTrace();
  729.         }
  730.  
  731.         for (Product p : productMap.keySet()){
  732.             System.out.println(c + "\tLagerbestand von " + p.getName()
  733.                     + " betr√§gt " + stock.getStock(p));
  734.         }
  735.  
  736.     }
  737. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement