# Problem description: | Computer Science homework help

### Problem Description:

This assignment will give you practice with interactive programs, if/else statements, and methods that return values. Turn in a Java class named MITnnnnnGrades in a file named MITnnnnnGrades.java were MITnnnnn is your MIT ID. You will be using a Scanner object for console input, so you will need to import java.util.*; into your program. (Make sure you are using Java v1.5, otherwise, the Scanner will not be found.)

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 as shown below. (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).

Grade=77.1

Note that the above math is written as real math and not Java math; in Java, an integer expression such as 81/100 would evaluate to 0, but above the value intended is 0.81.

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.

(You may wish to skip ahead to the example logs of execution to get a feel for the program before reading the detailed description of its behaviour.)**Program Behavior:**

The following section describes the program’s behaviour in detail. You can also get a good idea of the program’s behaviour by looking at the logs of execution that will follow, but you should read this section completely to make sure you see all of the cases and behaviours your program should have.

· First, the program prints a header message describing itself.

· Second, the program asks the user for homework information. The user enters the weight of the homework assignments, which can be any number between 0 and 100. The user enters how many homework assignments were completed. For each of these assignments, the user enters his/her score along with the maximum possible score, separated by spaces. Your code should work for any number of assignments greater than or equal to 1.

· Third, the program asks the user for midterm exam information. The user enters its weight from 0 to 100 and his/her score. (The user does not enter the maximum score for the midterm because this is assumed to be 100.) The user is asked whether the midterm was curved; a response of 1 means, yes, and 2 means, no.

o If there was a curve, the user is asked how many points were added. These points are added to the user’s midterm score.

o No exam’s score can be above 100, so if the curve would have made the user’s score exceed 100, a score of 100 is used.

· Fourth, the program asks the user for final exam information. The program can be run before or after the final exam, so first, the user enters whether the final exam has been completed; a response of 1 means, yes, and 2 means, no.

o If the final exam has been completed, the program will help the user show his/her overall course grade. The user enters the exam weight and his/her score on the final exam. The user is asked whether the final exam was curved; a response of 1 means, yes, and 2 means no. If there was a curve, the user is asked how many points were added. These points are added to the user’s final exam score. No exam’s score can be above 100, so if the curve would have made the user’s score exceed 100, a score of 100 is used. Lastly, the user’s overall course grade is printed.

o If the final exam has not yet been completed, the program will help the user see what final exam score he/she needs to earn a particular overall grade in the course. The final exam weight and the user’s desired course grade are entered. The program computes and shows what score the student needs on the final to achieve the desired course grade.

o If the student can achieve the desired course grade without taking the final exam (in other words, if a final exam score of 0 or less is required), the program shows 0.0 as the needed final exam score.

o If the required score for the student to get the desired course grade is greater than 100, it should still be printed as normal, and then the user should receive a message indicating that the desired score cannot be achieved, and a message showing the highest course grade that the student can get (which is the grade that would result if the student earns 100 on the final exam).

See the provided logs of execution on the course web site for an example of the expected output.

### Expected Output:

The following logs of execution indicate the exact format of the output that you should reproduce. Your program’s output should match these samples when the same input is typed. Please note that there are some blank lines between sections of output and that some lines of output are indented by four spaces. Also, note that input values typed by the user appear on the same line as the corresponding prompt message.

#### First log of execution (user input underlined)

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

How many homework assignments were there?

Homework 1 score and max score:

Homework 2 score and max score:

Homework 3 score and max score:

Weighted homework score: 42.5

Midterm exam:

What is its weight (0-100)?

Exam score:

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

Weighted exam score: 16.2

Final exam:

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

What is its weight (0-100)?

What percentage would you like to earn in the course?

You need a score of 71.0 on the final exam.

#### Second log of execution (user input underlined)

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

How many homework assignments were there?

Homework 1 score and max score:

Homework 2 score and max score:

Homework 3 score and max score:

Homework 4 score and max score:

Weighted homework score: 23.64

Midterm exam:

What is its weight (0-100)?

Exam score:

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

How much was the curve?

Weighted exam score: 30.0

Final exam:

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

What is its weight (0-100)?

Exam score:

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

How much was the curve?

Weighted exam score: 20.4

Your course grade is 74.04

#### Third log of execution (user input underlined)

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

How many homework assignments were there?

Homework 1 score and max score:

Homework 2 score and max score:

Weighted homework score: 14.67

Midterm exam:

What is its weight (0-100)?

Exam score:

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

Weighted exam score: 14.0

Final exam:

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

What is its weight (0-100)?

What percentage would you like to earn in the course?

You need a score of 245.33 on the final exam.

Sorry, it is impossible to achieve this percentage.

The highest percentage you can get is 53.67.

### Input and Output Details:

**You do not have to perform any error checking on user input.** You may assume that the user types legal values of the proper type and in the appropriate range. For example, when prompted for a number, assume that the user does enter a number and not a String. When prompted for a number within an expected range, such as a weight or exam score between 0 and 100, the user will enter a valid number in that range and not a number outside the range. When prompted for the number of homework assignments, the user will enter a number no less than 1. The sum of the weights the user will enter will always be 100.

Notice that all real numbers output by the program are printed with no more than 2 digits after the decimal point. To achieve this, you may use code such as the following method to round a double value to the nearest hundredth:

// Returns the given double value rounded to the nearest hundredth.

public static double round2(double number) {

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

}

Only round numbers as you are about to print them, such as:

System.out.println(“Weighted exam score: ” + round2(weightedExamScore));

Another way to print a number rounded to 2 places is to use the System.out.printf method as follows.

// print weighted exam score, rounded to 2 decimal places

System.out.printf(“%.2f”, weightedExamScore);

The System.out.printf command will always print 2 digits after the decimal point, such as 93.50 instead of 93.5. This will be considered acceptable and correct output for this assignment.