NaoDesu

Order

Feb 20th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.86 KB | None | 0 0
  1. package resources;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.text.ParseException;
  5. import java.util.ArrayList;
  6. import java.util.Iterator;
  7. import java.util.Scanner;
  8.  
  9. import resources.Menu;
  10.  
  11. public class Order {
  12.     //this class contains payment function
  13.     private Scanner scanner;
  14.     private ArrayList<Item> itemList = new ArrayList<Item>();
  15.     public double orderBill=0;
  16.     static Menu menu;
  17.  
  18.     public Order(){
  19.        
  20.     }
  21.        
  22.     public void printInvoice(Staff staff) throws ParseException{
  23.         DateCreated dateFormat = new DateCreated();
  24.         DecimalFormat decformat = new DecimalFormat ("#.##");
  25.        
  26.         //print receipt pattern
  27.         System.out.println();
  28.         System.out.println("======================== RECEIPT ========================");
  29.         System.out.println("Staff Name : " + staff.getStaffName() );
  30.         System.out.println("Order ID : " );
  31.         System.out.println("Date : " + dateFormat.getDateCreated());
  32.         System.out.println("---------------------------------------------------------");
  33.        
  34.         //printing order list
  35.         if(itemList.size() > 0){
  36.             System.out.println("Menu Items : ");
  37.            
  38.             //looping printing item
  39.             for(int i = 0; i < itemList.size(); i++ ){
  40.                 System.out.println(" " + (itemList.get(i)).getName() + "    RM" + (itemList.get(i)).getPrice() + "    " + (itemList.get(i)).getDesc() );
  41.                 }
  42.             }
  43.            
  44.             calOrderBill(); //calculate order bill return order bill
  45.  
  46.             System.out.println("--------------------------------------------------------- ");
  47.             System.out.println("TOTAL COST : RM " + decformat.format((orderBill)));
  48.             System.out.println("============= Thank you! Please come again! =============\n");
  49.            
  50.            
  51.             }
  52.        
  53.         //make order
  54.         public void takeOrder(){
  55.             menu = new Menu(); //create object
  56.             Object object = menu.displayMenu(); //create dynamic object and display menu
  57.             //store object value in itemList
  58.             if(object!=null){
  59.                 if(object instanceof Item)
  60.                     itemList.add((Item)object);
  61.             }      
  62.         }
  63.        
  64.         public double calOrderBill(){
  65.            
  66.             //looping for calculate item price
  67.             for(Iterator<Item> input = itemList.iterator(); input.hasNext();){
  68.                 Item item = input.next();
  69.                 orderBill += Double.parseDouble(item.getPrice()); //ordelBill <- price
  70.             }
  71.             return orderBill; //return orderBill
  72.         }
  73.        
  74.         public void removeOrder(){
  75.             scanner = new Scanner(System.in);
  76.             String input;
  77.            
  78.             //looping get item
  79.             for(Iterator<Item> i = itemList.iterator(); i.hasNext();){
  80.                 Item item = i.next();
  81.                 System.out.println("Item: " + item.getName() + " " + "$"+ item.getPrice());
  82.             }
  83.            
  84.             System.out.println("Enter itemID to remove from order, press 0 if there is no item to remove");
  85.             input = scanner.nextLine();
  86.            
  87.             if(!input.equals(0)){
  88.                 for(Iterator<Item> i = itemList.iterator(); i.hasNext();){
  89.                     Item item = i.next();
  90.                     if(item.getItemID().equals(input)){
  91.                         i.remove();
  92.                     }
  93.                 }
  94.             }
  95.         }  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment