NaoDesu

SalesApp

Feb 20th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.76 KB | None | 0 0
  1. package main;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.Scanner;
  7. import java.text.ParseException;
  8.  
  9. import resources.Staff;
  10. import resources.SystemData;
  11. import resources.Data;
  12. import resources.DateCreated;
  13. import resources.Order;
  14.  
  15. public class SalesApp {
  16.     //instance variables are static to class access it
  17.     static Scanner sc = new Scanner(System.in);
  18.     //linking variables
  19.     static Data data;
  20.     static Staff staff;
  21.     static SystemData SystemData;
  22.     static Order Order;
  23.    
  24.     public static void main(String[] args)throws ParseException, IOException {
  25.         // Programmer: Syid (keyboardcrash)
  26.         // create obj
  27.         staff = new Staff();  
  28.         Order = new Order();
  29.         SystemData = new SystemData();
  30.  
  31.         boolean login;        //declare boolean
  32.         //start program
  33.         login = setStaffID(); //invoke method to get the boolean value
  34.        
  35.         if(login) //if login is true then do below
  36.         {
  37.         int choice; //choose is default value for switch case
  38.        
  39.         do { //creating sentinel value
  40.             //print menu
  41.             System.out.println("Please choose number: ");
  42.             System.out.println("1: Payment");
  43.             System.out.println("2: View items");
  44.             System.out.println("3: Info");
  45.             System.out.println("4: Exit system");
  46.             choice = sc.nextInt(); //get choose value
  47.            
  48.             switch(choice){ //check choose value
  49.             case 1: //for payment
  50.                 int input_1;//
  51.            
  52.                 do{
  53.                     //print menu
  54.                     System.out.print("\n");
  55.                     System.out.println("1: Order");
  56.                     System.out.println("2: Print Invoice");
  57.                     System.out.println("3: Remove order");
  58.                     System.out.println("4: Back to the menu");
  59.                     input_1 = sc.nextInt(); //get input_1 value
  60.                    
  61.                     //sc.nextLine();
  62.                     switch(input_1){
  63.                     case 1:
  64.                         Order.takeOrder(); //display menu
  65.                         //System.out.println("TEST : RM " + Order.orderBill);
  66.                         break;
  67.                     case 2:
  68.                         Order.orderBill = 0; //reset orderBill memory value
  69.                         Order.printInvoice(staff);
  70.                        
  71.                         break;
  72.                        
  73.                     case 3: Order.removeOrder(); //order remove
  74.                     case 4:
  75.                         input_1=4; //back to menu
  76.                         System.out.print("\n");
  77.                     }
  78.                 }while(input_1 < 4); //maintain in this page if do something
  79.                 break;
  80.                
  81.                
  82.             case 2: SystemData.viewItem(); break; //view itemlist
  83.            
  84.             case 3: staff.ViewStaff(staff.getStaffID() + "\n"); break; //view staff info
  85.            
  86.             case 4: System.out.println("System terminated"); break;
  87.             }
  88.            
  89.         }while (choice<4); //if choice value is < 4, then looping
  90.     }
  91.         else
  92.         {
  93.             main(args); //return main class
  94.         }
  95.     }
  96.  
  97.     //boolean method
  98.     public static boolean setStaffID() throws FileNotFoundException{
  99.         boolean result = false; //false as default boolean, if true = can access login
  100.         DateCreated date = new DateCreated(); //create date obj
  101.         data = new Data(); //create data obj
  102.         ArrayList<Staff> staffList = data.getStaffID();  //create arraylist stafflist invoke arraylist method to get info file
  103.        
  104.         System.out.print("Please enter Staff ID: ");
  105.         staff.setStaffID(sc.next()); //staff id value
  106.        
  107.         System.out.print("Password: ");
  108.         staff.setStaffPWD(sc.next()); //pwd value
  109.         System.out.print("\n");
  110.        
  111.         for(Staff input: staffList){ //looping checking in stafflist
  112.             if(staff.getStaffID().equals(input.getStaffID()) && staff.getStaffPWD().equals(input.getStaffPWD())){ //check if match id entered
  113.                 staff = input; //staff <- staff information
  114.                 result = true; //boolean become true
  115.             }
  116.         }
  117.         if(result){ //boolean cases selection print out something
  118.             System.out.println("Staff ID accepted, Welcome " + staff.getStaffName() + "!");
  119.             System.out.println("Login at " + date.getDateCreated() + "\n");
  120.             //true
  121.         }else{
  122.             System.out.println("Invalid StaffID! \n");
  123.             //false
  124.         }
  125.         return result; //return boolean result
  126.     }
  127.    
  128. }
Advertisement
Add Comment
Please, Sign In to add comment