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) //这里无法complie..要求加other到target
            { 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) //这里无法complie..要求减other到target
            {
                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)//这里无法complie..要求加ss seconds到target
            {
                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;
                
            }
 }

解决方案 »

  1.   

    public class Checkout
    {
               private static int count;
               
               public static int getCount()
               {
                   return count;
                }        private int serviceTime;         
                    private int indexNumber;   
                    private int custCount;

                    private Customer[]//这里要写一个array of 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)//要添加cust到array,增加custCount
                {
                    
                }
       
       
    }
      

  2.   

    另外请问如何写一个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;
                }}