Advertisement
Guest User

Manager

a guest
Jun 1st, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.61 KB | None | 0 0
  1. /**
  2.  * SEF Supermarket System
  3.  * Student 1 : Michael Mansour s3509599
  4.  * Student 2 :
  5.  * Student 3 :
  6.  * Student 4 : Zixi Zhang s3459799
  7.  */
  8. package Manager;
  9.  
  10. import java.io.*;
  11. import java.util.*;
  12. import Sales.*;
  13. import Utilities.*;
  14.  
  15. /**
  16.  * @author Student :
  17.  *
  18.  */
  19. public class Manager {
  20.    
  21.     private static PrintStream out = System.out;
  22.     private BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  23.     private List<product> prod_info = new ArrayList<product>();
  24.     private static final String username = "manager";
  25.     private static final String password = "12345678";
  26.    
  27.     private static int reorder_quantity;
  28.    
  29.     public Manager() throws FileNotFoundException, ClassNotFoundException, IOException{
  30.        
  31.         if(Login.login(username, password)){
  32.             loadItemInfo.loaditemInfo((ArrayList<product>) prod_info, "Product_info.tmp");
  33.             managerMenu();
  34.            
  35.         }else
  36.             out.println("\nusername or password incorrect!");
  37.        
  38.         saveItemInfo.saveiteminfo(prod_info, "Product_info.tmp");
  39.     }
  40.    
  41.     /**
  42.      * Manager Menu
  43.      */
  44.     private void managerMenu() throws IOException, ClassNotFoundException{
  45.        
  46.         int selection;
  47.        
  48.         do{
  49.             out.println("1. Maintains unit-price, stock level, replenish-level");
  50.             out.println("2. Supplier details for all products");
  51.             out.println("3. Special discounts on products");
  52.             out.println("4. Generate sales report");
  53.             out.println("5. The most revenue product");
  54.             out.println("6. Exit to main menu");
  55.             out.println("Enter a number");
  56.            
  57.             selection = InputValidation.ValidateInt(bf.readLine());
  58.            
  59.             if (selection == 1){
  60.                 reorder_quantity = reorder_quant_imple();
  61.                 out.println("\nReorder quantity for all item is: " + reorder_quantity);
  62.                 out.println();
  63.                 Unit_Price_StockLevel();
  64.             }
  65.             else if (selection == 2){
  66.                 //Not implement yet
  67.             }
  68.             else if (selection == 3){
  69.                 ChangeDiscountStatus();
  70.             }
  71.             else if (selection == 4){
  72.                 //Bonus function will be implemented later
  73.                 PrintPNGReport();
  74.             }
  75.             else if (selection == 5){
  76.                 Mst_Revenue_Product();
  77.             }
  78.            
  79.            
  80.         }while(selection != 6);
  81.        
  82.     }
  83.  
  84.     /**
  85.      * Specify reorder quantity for all items
  86.      * This method is used the in first function
  87.      * of the Menu
  88.      */
  89.     private int reorder_quant_imple() throws IOException{
  90.        
  91.         int re_quantity = 50;
  92.        
  93.         out.println("*** Do you want to change reorder quantity?(y/n)");
  94.        
  95.         String s = bf.readLine();
  96.        
  97.         if(s.charAt(0) == 'y' || s.charAt(0) == 'Y'){
  98.             out.print("Please enter new quantity: ");
  99.             return InputValidation.ValidateInt(bf.readLine());
  100.         }
  101.         return re_quantity;
  102.     }
  103.    
  104.     /**
  105.      * First Menu implementation
  106.      */
  107.     private void Unit_Price_StockLevel() throws IOException{
  108.        
  109.         PrintList();
  110.         out.println("Please select a number to change info: ");
  111.         int select = InputValidation.ValidateInt(bf.readLine()) -1;
  112.        
  113.         float unit_Price;
  114.         int quantity;
  115.         @SuppressWarnings("unused")
  116.         int replenish_level;
  117.        
  118.         try{
  119.             product po = prod_info.get(select);
  120.            
  121.             if(po.getStockLevel() <= reorder_quantity){
  122.                 out.println("StockLevel is too low, reorder item procedure is commencing");
  123.                 quantity = reorder_quantity;
  124.             }
  125.            
  126.             out.println("    Item Info    ");
  127.             out.println("Name: " + po.getName() + " ID: " + po.getID() + " Unit-Price: " + po.getPrice()
  128.                 + " Quantity: " + po.getStockLevel());
  129.             out.println("Enter new unit price: ");
  130.             unit_Price = InputValidation.ValidateFloat(bf.readLine());
  131.            
  132.             out.println("Enter new StockLevel: ");
  133.             quantity = InputValidation.ValidateInt(bf.readLine());
  134.            
  135.             if(quantity < reorder_quantity){
  136.                 quantity = reorder_quantity;
  137.                 out.println("StockLevel is low, set to reorder quantity");
  138.             }
  139.            
  140.             out.println("Enter new Replenish Level: ");
  141.             replenish_level = InputValidation.ValidateInt(bf.readLine());
  142.            
  143.             po = new product(po.getID(), po.getName(), unit_Price, po.getWeight(), quantity,
  144.                     po.getDiscount(), po.getminitemforDiscount());
  145.             prod_info.set(select, po);
  146.            
  147.         }catch(IndexOutOfBoundsException ibe){
  148.             out.println("No. invalid!");
  149.         }
  150.        
  151.     }
  152.    
  153.     /**
  154.      * Third Menu implementation
  155.      */
  156.     private void ChangeDiscountStatus() throws IOException {
  157.         // TODO Auto-generated method stub
  158.         int i = 1;
  159.         for(product p : prod_info){
  160.             out.println(i + " name : "+p.getName() + " ID: " + p.getID() + " discount: " + (int)(p.getDiscount()*100)+"%" +
  161.                     " Min items quantity for discount : " + p.getminitemforDiscount());
  162.             i++;
  163.         }
  164.         out.println("Please select an item : ");
  165.         int select = InputValidation.ValidateInt(bf.readLine()) - 1;
  166.        
  167.         try{
  168.             product po = prod_info.get(select);
  169.             out.println("Please specify discount amount(%) : ");
  170.             float dis = InputValidation.ValidateFloat(bf.readLine());
  171.             if(dis > 1f)
  172.                 dis = dis/100f;
  173.             out.println("Discount : " + (int)(dis*100)+"%");
  174.             out.println("Please specify quantity for discount item : ");
  175.             int quan = InputValidation.ValidateInt(bf.readLine());
  176.            
  177.             po = new product(po.getID(), po.getName(), po.getPrice(), po.getWeight(), po.getStockLevel(),
  178.                     dis, quan);
  179.             prod_info.set(select, po);
  180.         }catch(IndexOutOfBoundsException ibe){
  181.             out.println("No. invalid!");
  182.         }
  183.        
  184.         Iterator<product> itr = prod_info.iterator();
  185.         while(itr.hasNext()){
  186.             product el = (product) itr.next();
  187.             out.println("name : "+el.getName() + " ID: " + el.getID() + " discount: " + el.getDiscount() +
  188.                     " Min items quantity for discount : " + el.getminitemforDiscount());
  189.         }
  190.        
  191.     }
  192.    
  193.     /**
  194.      * Fifth Menu implementation
  195.      */
  196.     private void Mst_Revenue_Product() throws FileNotFoundException, ClassNotFoundException, IOException {
  197.         // TODO Auto-generated method stub
  198.         List<transaction_info> t_i = new ArrayList<transaction_info>();
  199.         List<product> p_i = new ArrayList<product>();
  200.         p_i = prod_info;
  201.        
  202.         ArrayList<Integer> tmp = new ArrayList<Integer>(Collections.nCopies(p_i.size(), 0));
  203.         loadItemInfo.loadtransactionInfo((ArrayList<transaction_info>) t_i, "transaction_info.tmp");
  204.        
  205.         //Count All item Transaction quantity
  206.         for(transaction_info t : t_i){ 
  207.             for(Cart c : t.get_Cart()){
  208.                 int j = 0;
  209.                 for(product p : p_i){
  210.                     int amt_count = 0;
  211.                     if(p.getID().equals(c.getID()))
  212.                         amt_count += c.getQuantity();
  213.                     tmp.set(j, tmp.get(j) + amt_count);
  214.                     j++;
  215.                 }  
  216.             }
  217.         }
  218.        
  219.         int index = FindMaxIndex(tmp);
  220.         if(index == -1)
  221.             throw new IOException();
  222.        
  223.         out.println("######### Revenue Status #########");
  224.         out.println("*** Most revenue product : " + p_i.get(index).getName());
  225.         out.println("*** Product ID : " + p_i.get(index).getID());
  226.         out.println("*** Sales Amount : " + tmp.get(index));
  227.         out.println("##################################");
  228.     }
  229.    
  230.     /**
  231.      * Generate PNG file using Java.awt and Javax.imageIO GUI in another class
  232.      * @throws IOException
  233.      * @throws ClassNotFoundException
  234.      * @throws FileNotFoundException
  235.      */
  236.     private void PrintPNGReport() throws IOException, ClassNotFoundException {
  237.         // TODO Auto-generated method stub
  238.         List<String> report = new ArrayList<String>();
  239.        
  240.         ArrayList<transaction_info> trans_info = new ArrayList<transaction_info>();
  241.         loadItemInfo.loadtransactionInfo(trans_info, "transaction_info.tmp");
  242.        
  243.         report.add(new String("###### Report ######"));
  244.        
  245.         //Add new line
  246.         report.add(new String(""));
  247.        
  248.         int i = 1;
  249.         for(transaction_info t_i : trans_info){
  250.             report.add(new String("###### Transaction " + Integer.toString(i) + " ######"));
  251.             report.add(new String("Customer ID : " + t_i.get_customerid()));
  252.             report.add(new String("Card Number : " + t_i.get_CardNum()));
  253.             report.add(new String(""));
  254.             report.add(new String("###### Detail ######"));
  255.             report.add(new String(""));
  256.             for(Cart c : t_i.get_Cart()){
  257.                 report.add(new String("Item ID : " + c.getID()));
  258.                 report.add(new String("Quantity : " + c.getQuantity()));
  259.                 report.add(new String(""));
  260.             }
  261.             i++;
  262.         }
  263.         report.add(new String(""));
  264.         report.add(new String("###### End of Report ######"));
  265.        
  266.         out.println("Generating PNG file......");
  267.        
  268.         GenPNGReport.PNG_gen((ArrayList<String>) report);
  269.        
  270.         out.println("Generation is finished\n");
  271.     }
  272.    
  273.     /**
  274.      * This method is used for find most revenue product in transaction list
  275.      */
  276.     private int FindMaxIndex(List<Integer> al){
  277.         int index = -1;
  278.        
  279.         int Max = Collections.max(al);
  280.  
  281.         while(true){
  282.             if(al.contains(Max)){
  283.                 index = al.indexOf(Max);
  284.                 break;
  285.             }
  286.         }
  287.        
  288.         return index;
  289.     }
  290.    
  291.     private void PrintList(){
  292.         int i = 1;
  293.         for(product p : prod_info){
  294.             System.out.println(i + " ID: " + p.getID() + " name: " + p.getName() + " price: " +
  295.                     p.getPrice() + " quantity: " + p.getStockLevel());
  296.             i++;
  297.         }
  298.     }
  299. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement