intermediate/Cashier

From ggc

Jump to: navigation, search

001 package intermediate;
002 
003 import java.util.*;
004 
005 public class Cashier
006 {
007   /**items per second*/
008   private double rateOfChecking;
009 
010   /**fast lane is for 15 items or less*/
011   private boolean fastLane;
012 
013   private double nextAvailableTime;
014 
015   private Queue<Customer> queue;
016 
017   private int id;
018   private static int cashiersCreated=1;
019 
020   public Cashier()
021   {
022     rateOfChecking=0.5;
023     fastLane=false;
024     queue=new LinkedList<Customer>();
025     id=cashiersCreated;
026     cashiersCreated++;
027   }
028 
029   public boolean hasCustomer(Customer customer)
030   {
031     for(Customer c: queue)
032     {
033       if(c==customerreturn true;
034     }
035     return false;
036   }
037 
038   public void joinLane(Customer customer)
039   {
040     queue.add(customer);
041   }
042 
043   public boolean canJoin(Customer customer)
044   {
045     if(fastLane)
046       return customer.getItems()<=15;
047     return true;
048   }
049 
050   public void scanNextCustomer(double startTime)
051   {
052     if(queue.isEmpty())
053       return;
054     if(startTime<nextAvailableTime)
055       return;
056     Customer customer=queue.remove();
057     int items=customer.getItems();
058     double timeToProcess=items/rateOfChecking;
059     customer.setExitLaneTime(startTime+timeToProcess);
060     nextAvailableTime=startTime+timeToProcess;
061   }
062 
063   public double getNextAvailableTime()
064   {
065     return nextAvailableTime;
066   }
067 
068   public int getNumberInQueue()
069   {
070     return queue.size();
071   }
072 
073   public String toString()
074   {
075     String text="Cashier#"+id+"[";
076     for(Customer c: queue)
077       text+=c.toString()+", ";
078     text+="]";
079     return text;
080   }
081 
082   public static void main(String[] args)
083   {
084     System.out.println("Cashier comes on duty.");
085     Cashier c=new Cashier();
086     System.out.println(c);
087     Customer cust=new Customer();
088     c.joinLane(cust);
089     System.out.println("A customer joins the lane.");
090     System.out.println(c);
091     Customer cust2=new Customer();
092     c.joinLane(cust2);
093     System.out.println("A customer joins the lane.");
094     System.out.println(c);
095     Customer cust3=new Customer();
096     System.out.println("A customer joins the lane.");
097     c.joinLane(cust3);
098     System.out.println(c);
099     System.out.println("A customer is scanned.");
100     c.scanNextCustomer(5);
101     System.out.println(c);
102   }
103 }

Compiler Errors:
----------
1. ERROR in intermediate/Cashier.java (at line 46)
	return customer.getItems()<=15;
	                ^^^^^^^^
The method getItems() is undefined for the type Customer
----------
2. ERROR in intermediate/Cashier.java (at line 57)
	int items=customer.getItems();
	                   ^^^^^^^^
The method setExitLaneTime(double) is undefined for the type Customer
----------
3 problems (3 errors)

Download/View intermediate/Cashier.java




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter