使用策略对java程序进行评级

时间:2012-07-03 17:51:28

标签: java

评分政策

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);

    } 
  }
}

这是我到目前为止所提出的,但我不断收到三条错误消息

Assign7.java:28;错误:非法开始表达 public String toString(){

Assign7.java:28;错误:';'预期 public String 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;

  }
} 

3 个答案:

答案 0 :(得分: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

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

答案 1 :(得分:1)

你错过了其他人的右手大括号。

答案 2 :(得分: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;

  }
}