在第15行和第18行找不到符号错误

时间:2016-10-09 08:36:36

标签: java

我无法修复我的代码。它总是说“找不到符号”错误。我试图寻找一些解决方案,但仍然无效。

import java.util.*;

public class NPP{

    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);

        int numOfJobs;
        float waitingTimeAve = 0, turnaroundTimeAve = 0;

        System.out.println("Enter number of jobs : ");
        numOfJobs = scan.nextInt();

        Job[] job = new Job[numOfJobs];        // Line 15

        for(int i = 0; i < numOfJobs; i++ ){
            job[i] = new Job();                // Line 18

            System.out.println("For job " + (i+1));
            System.out.print("Enter arrival time: ");
            job[i].setArrivalTime(scan.nextInt());
            System.out.print("Enter burst time: ");
            job[i].setBurstTime(scan.nextInt());
            System.out.print("Enter priority: ");   
            job[i].setPriority(scan.nextInt());
            System.out.println();   
        }

        System.out.println("Type go.");
        scan.next();

        int jobNum = 0, jobAt = 1, jobBt = 2, jobPrio = 3;
        int currentTime;
        int [][]timeline = new int[numOfJobs][4];

1 个答案:

答案 0 :(得分:-1)

import java.util.*;

public class NPP{

    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);

        int numOfJobs;
        float waitingTimeAve = 0, turnaroundTimeAve = 0;

        System.out.println("Enter number of jobs : ");
        numOfJobs = scan.nextInt();

        Job[] job = new Job[numOfJobs]; //LINE15

        for(int i = 0; i < numOfJobs; i++ ){
            job[i] = new Job(); //LINE18

            System.out.println("For job " + (i+1));
            System.out.print("Enter arrival time: ");
            job[i].setArrivalTime(scan.nextInt());
            System.out.print("Enter burst time: ");
            job[i].setBurstTime(scan.nextInt());
            System.out.print("Enter priority: ");   
            job[i].setPriority(scan.nextInt());
            System.out.println();   
        }

        System.out.println("Type go.");
        scan.next();

        int jobNum = 0, jobAt = 1, jobBt = 2, jobPrio = 3;
        int currentTime;
        int [][]timeline = new int[numOfJobs][4];

        for(int i = 0; i < numOfJobs; i ++){
            timeline[i][jobNum] = i;                            
            timeline[i][jobAt] = job[i].getArrivalTime();       
            timeline[i][jobBt] = job[i].getBurstTime();
            timeline[i][jobPrio] = job[i].getPriority();
        }

        Arrays.sort(timeline, new Comparator<int[]>(){
            public int compare(int[] o1, int[] o2) {
                return Integer.compare(o1[jobAt], o2[jobAt]);
            }
        });

        currentTime = timeline[0][jobAt];
        int [][]ganttchart = new int [100][2];
        int g = 0;

        for(int i = 0; i < numOfJobs; i++){ 
            int n = 0;
            int temp = i;
            if(timeline[i][jobAt] > currentTime){
                int idle =   timeline[i][jobAt] - currentTime;
                currentTime += idle;
            }
            while(timeline[i][jobAt] <= currentTime){
                n++;
                i++;
                if(i == numOfJobs){
                    break;
                }
            }

            i = temp;

            if(n > 1){
                for(int j = i; j < n+i; j++){
                    for(int k = j; k < n+i; k++){
                        if(timeline[j][jobPrio] > timeline[k][jobPrio]){
                            int temp1 = timeline[j][jobNum];
                            int temp2 = timeline[j][jobAt];
                            int temp3 = timeline[j][jobBt];
                            int temp4 = timeline[j][jobPrio];

                            timeline[j][jobNum] =  timeline[k][jobNum];
                            timeline[j][jobAt] = timeline[k][jobAt];
                            timeline[j][jobBt] = timeline[k][jobBt];
                            timeline[j][jobPrio] = timeline[k][jobPrio];

                            timeline[k][jobNum] = temp1;
                            timeline[k][jobAt] = temp2;
                            timeline[k][jobBt] = temp3;
                            timeline[k][jobPrio] = temp4;
                        }
                    }   
                }
            }

            int temp4 = timeline[i][jobNum];
            currentTime += job[temp4].getBurstTime();
            job[temp4].setEndTime(currentTime);
            ganttchart[g][0] = timeline[i][jobNum];
            ganttchart[g][1] = currentTime;
            g++;
        }

        for(int i = 0; i < numOfJobs; i++){
            int wt, tt;
            tt = job[i].getEndTime() - job[i].getArrivalTime();
            job[i].setTurnaroundTime(tt);
            turnaroundTimeAve +=tt;

            wt = job[i].getTurnaroundTime() - job[i].getBurstTime();
            job[i].setWaitingTime(wt);
            waitingTimeAve+=wt;
        }

        turnaroundTimeAve = turnaroundTimeAve/numOfJobs; 
        waitingTimeAve = waitingTimeAve/numOfJobs;

        for(int i = 0; i < numOfJobs; i++){
            System.out.println("Job " + (i+1));
            System.out.println("End time is " + job[i].getEndTime());
            System.out.println("Turnaround time is " + job[i].getTurnaroundTime());
            System.out.println("Waiting time is " + job[i].getWatingTime());
            System.out.println();
        }

        System.out.println("Turnaround time average is " + turnaroundTimeAve);
        System.out.println("Waiting time average is " + waitingTimeAve);
        System.out.println("Gantt Chart: ");

        for( int i = 0; i < g; i++){
            System.out.println("Job " + (ganttchart[i][0]+1) + " end time of " + ganttchart[i][1]);
        }
    }
}