2013-03-04 87 views
0
import java.util.*; 
public class DriverExam 
{ 
    private String[] answers = {"B", "D", "A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A"}; 
    private String[] input_validation = {"A", "B", "C", "D"}; 
    private String[] student_answers = new String[20]; 
    private int[] missed = new int[20]; 
    private int[] copy_missed; 
    private boolean pass=true; 
    private int number_missed = 0; 
    Scanner kb = new Scanner(System.in); 
    String input; 

    private String input() 
    { 
     input = kb.nextLine(); 
     while(!(input.equalsIgnoreCase("A")||input.equalsIgnoreCase("B")||input.equalsIgnoreCase("C")||input.equalsIgnoreCase("D"))) 
     { 
      System.out.print("Please enter either A, B, C or D: "); 
      input = kb.nextLine(); 
     } 
     return input; 
    } 

    public boolean passed(String[] student_answers) 
    { 
     int v=0; 

     for(int i=0; i<answers.length; i++) 
     { 
      if(!(answers[i].equalsIgnoreCase(student_answers[i]))) 
      { 
       number_missed++; 
       missed[v]=i; 
       v++; 

      } 

     } 
     if(number_missed>5) 
     { 
      pass=false; 
     } 
     return pass; 
    } 

    public String[] setStudentAnswers() 
    { 
     int question = 1; 
     for(int i=0; i<student_answers.length; i++) 
     { 
      System.out.print("Enter the answer for question "+ question + ": "); 
      student_answers[i]=input(); 
      question++; 
     } 

     return student_answers; 
    } 

    public int totalCorrect() 
    { 
     int correct = 20 - number_missed; 
     return correct; 
    } 

    public int totalIncorrect() 
    { 
     return number_missed; 
    } 

    public int[] questionsMissed() 
    { 
     int[] copy_missed = Arrays.copyOfRange(missed, 0, number_missed); 
     return copy_missed; 
    } 

} 

時更具體地說,在方法questionsMissed()「無法找到符號」的錯誤,我不斷收到cannot find symbol錯誤,當談到Arrays.copyOfRange爪哇 - 調用Arrays.copyOfRange

我檢查了語法,我似乎是正確與missed作爲int[]0作爲intnumber_missed也正在一個int。

我很難過,爲什麼它不工作。

+0

? copyOfRange是1.5+。嘗試使用System.arraycopy()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/System.html#arraycopy(java.lang.Object,INT,java.lang.Object中,INT,INT)如果您正在使用<1.5 – Jaxedin 2013-03-04 04:23:30

+0

工作@OwerFlov我使用jGrasp版本1.8.8_23。這應該工作,對吧?它說它是最新的。 – gjvatsalya 2013-03-04 04:31:30

+0

發佈完整的錯誤。 – 2013-03-04 04:34:46

回答

0

的jGRASP主頁指出,最新版只需要JDK 1.5中運行,而Arrays.copyOfRange()未添加到JDK 1.6。見證docs for Arrays in 1.5中缺少任何此類方法。我對jGRASP一無所知,但我猜測你只是在引擎蓋下運行一箇舊的JDK,因爲這個錯誤是非常明確的,因爲這種方法不可用。

+0

呀。 ,你是對的。我跑1.5。 萬一你知道如何更新? – gjvatsalya 2013-03-04 04:55:18

+0

事實上,我現在固定的。感謝您的幫助。 – gjvatsalya 2013-03-04 05:19:17

0

在JDK 1.5 +您應該您正在使用什麼版本的JDK使用

System.arraycopy() 

而不是

Arrays.copyOfRange() 
+0

好了。非常感謝你! – gjvatsalya 2013-03-04 04:56:17