Question

In: Computer Science

Instructions Write a Java program that asks the user t enter five test scores. The program...

Instructions

Write a Java program that asks the user t enter five test scores. The program should display a letter grade for each score and the average test 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 grading scale.

Score Letter Grade

90-100 A

80-89 B

70-79 C

60-69 D

Below 60 F

Solutions

Expert Solution

According to the problem statement above,

I have coded the function using Java

Below are the Snippets:

Code Snippet:

Output Snippet:

Code in Text format:

import java.io.*;
import java.util.*;

public class demo                                                                               // class starts from here
{
    public static double calcAverage(double a, double b, double c,double d, double e)           // method to calculate average
    {
        return (a + b + c + d + e) / 5;                                                         // returning the average
    }
  
    public static char determineGrade(double g)                                                 // method to determice Grade
    {
       if(g>=90 && g<=100)                                                                    // A between 90 and 100
       {
           return 'A';
       }
       else if(g>=80 && g<=90)                                                                 // B between 80 and 89
       {
           return 'B';
       }
       else if(g>=70 && g<=80)                                                                 // C between 70 and 79
       {
           return 'C';
       }
       else if(g>=60 && g<=70)                                                                 // D between 60 and 69
       {
           return 'D';
       }
       else if(g<60)                                                                           // A less than 60
       {
           return 'F';
       }
       return 0;
    }
  
   public static void main(String[] args)                                                      // main method
   {
        Scanner z = new Scanner(System.in);                                                     // scanner to scan inputs
    
        double num1 = z.nextDouble();                                                           // scanning 5 scores
        double num2 = z.nextDouble();
        double num3 = z.nextDouble();
        double num4 = z.nextDouble();
        double num5 = z.nextDouble();
      
        double average = calcAverage(num1, num2, num3, num4, num5);                             // passing scores to average
       char grade = determineGrade(average);                                                   // passing average to grade
      
        System.out.println("The average of Scores is: " +average);                              // printing average
        System.out.print("The grade of Test Score is: " +grade);                                // printing grade
    }
}

I hope the above snippets, information, and the explanation will help you out!

Please comment if you have any queries/errors!

Thank you!


Related Solutions

Write a program that asks the user to enter five test scores. The program should display...
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test 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 grading scale: Score Letter Grade 90-100...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
Design, plan, test, and write a computer program in Java that asks the user to enter...
Design, plan, test, and write a computer program in Java that asks the user to enter 1 number and a String. You will display the first n characters of the string where n is the number entered. For example, if the user enters 3 and java then you will print jav. If they enter 5 and Halloween then you print Hallo. If the user enters a number less than 0 then set the number to 0. Assume the user will...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
Write a javascript program that asks the user to enter up to 10 golf scores, which...
Write a javascript program that asks the user to enter up to 10 golf scores, which are to be stored in an array. You should provide a means for the user to terminate input prior to entering 10 scores. The program should display all the scores on one line and report the average score. Handle input, display, and the average calculation with three separate array processing functions.
Write a program in Java to: Ask the user how many scores they want to enter...
Write a program in Java to: Ask the user how many scores they want to enter (=> Create an array based the entered size) Ask the user to enter their scores in the quarter (Fill the array with the entered scores(assigned to elements)) ==>> Use a "for" loop Find the greatest score Calculate and show the average Show the final grade based on the average (For example A,B,C ... ) Print the scores (the elements of the array) => Use...
Write a java simple document retrieval program that first asks the user to enter a single...
Write a java simple document retrieval program that first asks the user to enter a single term query, then goes through two docuements named doc1.txt and doc2.txt (provided with assignment7) to find which document is more relevant by calculating the frequency of the query term in each document. Output the conclusion to a file named asmnt7output.txt in the following format (as an example for query “java” and “problem”). The percentages in parenthese are respective supporting frequencies. java: doc1(6.37%) is more...
IN JAVA Write a complete program that asks the user to enter two real numbers from...
IN JAVA Write a complete program that asks the user to enter two real numbers from the console. If both numbers are positive print the product, if both numbers are negative print the quotient, otherwise print INVALID INPUT. Use a nested if; output should be to a dialog and console; use printf to format the console output (for real numbers specify the width and number of digits after the decimal). The output must be labeled. Follow Java conventions, indent your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT