Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS A JAVA PROGRAM THAT WILL BE RUN ON NETBEANS: Rewrite the BASE CODE using multiple methods to calculate the student average and letter

THIS IS A JAVA PROGRAM THAT WILL BE RUN ON NETBEANS:

Rewrite the BASE CODE using multiple methods to calculate the student average and letter grade. The following are the rules of calculating the average and letter grade.

Average Score Calculation:

Average Score = (Test Score 1 + Test Score 2 + Test Scores 3) /3

Grade Conversion Rules:

Rule A - If the average score is 90 or more the grade is 'A'.

Rule B - If the average score is 70 or more and less than 90 then check the third test score. If the third score is 90 or more the grade is 'A' otherwise the grade is 'B'.

Rule C - If the average score is 50 or more and less than 70 then check the average of the second and third scores. If the average of the last two is 70 or more, the grade is 'C' otherwise it is a 'D'

Rule D - If the average score is less than 50 then the grade is 'F'.

Rounding Rule: Midpoint Rounding

Calculate the grade average as a double. Round up to the next int if the fractional part is .5 or greater, otherwise truncate the fraction by casting to an int. The algorithm is: Add .5 to the average and cast the result to an int. Example: average = (int)(average+0.5);

Methods required in the project:

gradesInput() Get test score from the user and return a test score to the calling method. You can call this method 3 times to get 3 test scores.

average3Scores(int s1, int s2, ints3) Average three test scores and apply the rounding rule and return the average. You pass three test scores in the parameter list in this method.

averageLast2Scores(int s2, ints3) Average last 2 test scores and apply the rounding rule and return the average. You pass two test scores in the parameter list in this method.

toLetterGrade(double avg, double avg2, int s3) Convert average grade to letter grade according the grade conversion rules and return the letter grade. You pass average, average2 and test 3 in this method.

displayGrade(double avg, char lGrade) Display average grade and letter grade, and do not return anything. You pass averge and letter grade in your parameter list in this method.

Program Design:

This assignment is using method to reorganize the BASE CODE. Add the methods below and call all the methods inside of your main() method. Each method will replace the code in your main() method that you wrote in the BASE CODE. After all the methods have been called, your main() will be very short and organized.

Here are the layouts for each method:

public static int gradesInput()

{

//Declare an int variable to store test score

//Create new Scanner object

//Prompt user to enter the test score

//Read the test score and store it into a variable

//Validate the test input to make sure it is between 0 and 100

//return test score

}

public static double average3Scores(int s1, int s2, int s3)

{

//Declare a double variable to hold average

//Calculate average by adding three scores (s1, s2, and s3) and divide it by 3.0

//Apply rounding rule

//return average

}

public static double average2Scores(int s2, int s3)

{

//Declare a double variable to hold average of 2 test scores

//Calculate average by adding two test scores (s2 and s3) and divide it by 2.0

//Apply rounding rule

//return average

}

public static char toLetterGrade(double avg, double avg2 ,int s3)

{

//Declare a letter grade variable

//Apply grade conversion rule using if.. else if statement

//return letter grade

}

public static void displayGrade(double avg, char lGrade)

{

//Display average of 3 test scores(avg)

//Display letter grade (lGrade)

}

This is the BASE CODE that this assignment is based off of:

public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter first test score: ");

int Test1 = keyboard.nextInt();

System.out.println("Enter second test score: ");

int Test2 = keyboard.nextInt();

System.out.println("Enter third test score: ");

int Test3 = keyboard.nextInt();

double Average = (Test1 + Test2 + Test3)/3.0;

Math.round(Average);

double Average2 = (Test2 + Test3)/2.0;

Math.round(Average2);

char letterGrade;

if (Average>=90){

letterGrade = 'A';

}

else if (Average>=70)

if (Test3 >=90){

letterGrade = 'A';}

else {

letterGrade = 'B';

}

else if (Average>=50)

if (Average2>=70) {

letterGrade = 'C';}

else

{letterGrade = 'D';}

else{

letterGrade = 'F';

}

System.out.println("Your letter grade is: " + letterGrade);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

=+ What skills and competencies will enable someone

Answered: 1 week ago

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago

Question

=+How will this affect the recruiting process?

Answered: 1 week ago