当前位置:编程学习 > JAVA >>

新手求救,不知为何老提示错误

class Queue
 {
     private int maxSize;
     private long[] queueArray;
     private int front;
     private int rear;
     private int nItems;
     //------------------------------------------
     public Queue(int s)
     {
         maxSize = s;
         queueArray = new long [maxSize];
         front = 0;
         rear =-1;
         nItems = 0;
        }
        //-------------------------------------
        public void  insert (long j)
        { 
            if(!isFull())
              {
                if (rear==maxSize-1)
                    rear =-1;
                queueArray[++rear] = j;
                nItems++;
              }
        }
        //---------------------------------------------------
        public long remove()
        {
            if(front ==maxSize)
               front =0;
            long temp = queueArray[front++]; 
            nItems--;
            return temp;
        }
        //--------------------------------------------------
        public long peekfront ()
        {
            return queueArray[front];
        }
        //-----------------------------------------------
        public boolean isEmpty()
        {
            return (nItems==0);
        }
        //-------------------------------------------------
        public boolean isFull()
        {
            return (nItems==maxSize);
        }
        //----------------------------------------------------
        public int size()
        {
            return nItems;
        }
        //--------------------------------------------------------------
        public void display()
        {
            if(front<=rear)
               for (int i=(++front);i<=rear;i++)
                  System.out.print(queueArray[i]+"  ");  
            else
               for(int i=(++front);i<maxSize;i++)
                System.out.print(queueArray[i]+"  ");
               for(int i=0;i<=rear;i++)
                 System.out.print(queueArray[i]+"  ");
           System.out.println("");
                }
//----------------------------------------
     public long totalTime()
     {
         int n = 0;
         if(rear>=front)
             for(int i=front;i<=rear;i++)
                 n+=queueArray[i];
         else
             for(int i=front;i<maxSize;i++)
                 n+=queueArray[i];
             for(int i=0;i<=rear;i++)
                  n+=queueArray[i];
         return n;
        }
    }
    ///////////////////////////////////////////////////////////////

class creatQueue
 {
     private int n ;
     private int num;
     private int maxSize;
     public Queue[] a;
     public Queue[] b;
     public Queue[] c;
 //------------------------------------
   public  creatQueue(int x)
   {
       maxSize = x;
       Queue a =new Queue(maxSize);
       Queue b = new Queue(maxSize);
       Queue c = new Queue(maxSize);
    }
    //--------------------------------------------
    public long bestQueue()
    {
       if(a.totalTime()<=b.toatalTime())
          if(c.totalTime()<=a.totalTime())
          return c;
          else 
          return a;
       else if(c.totalTime()<=b.totalTime())
          return c;
       else
          return b;    
        }
    //--------------------------------------------
    public  void insertQueue(int y)
    {
        n = y;
        if(a.isEmpty())
          a.insert(n);
        else if(b.isEmpty())
          b.insert(n);
        else if(c.isEmpty())
          c.insert(n);
        else
           bestQueue().insert(n);
        }
//----------------------------------------
  public void  deleteQueue(int v)
  {
     int i=num;
     for(int i=15;i>=0;i--)
      {
          int p,q,r;
          p = a.peekfront();
          q = b.peekfront();
          r = c.peekfront();
          System.out.print("距离结账结束还有:"+p+"分钟!");
          a.display();
          System.out.print("距离结账结束还有:"+q+"分钟!");
          b.display();
          System.out.print("距离结账结束还有:"+r+"分钟!");
          c.display();
          p--;
          q--;
          r--;
          if(p==0)
             a.remove();
          if(q==0)
             b.remove();
          if(r==0)
            c.remove();
        }
    }
}
///////////////////////////////////////
class QueueArr
 {
   public static void main (String[]agrs)
   {
       creatQueueArr(10);
       for(int i=0;i<12;i++)
       {
           int n =Math.random();
           insertQueue(n);
        } 
    }
}
        --------------------编程问答-------------------- public Queue[] a;
     public Queue[] b;
     public Queue[] c;

lz,a、b、c是数组啊,使用怎么也得加个下标吧。。

 public long bestQueue()
    {
       if(a.totalTime()<=b.toatalTime())//a是数组名,而lz的意思是要用Queue类中定义的totalTime,是么?
          if(c.totalTime()<=a.totalTime())
          return c;
          else 
          return a;
       else if(c.totalTime()<=b.totalTime())
          return c;
       else
          return b;    
        }

后面还有,应该也都是这个情况。。 --------------------编程问答-------------------- 但加了之后似乎还是不行;本来的是意思是使用totalTime方法来计算其中一数组的各项值之和n,利用a.totalTime来调用n;
补充:Java ,  Java SE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,