Problem description This assignment will give you practice w
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 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, 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).
Grade = WeightedHomeworkScore + WeightedMidtermScore + WeightedFinalExamScore
Grade = (HomeworkEarned/HomeworkPossible * HomeworkWeight) + (MidtermEarned/MidtermPossible * MidtermWeight) + (FinalEarned/FinalPossible * FinalWeight)
Expected Output:
The following logs of execution indicate the exact format of the output you should reproduce. Your program\'s output should match these examples exactly when the same input is typed. Please note 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 in bold):
This program accepts your homework and exam scores as input, and computes your grade in the course or indicated what grade you need to earn on the final exam.
Homework:
What is it\'s 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 it\'s 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 it\'s 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.
Second log of execution (user input in bold):
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 it\'s weight (0-100)? 40
How many assignments were there? 4
Homework 1 score and max score: 21 30
Homework 2 score and max score: 11 20
Homework 3 score and max score: 28 50
Homework 4 score and max score: 5 10
Weighted homework score: 23.64
Midterm exam:
What is it\'s weight (0-100)? 30
Exam score: 95
Was there a curve? (1 for yes, 2 for no) 1
How much was the curve? 10
Weighted exam score: 30.0
Final exam:
Have you taken the final exam yet? (1 for yes, 2 for no) 1
What is it\'s weight (0-100)? 30
Exam score: 63
Was there a curve? (1 for yes, 2 for no) 1
How much was the curve? 5
Weighted exam score: 20.4
Your course grade is 74.04
Third log of execution (user input in bold):
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 it\'s weigt (0-100)? 50
How many homework assignments were there? 2
Homework 1 score and max score: 10 50
Homework 2 score and max score: 12 25
Weighted homework score: 14.67
Midterm Exam:
What is it\'s weight (0-100)? 25
Exam score: 56
Was there a Curve? (1 for yes, 2 for no) 2
Weighted exam score: 14.0
Final exam:
Have you taken the final exam yet? (1 for yes, 2 for no) 2
What is it\'s weight (0-100)? 25
What percentage would you like to earn in the course? 90
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.
The above three logs of execution are sample outputs. The program requires at least four non-trivial methods other than \"main\" in the program.
Solution
import java.util.Scanner;
import java.text.DecimalFormat;
public class Grades {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int weight;
int hmScore,maxScore;
int sumhm=0;
int sumMAx=0;
System.out.println(\"Homework:\");
System.out.println(\"What is it\'s weight (0-100)?:\");
weight=scan.nextInt();
if(weight>=100){
System.out.println(\"ReEnter weight (0-100)?\");
weight=scan.nextInt();
}
System.out.println(\"How many homework assignments were there?:\");
int assignments=scan.nextInt();
for(int i=0;i<assignments;i++){
System.out.println(\"Homework \"+i+\" score and max score:\");
hmScore=scan.nextInt();
sumhm=sumhm+hmScore;
maxScore=scan.nextInt();
sumMAx=sumMAx+maxScore;
}
double val=(sumhm / sumMAx);
DecimalFormat df = new DecimalFormat(\"#.#####\");
df.format(sumhm / sumMAx);
//System.out.println(\"Weighted homework score is sum:\"+sumhm+\"\ \"+\"sumMAx\"+sumMAx+\" \"+val+ \" \"+val*weight);
System.out.println(sumhm);
System.out.println(sumMAx);
System.out.println(sumhm/sumMAx);
System.out.println(val*weight);
//System.out.println(\"What \"+weight);
}
}



