Question
JAVA PROGRAMMING: Feel free to correct and or alter my code as you see fit (found below), or write your own to answer this question.
JAVA PROGRAMMING: Feel free to correct and or alter my code as you see fit (found below), or write your own to answer this question. Please comment if writing your own code or altering mine. Please leave my edited or your own code in the answer section, thank you!
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score, and test the average score. Write the following methods in the program:
CalcAverage--- This method should accept five test scores as arguments, and return the average of the scores
determineGrade--- This method should accept a test score as an argument, and return a letter grade for the score, based on the following scale
90-100 =A
80-89=B
70-79=C
60-69=D
Below 60=F
---------------------------------------------------------------------
import java.util.Scanner;
class TestGrade { public static void main(String arg[]) { double score1, score2, score3, score4, score5; char grade1, grade2, grade3, grade4, grade5; double avg; System.out.println("Please enter a score:"); Scanner sc= new Scanner(System.in); score1 = sc.nextDouble(); grade1=determineGrade(score1); System.out.println("Please enter a score:"); Scanner st= new Scanner(System.in); score2 = st.nextDouble(); grade2=determineGrade(score2); System.out.println("Please enter a score:"); Scanner se= new Scanner(System.in); score3 = se.nextDouble(); grade3=determineGrade(score3); System.out.println("Please enter a score:"); Scanner sd = new Scanner(System.in); score4 = sd.nextDouble(); grade4=determineGrade(score4); System.out.println("Please enter a score:"); Scanner sg= new Scanner(System.in); score5 = sg.nextDouble(); sc.close(); st.close(); se.close(); sd.close(); sg.close(); grade5=determineGrade(score5); System.out.println(" "); avg = calcAverage(score1, score2, score3, score4, score5); System.out.println("Score Letter Grade"); System.out.println(".............."); System.out.println(" Score1" + grade1); System.out.println(" Score2" + grade2); System.out.println(" Score3" + grade3); System.out.println(" Score4" + grade4); System.out.println(" Score5" + grade5); System.out.println("The average test score is" + avg); }
public static char determineGrade(double score) { char grade; if(score>= 90 && score <= 100) grade = 'A'; else if (score>=80 && score <=89) grade = 'B'; else if (score>=70 && score <=79) grade = 'C'; else if (score>=60 && score <=69) grade = 'D'; else grade = 'F'; return grade; } public static double calcAverage(double score1, double score, double score3, double score4, double score5) { return((score1 + score2 + score3 + score4 + score5)/5.0); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started