3

分级政策是

2 次测验 10 分

1次期中考试和1次期末考试,每项以100分计分

期末考试占成绩的 50%,期中考试占 25%,2 次测验合计占 25%。

还应该给出一个字母等级

这是教练给的

import java.util.*;
import java.io.*;

public class Assign7{
  public static void main(String[] args)throws Exception{



    Scanner myIn = new Scanner( new File("scores.txt") );



    System.out.println( myIn.nextLine() +"  avg  "+"letter");

    while( myIn.hasNext() ){
       name = myIn.Next();
       q1 = myIn.nextInt();
       q2 = myIn.nextInt();
       m = myIn.nextInt();
       f = myIn.nextInt();
       Record myR = new Record( name, q1,q2,m,f);
       System.out.println(myR);

    } 
  }
}

这就是我到目前为止想出的但是我不断收到三个错误消息

分配7.java:28;错误:表达式的非法开头 public String toString(){

分配7.java:28;错误:';' 预期的公共字符串 toString(){

Assign7.java:33:错误:解析时到达文件末尾}

谁能告诉我如何解决这个错误(这是我的代码)

class Assign7{
  private double finalScore;
  private double private_quiz1;
  private double private_quiz2;
  private double private_midTerm;
  private double private_final;
  private final char grade;


  public Assign7(double finalScore){
    private_quiz1 = 1.25;
    private_quiz2 = 1.25;
    private_midTerm = 0.25;
    private_final = 0.50;

        if (finalScore >= 90) {
            grade = 'A';
        } else if (finalScore >= 80) {
            grade = 'B';
        } else if (finalScore >= 70) {
            grade = 'C';
        } else if (finalScore>= 60) {
            grade = 'D';
        } else {
            grade = 'F';


  public String toString(){
    return finalScore+":"+private_quiz1+":"+private_quiz2+":"+private_midTerm+":"+private_final;

  }
} 
4

3 回答 3

5

你错过了}结束声明public Assign7以及你最后的if声明。

public Assign7(double finalScore){
    private_quiz1 = 1.25;
    private_quiz2 = 1.25;
    private_midTerm = 0.25;
    private_final = 0.50;

    if (finalScore >= 90) {
        grade = 'A';
    } else if (finalScore >= 80) {
        grade = 'B';
    } else if (finalScore >= 70) {
        grade = 'C';
    } else if (finalScore>= 60) {
        grade = 'D';
    } else {
        grade = 'F';
    } // <===== ADD THIS
} // <============= ADD THIS

其他答案提供了有关确保您始终拥有匹配的大括号的建议。这些也是可靠的答案。

于 2012-07-03T17:53:58.857 回答
1
public class Assign7{
  private double finalScore;
  private double private_quiz1;
  private double private_quiz2;
  private double private_midTerm;
  private double private_final;
  private final char grade;


  public Assign7(double finalScore){
    private_quiz1 = 1.25;
    private_quiz2 = 1.25;
    private_midTerm = 0.25;
    private_final = 0.50;

        if (finalScore >= 90) {
            grade = 'A';
        } else if (finalScore >= 80) {
            grade = 'B';
        } else if (finalScore >= 70) {
            grade = 'C';
        } else if (finalScore>= 60) {
            grade = 'D';
        } else {
            grade = 'F';
}

}

  public String toString(){
    return finalScore+":"+private_quiz1+":"+private_quiz2+":"+private_midTerm+":"+private_final;

  }
} 
于 2012-07-03T17:56:16.473 回答
1

您在 else 上缺少一个右括号。

于 2012-07-03T17:54:05.430 回答