Advertisement
Guest User

Untitled

a guest
May 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.19 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 Sale_staff;
  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 Sale_Staff {
  20.    
  21.     private static PrintStream out = System.out;
  22.     private BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  23.     private static final String username = "salestaff";
  24.     private static final String password = "12345678";
  25.     private List<transaction_info> trans_info = new ArrayList<transaction_info>();
  26.    
  27.     public Sale_Staff() throws FileNotFoundException, ClassNotFoundException, IOException{
  28.        
  29.         //Check Username & Password first
  30.         if(Login.login(username, password)){
  31.             loadItemInfo.loadtransactionInfo((ArrayList<transaction_info>) trans_info, "transaction_info.tmp");
  32.            
  33.             staffMenu();
  34.            
  35.             saveItemInfo.savetransactioninfo(trans_info, "transaction_info.tmp");
  36.            
  37.         }else
  38.             out.println("\nusername or password incorrect!");
  39.        
  40.     }
  41.    
  42.     /**
  43.      * Staff Menu contains 1. Remove items
  44.      *                     2. Cancel Transaction
  45.      */
  46.     private void staffMenu() throws IOException{
  47.        
  48.         for(int i =0;i < trans_info.size();i++){
  49.             for(int j=i+1;j < trans_info.size();j++){
  50.                 if(trans_info.get(i).get_customerid().equals(trans_info.get(j).get_customerid())){
  51.                     trans_info.get(i).get_Cart().addAll(trans_info.get(j).get_Cart());
  52.                     trans_info.remove(j);
  53.                     j = i;
  54.                 }
  55.             }
  56.         }
  57.        
  58.         int selection;
  59.        
  60.         do{
  61.             out.println("1. Remove item");
  62.             out.println("2. Cancel transaction");
  63.             out.println("3. Exit to main menu");
  64.             out.println("Enter a number");
  65.            
  66.             selection = InputValidation.ValidateInt(bf.readLine());
  67.            
  68.             if (selection == 1){
  69.                 PrintList();
  70.                 removeitem();
  71.             }
  72.             else if (selection == 2){
  73.                 PrintList();
  74.                 Cancellation();
  75.             }
  76.            
  77.            
  78.         }while(selection != 3);
  79.        
  80.        
  81.     }
  82.    
  83.     /**
  84.      * Remove items implementation
  85.      */
  86.     private void removeitem() throws IOException{
  87.        
  88.         out.println("Select transaction number: ");
  89.         int select = InputValidation.ValidateInt(bf.readLine()) - 1;
  90.        
  91.         try{
  92.             transaction_info ti = trans_info.get(select);
  93.             out.println("\n     Transaction Detail     \n");
  94.             out.println("CustomerID: " + ti.get_customerid() + " Card: " + ti.get_CardNum() +
  95.                     " Total Price: " + ti.get_totalPrice());
  96.             out.println();
  97.            
  98.             List<Cart> cart = ti.get_Cart();
  99.            
  100.             if (cart.size() > 0){
  101.                 int j = 1;
  102.                 for(int i = 0;i < cart.size();i++){
  103.                     out.println(j +" name : "+cart.get(i).getName() + " ID: " + cart.get(i).getID() + " price: " + cart.get(i).getPrice()
  104.                     + " quantity: " + cart.get(i).getQuantity());
  105.                     j++;
  106.                 }
  107.                
  108.                 out.println("Select No. item to remove: ");
  109.                 int sel = InputValidation.ValidateInt(bf.readLine()) - 1;
  110.                 try{
  111.                     cart.remove(sel);
  112.                     out.println("Item has been deleted!!!");
  113.                     trans_info.set(select, new transaction_info(ti.get_customerid(), ti.get_CardNum(), cart));
  114.                 }catch(IndexOutOfBoundsException ibe){
  115.                     out.println("No. invalid!");
  116.                 }
  117.             }else
  118.                 out.println("### NO ITEM IN LIST ###\n");
  119.            
  120.         }catch(IndexOutOfBoundsException iob){
  121.             out.println("Number invalid!");
  122.         }
  123.        
  124.     }
  125.    
  126.     /**
  127.      * Cancel transactions implementation
  128.      */
  129.     private void Cancellation() throws IOException{
  130.        
  131.         out.println("Select transaction number: ");
  132.         int select = InputValidation.ValidateInt(bf.readLine()) - 1;
  133.        
  134.         try{
  135.            
  136.             transaction_info ti = trans_info.remove(select);
  137.             out.println(ti.get_customerid() + "'s transaction has been cancelled!\n");
  138.            
  139.         }catch(IndexOutOfBoundsException iob){
  140.             out.println("Number invalid!");
  141.         }
  142.        
  143.     }
  144.    
  145.     private void PrintList(){
  146.         int i = 1;
  147.         for(transaction_info t : trans_info){
  148.             out.println(i + " CustomerID: " + t.get_customerid() + " Card: " + t.get_CardNum() +
  149.                     " Total Price: " + t.get_totalPrice());
  150.             out.println("\n     Cart Detail     \n");
  151.             for(Cart c : t.get_Cart())
  152.                 if(c != null)
  153.                     out.println("name : "+c.getName() + " ID: " + c.getID() + " price: " + c.getPrice()
  154.                     + " quantity: " + c.getQuantity());
  155.             out.println();
  156.             i++;
  157.         }
  158.        
  159.     }
  160.    
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement