队列的Java数组只打印出print方法中for循环中的最后一个元素

时间:2017-05-01 00:53:54

标签: java arrays methods printing queue

我花了几个小时研究这个,甚至让我的教授看看这个,它似乎只打印出for循环中的最后一个元素。它似乎允许我添加数据结构信息并初始化数组队列,但它只打印出最后一个元素。这是足以帮助解决问题的代码。

static  int MAX;
static final int amount =  6;
static boolean [] openflag;
static queue [] Clinic; 
static String [] Doctor;
final static String HEADING = "The clinic moniter of Dylan Rychlik";

public static void Listpaitents( ) {
    Paitent[] array;
    int queuechoice;

    JOptionPane.showMessageDialog(null, "Which doctor would you like to 
print?");
    String InputString = JOptionPane.showInputDialog(null,Doctor, HEADING, 
    JOptionPane.QUESTION_MESSAGE); 

    queuechoice = Integer.parseInt(InputString);

    if (openflag[queuechoice -1 ] == false){
        JOptionPane.showMessageDialog(null, "Sorry, that doctor is not aviable");
    }
    else {
        //Paitent[] array = null; 
        int limit;
        limit = Clinic[queuechoice -1 ].getSize();
        array = Clinic[queuechoice  -1 ].toArray();

        System.out.println(array[0]);
        System.out.println(array[1].Print());
        System.out.println(array[2].Print());

        //int size = Clinic[queuechoice -1].getSize();
        //System.out.println(limit);
        int x; String out = " Members of the list are: \n";

        // boolean exit = false;
        for(x = 0; x < limit; x++) {
            out += array[x].Print() + "\n";
            //System.out.println(out);
            // System.out.println(Clinic[queuechoice].toString() + "\n");
        }
        System.out.println(limit);
        JOptionPane.showMessageDialog(null,out);
    }
}

这是队列clas中的array()方法

 public Paitent[] toArray() {
     int x;
     Paitent[] Array = new Paitent[Length];
     queuenode Current = rear;

     for (x = 1; ((Current != null) && (x <= Length));x++) {
         Array[x-1] = new Paitent();
         Array[x-1].update(Current.info);
         Current = Current.next; 
         //  System.out.println( Array[x-1].Print());
     }
     //System.out.println( Array[x-1].Print());
     return Array;
 }

最后这里是打印方法

public String Print() {
    String outputString;
    outputString = "Paitent: " + "-" + name + "\n" + " Telephone number 
    telephone + " ID " + ID;
    return outputString; 
}

非常感谢您提供的任何帮助。我真的花了几个小时来分析代码来提出解决方案。这是一个庞大的计划。

0 个答案:

没有答案