Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package resources;
- import java.text.DecimalFormat;
- import java.text.ParseException;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.Scanner;
- import resources.Menu;
- public class Order {
- //this class contains payment function
- private Scanner scanner;
- private ArrayList<Item> itemList = new ArrayList<Item>();
- public double orderBill=0;
- static Menu menu;
- public Order(){
- }
- public void printInvoice(Staff staff) throws ParseException{
- DateCreated dateFormat = new DateCreated();
- DecimalFormat decformat = new DecimalFormat ("#.##");
- //print receipt pattern
- System.out.println();
- System.out.println("======================== RECEIPT ========================");
- System.out.println("Staff Name : " + staff.getStaffName() );
- System.out.println("Order ID : " );
- System.out.println("Date : " + dateFormat.getDateCreated());
- System.out.println("---------------------------------------------------------");
- //printing order list
- if(itemList.size() > 0){
- System.out.println("Menu Items : ");
- //looping printing item
- for(int i = 0; i < itemList.size(); i++ ){
- System.out.println(" " + (itemList.get(i)).getName() + " RM" + (itemList.get(i)).getPrice() + " " + (itemList.get(i)).getDesc() );
- }
- }
- calOrderBill(); //calculate order bill return order bill
- System.out.println("--------------------------------------------------------- ");
- System.out.println("TOTAL COST : RM " + decformat.format((orderBill)));
- System.out.println("============= Thank you! Please come again! =============\n");
- }
- //make order
- public void takeOrder(){
- menu = new Menu(); //create object
- Object object = menu.displayMenu(); //create dynamic object and display menu
- //store object value in itemList
- if(object!=null){
- if(object instanceof Item)
- itemList.add((Item)object);
- }
- }
- public double calOrderBill(){
- //looping for calculate item price
- for(Iterator<Item> input = itemList.iterator(); input.hasNext();){
- Item item = input.next();
- orderBill += Double.parseDouble(item.getPrice()); //ordelBill <- price
- }
- return orderBill; //return orderBill
- }
- public void removeOrder(){
- scanner = new Scanner(System.in);
- String input;
- //looping get item
- for(Iterator<Item> i = itemList.iterator(); i.hasNext();){
- Item item = i.next();
- System.out.println("Item: " + item.getName() + " " + "$"+ item.getPrice());
- }
- System.out.println("Enter itemID to remove from order, press 0 if there is no item to remove");
- input = scanner.nextLine();
- if(!input.equals(0)){
- for(Iterator<Item> i = itemList.iterator(); i.hasNext();){
- Item item = i.next();
- if(item.getItemID().equals(input)){
- i.remove();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment