2016-10-09 62 views
-4

我無法修復我的代碼。它總是說「找不到符號」錯誤。我試圖尋找一些解決方案,但仍然無法正常工作。在第15行和第18行找不到符號錯誤

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]; 
+2

那麼你*有*一個'Job'類?你是在同一時間編譯它嗎?你怎麼編譯你的代碼?它是什麼樣子的?請提供一個[mcve],而不僅僅是一個程序的前半部分,其中大部分與該問題無關。 –

+3

你爲什麼不標記第15和18行?讓我們數數? – passion

+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]); 
     } 
    } 
}