Stage 1
Implement and test class Clock. This will be a basic class in the simulation which will be used to store the time for the simulation as a whole, as well as the time customers join queues, the time they spend at the counter, and the time they leave.  Clock contains three integer instance variables to store hours minutes and seconds.  The operations are given in the table below.  这中间的问题:
public transformers
 
void addSeconds(int ss)    要求     adds ss seconds to target
void subtract(Clock other)             Subtracts other from target
void add(Clock other)             Adds other to target

解决方案 »

  1.   

    这个是clock.java
    public class Clock
    {
                private int hour, min, sec;
                
                // constructors
                public Clock(int hh, int mm, int ss)
                {
                    hour = hh;
                    min = mm;
                    sec = ss;
                }
                 
                public Clock(Clock other)
                {
                    hour = other.hour;
                    min = other.min;
                    sec = other.sec;
                    
                }
                
                 
                public Clock()
                {
                    hour = 0;
                    min = 0;
                    sec = 0;
                }
                
                public Clock(long seconds)
                {
                    hour = (int) seconds / 3600;
                    min = (int) seconds %3600 /60;
                    sec = (int) seconds % 60;
                }
                // transformers
                
                public void copy(Clock other)
                {
                    hour = other.hour;
                    min = other.min;
                    sec = other.sec;
                    
                }
                public void add(Clock other)
                { int totalsec;
                    totalsec = other.hour*3600 + other.min*60 + other.sec + hour*3600 + min*60 + sec;
                    hour = (int) seconds / 3600;
                    min = (int) seconds %3600 /60;
                    sec = (int) seconds % 60;
                }
                
                public void subtract(Clock other)
                {
                    int totalsec;
                    totalsec = hour*3600 + min*60 + sec - (other.hour*3600 + other.min*60 + other.sec);
                    hour = (int) seconds / 3600;
                    min = (int) seconds %3600 /60;
                    sec = (int) seconds % 60;
                }
                public void addSeconds(int ss)
                {
                    int totalsec;
                    totalsec = hour*3600 + min*60 + sec +ss;
                    hour = (int) seconds / 3600;
                    min = (int) seconds %3600 /60;
                    sec = (int) seconds % 60;
                }
                    
                //accessors
                public boolean isLater(Clock other)
                {
                   if (hour > other.hour)
                   return true;
                   else if (min > other.min)
                   return true;
                   else if (sec > other.sec)
                   return true;
                   else return false;
                }
                
                public boolean equals(Clock other)
                {
                 
                     return hour == other.hour && min == other.min 
                            && sec == other.sec;
                     
                  
                }
                
                public long asSeconds()
                {
                    return hour * 3600 + min * 60 + sec;
                    
                }
                
                public String toString()
                {
                    return "hour:"+ hour + "min:" + min + "sec" + sec;
                    
                }
     }
      

  2.   

    Stage 2. 
    Implement and test class Customer.  This class stores information on a Customer that includes the time the customer joins a queue, the finish time and the service time (time spent at desk with cashier). It also stores information as to method of payment and number of items in the basket.You should write a Controller which creates two or more customers, and tests each of the accessors and transformers.
    请问controller要如何写,这是customer.java
    public class Customer
    {
               private static int count;
               
               public static int getCount()
               {
                   return count;
                }
               
               private Clock joinedTime, completionTime, serviceTime;         
               private int items;   
               private int payMethod;
               
               
               public static final int CHEQUE = 1;
               public static final int CASH = 2;
               public static final int CARD = 3;
                
                //constructors
               public Customer()
               {
                   joinedTime = new Clock();
                   completionTime =  new Clock();
                   serviceTime = new Clock();         
                   items   =   0;   
                   payMethod =  CASH;
                   count ++;
                }
                
               public Customer(Clock start, int payBy, int size)
               {
                   this();
                   joinedTime = start;
                   items   =   size;   
                   payMethod = payBy;
                }
                
                //transformers
                public void setCompletionTime(Clock time)
                {
                    completionTime = new Clock();
                }
                
                public void setServiceTime(Clock time)
                {
                    serviceTime = new Clock();
                }
                
                public void setPayMethod(int method)
                {
                    payMethod = 0;
                }
                
                public void setItemSize(int size)
                {
                    size = 0;
                }
                
                //accessors
                public String toString()
                {
                     return " ";
                }
                
                public String payMethodAsString()
                {
                    switch (payMethod)
                    {
                   case 1 :  return "CHEQUE";
        
                   case 2 :  return "CASH";

                           case 3 :  return  "CARD";
          

                      default : return " ";
                 }  // end of switch
                      
                }
                
                public Clock getJoinedTime()
                {
                    return new Clock();
                }
                
                public Clock getCompletionTime()
                {
                    return new Clock();
                }
                
                public Clock getServiceTime()
                {
                     return new Clock();
                }
                
                public int getPayMethod()
                {
                    return 0;
                }
                
                public int getItems()
                {
                    return 0;
                }}
      

  3.   

    Stage 3
    Develop and test class Checkout
    This class will be used to model each checkout and associated queue in the simulation. It should be implemented at this stage using a private array.
    下面是checkout.java..空白处要求:
    private attribute       Customer[]        要求 array of Customer
    transformers public void add(Customer cust)   要求Adds cust to array; increments custCount
    public class Checkout
    {
               private static int count;
               
               public static int getCount()
               {
                   return count;
                }        private int serviceTime;         
               private int indexNumber;   
               private int custCount;

               private Customer[]
                  
               
               //constructors
               public Checkout(int servicetime)
           {
            serviceTime = new Clock();
           }        //accessors
                public String toString()
                {
                     return " ";
                }
                
                public int getServiceTime()
                {
                    return new Clock();
                      
                }
                
                public int getCustCount()
                {
                    return count;
                }
                
                public int getNumber()
                {
                    return 0;
                }
                
                //tranformers
               
            public void add(Customer cust)
                {
                }
       
       
    }