Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.text.ParseException;
- import resources.Staff;
- import resources.SystemData;
- import resources.Data;
- import resources.DateCreated;
- import resources.Order;
- public class SalesApp {
- //instance variables are static to class access it
- static Scanner sc = new Scanner(System.in);
- //linking variables
- static Data data;
- static Staff staff;
- static SystemData SystemData;
- static Order Order;
- public static void main(String[] args)throws ParseException, IOException {
- // Programmer: Syid (keyboardcrash)
- // create obj
- staff = new Staff();
- Order = new Order();
- SystemData = new SystemData();
- boolean login; //declare boolean
- //start program
- login = setStaffID(); //invoke method to get the boolean value
- if(login) //if login is true then do below
- {
- int choice; //choose is default value for switch case
- do { //creating sentinel value
- //print menu
- System.out.println("Please choose number: ");
- System.out.println("1: Payment");
- System.out.println("2: View items");
- System.out.println("3: Info");
- System.out.println("4: Exit system");
- choice = sc.nextInt(); //get choose value
- switch(choice){ //check choose value
- case 1: //for payment
- int input_1;//
- do{
- //print menu
- System.out.print("\n");
- System.out.println("1: Order");
- System.out.println("2: Print Invoice");
- System.out.println("3: Remove order");
- System.out.println("4: Back to the menu");
- input_1 = sc.nextInt(); //get input_1 value
- //sc.nextLine();
- switch(input_1){
- case 1:
- Order.takeOrder(); //display menu
- //System.out.println("TEST : RM " + Order.orderBill);
- break;
- case 2:
- Order.orderBill = 0; //reset orderBill memory value
- Order.printInvoice(staff);
- break;
- case 3: Order.removeOrder(); //order remove
- case 4:
- input_1=4; //back to menu
- System.out.print("\n");
- }
- }while(input_1 < 4); //maintain in this page if do something
- break;
- case 2: SystemData.viewItem(); break; //view itemlist
- case 3: staff.ViewStaff(staff.getStaffID() + "\n"); break; //view staff info
- case 4: System.out.println("System terminated"); break;
- }
- }while (choice<4); //if choice value is < 4, then looping
- }
- else
- {
- main(args); //return main class
- }
- }
- //boolean method
- public static boolean setStaffID() throws FileNotFoundException{
- boolean result = false; //false as default boolean, if true = can access login
- DateCreated date = new DateCreated(); //create date obj
- data = new Data(); //create data obj
- ArrayList<Staff> staffList = data.getStaffID(); //create arraylist stafflist invoke arraylist method to get info file
- System.out.print("Please enter Staff ID: ");
- staff.setStaffID(sc.next()); //staff id value
- System.out.print("Password: ");
- staff.setStaffPWD(sc.next()); //pwd value
- System.out.print("\n");
- for(Staff input: staffList){ //looping checking in stafflist
- if(staff.getStaffID().equals(input.getStaffID()) && staff.getStaffPWD().equals(input.getStaffPWD())){ //check if match id entered
- staff = input; //staff <- staff information
- result = true; //boolean become true
- }
- }
- if(result){ //boolean cases selection print out something
- System.out.println("Staff ID accepted, Welcome " + staff.getStaffName() + "!");
- System.out.println("Login at " + date.getDateCreated() + "\n");
- //true
- }else{
- System.out.println("Invalid StaffID! \n");
- //false
- }
- return result; //return boolean result
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment