Ask Question

Write a program that prompts user to enter five numeric test score. the program should display the corresponding letter grade and class average

+3
Answers (1)
  1. 24 June, 04:40
    0
    import java. util. Scanner;

    public class Student {

    public static void main (String[ ] args) {

    //Enter 5 test scores

    int[ ] marks=enterMark ();

    //calculate average

    double averageScore=calAverage (marks);

    //calculate grade

    char theGrade=letterGrade (marks);

    //Display average

    System. out. println ("Average: " + average Score);

    //Display grade

    System. out. println (" Grade: " + theGrade);

    /* * method collects 5 test scores and returns reference*/

    public static int[ ] enterMark () {

    int[ ] arr=new int[5];

    //create Scanner object

    Scanner keyboard=new Scanner (System. in);

    int index=0;

    while (index
    System. out. print ("Enter test " + (index+1));

    arr[index]=keyboard. nextInt ();

    index++;

    }

    return arr;

    }

    /**method calculates and returns average*/

    public static double calAverage (int[ ] arr) {

    double total=0.0; / /to hold total

    double average=0.0; //hold average

    for (int count=0; count
    total+=arr[count];

    }

    average=total/arr. length;

    return average;

    }

    /* * method calculates and returns grade*/

    public static char letterGrade (double ave) {

    char grade; / /to hold grade

    if (ave >30)

    grade='D';

    if (ave >50)

    grade='C';

    if (ave > 60)

    grade='B';

    if (ave > 70)

    grade='A';

    else

    grade='F';

    return grade;

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that prompts user to enter five numeric test score. the program should display the corresponding letter grade and class ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers