pasito15
pasito15

Reputation: 111

Grading java program with policies

The grading policies are

2 quizzes 10 points

1 midterm exam and one final exam, each graded on the basis of 100 points

the final exam counts for 50% of the grade, the midterm counts for 25%, and the 2 quizzes together count for a total of 25%.

a letter grade is also suppose to be given

this was given by the instructor

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

    } 
  }
}

and this is what i came up with so far however i keep getting three error messages

Assign7.java:28; errror: illegal start of expression public String toString(){

Assign7.java:28; errror: ';' expected public String toString(){

Assign7.java:33: error: reached end of file while parsing }

Could anybody tell me how to fix this errors please (this is my code)

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;

  }
} 

Upvotes: 3

Views: 324

Answers (3)

Eric J.
Eric J.

Reputation: 150138

You are missing a } to close out the declaration of public Assign7 as well as your last if statement.

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

Other answers give advice on ensuring you always have matching braces to begin with. Those are solid answers as well.

Upvotes: 5

nook
nook

Reputation: 2396

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;

  }
} 

Upvotes: 1

Justin
Justin

Reputation: 2372

You are missing a closing brace on your else.

Upvotes: 1

Related Questions