Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment will give you practice with interactive programs, if/else statem

ID: 3531807 • Letter: T

Question

This assignment will give you practice with interactive programs, if/else statements, and methods that return

values. Turn in a Java class named Grades in a file named Grades.java. You will be using a Scanner object

for console input, so you will need to import java.util.*; into your program.

This program uses a student's grades on homework, a midterm exam, and a final exam to compute an overall

course grade. The course grade is a weighted average. To compute a weighted average, the student's point

scores in each category are divided by the total points for that category, then multiplied by that category's

weight. (The sum of all categories' weights should be 100.)


Example: A course has 50% weight for homework, 20% weight for its midterm, and 30% weight for its final.

There are 3 homework assignments worth 15, 20, and 25 points respectively. The student received homework

scores of 10, 16, and 19, a midterm score of 81, and a final exam score of 73 (which was curved by +5 points to

make a curved score of 78).


This program asks the user to enter his/her grades on homework, a midterm exam, and (optionally) a final

exam. Using this information, the program can either compute the student's overall course grade (if the student

has taken the final exam) or tell the student what score he/she needs to earn on the final exam to achieve a

certain grade in the class.


EXPECTED OUTPUT

This program accepts your homework and exam

scores as input, and computes your grade in

the course or indicates what grade you need

to earn on the final exam.

Homework:

What is its weight (0-100)? 50

How many homework assignments were there? 3

Homework 1 score and max score: 14 15

Homework 2 score and max score: 18 20

Homework 3 score and max score: 19 25

Weighted homework score: 42.5

Midterm exam:

What is its weight (0-100)? 20

Exam score: 81

Was there a curve? (1 for yes, 2 for no) 2

Weighted exam score: 16.2

Final exam:

Have you taken the final exam yet? (1 for yes, 2 for no) 2

What is its weight (0-100)? 30

What percentage would you like to earn in the course? 80

You need a score of 71.0 on the final exam.


my work so far:


import java.util.*; // for Scanner


// This program prompts the user to enter various student scores

// and outputs the student's grade in the course.

public class Grades {



public static void main(String[] args) {

giveIntro();

Scanner console = new Scanner(System.in);

int Grade ;

double weightedScore = weightedScore(weight, score, curveNumber);

double weightedScore = weightedScore2(weight2, sections, sumScore);

}


// a welcome message to start the program

public static void giveIntro() {

System.out.println("This program accepts your homework and exam");

System.out.println("scores as input and,computes your grade in");

System.out.println("the course or indicates what grade you need");

System.out.println("to earn on the final exam.");

System.out.println();

}


// asks about student's homeworks and returns weighted HW score

public static void getHomeworkScores() {

System.out.print("What is its weight (0-100)?");

double weight = console.nextInt();

}


public static double homework(int weight) {

//your code goes here

return 0.0;

}


// asks about student's exam and returns weighted exam score

public static double exam(Scanner console, int number, int weight)

{

//your code goes here

return 0.0;

}


// helper method to compute and print a weighted category score

public static double weightedScore(int weight, int earned, int

possible) {

//your code goes here

return 0.0;

}


// returns the given double value rounded to the nearest hundredth

public static double round2(double number) {

return Math.round(number * 100.0) / 100.0;

}

}


Explanation / Answer

import java.io.*; import java.text.*; class Grades { static BufferedReader stdin; //-------------------------------------------------------------- // getName // // prompt the user for a name and returns a string entered by user. //-------------------------------------------------------------- static String getName() throws IOException { System.out.println("Name : "); return stdin.readLine(); } //-------------------------------------------------------------- // getInt // // input : a message to print // output : an integer input by the user // read an positive int from user and returns it. //-------------------------------------------------------------- static int getInt(String message) throws IOException { String errMessage = "ERROR : input must be positive. " + "Try again :"; // prompt and read in the grade. System.out.println(message); int input = Integer.parseInt(stdin.readLine()); // make sure that grade is valid. while (input < 0) { System.out.println(errMessage); System.out.println(message); input = Integer.parseInt(stdin.readLine()); } // invariant : input is positive. Return the input. return input; } //-------------------------------------------------------------- // getGrade // // input : a message to print // output : an double input by the user // read a double between 0 and 100 from a user and returns it. //-------------------------------------------------------------- static double getGrade(String message) throws IOException { String errMessage = "ERROR : grade must be between 0 and 100. " + "Try again :"; // prompt and read in the grade. System.out.println(message); double grade = Double.valueOf(stdin.readLine()).doubleValue(); // make sure that grade is valid. while (grade < 0 || grade > 100) { System.out.println(errMessage); System.out.println(message); grade = Double.valueOf(stdin.readLine()).doubleValue(); } // invariant : grade is >= 0 and