Question

Write a program to calculate students’ average test scores and their grades. You may assume the...

Write a program to calculate students’ average test scores and their grades. You may assume the following data:

Johnson 85 83 77 91 76

Aniston 80 90 95 93 48

Cooper 78 81 11 90 73

Gupta 92 83 30 69 87

Blair 23 45 96 38 59

Clark 60 85 45 39 67

Kennedy 77 31 52 74 83

Bronson 93 94 89 77 97

Sunny 79 85 28 93 82

Smith 85 72 49 75 63

Use three arrays: a one-dimensional array to store the student names, a (parallel) two-dimensional array to store the test score, and a parallel one-dimensional array to store grades. Your program must contain at least the following methods: a method to read and store data into two arrays, a method to calculate the average test score and grade and a method to output the results. Have your program also output the class average.

Grade calculation to be computed as follows:

Marks Grade
85-100 A
75-84 B
65-74 C
50-64 D
<50 F

* Java program free from syntax, logic and run time errors.

* Used methods, array parameters and keyboard input.

* Code optimisation: no unnecessary assignment of variables, calculations, parameters and loops

* Descriptive block and inline comments included.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

import java.util.*;
import java.io.*;
class StudentGrades
{
public static void readInput(int n,String names[],int score[][])//method to read input
{
Scanner sc=new Scanner(System.in);//scanner object to read input from keyboard
int i,j;
System.out.println("Enter student names followed by marks:");
for(i=0;i<n;i++)
{
names[i]=sc.next();//reading names form keyboard
for(j=0;j<5;j++)//reading marks of five subjects
score[i][j]=sc.nextInt();
}
}
public static double calculateAverage(int score[])//method to calculate average
{
double res=0;
for(int i=0;i<5;i++)//calculate sum of five subjects
{
res+=score[i];
}
res=res/5;//calculate average
return res;
}
public static char findGrade(int score[])//method to find Grade
{
//return appropriate grade based on average
double res=calculateAverage(score);//calculate average
if(res>=85)
return 'A';
else if(res>=75 && res<=84)
return 'B';
else if(res>=65 && res<=74)
return 'C';
else if(res>=50 && res<=64)
return 'D';
else
return 'F';
}
public static void outputResult(String names[],char res[],int n)//method to print result
{
for(int i=0;i<n;i++)
System.out.println(names[i]+":"+res[i]);
}
public static void main(String args[])//main code
{
System.out.print("Enter no of students:");
Scanner sc=new Scanner(System.in);//scanner object to read input from keyboard
int n=sc.nextInt();//reading number of students
String names[]=new String[n];//creating a array of strings
int score[][]=new int[n][5];//creating array of scores
readInput(n,names,score);
char res[]=new char[n];//creating array of characters
for(int i=0;i<n;i++)
res[i]=findGrade(score[i]);//finding the grade of student
System.out.println("Final Grades:");
outputResult(names,res,n);
}
}

code output:

it consists of four functions:

readInput

outputResult

findGrade

calculateAverage.

hope this helps you :)

Add a comment
Know the answer?
Add Answer to:
Write a program to calculate students’ average test scores and their grades. You may assume the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Student average array program

    Having a bit of trouble in my c++ class, was wondering if anyone can help.Write a program to calculate students' average test scores and their grades. You may assume the following input data:Johnson 85 83 77 91 76Aniston 80 90 95 93 48Cooper 78 81 11 90 73Gupta 92 83 30 68 87Blair 23 45 96 38 59Clark 60 85 45 39 67Kennedy 77 31 52 74 83Bronson 93 94 89 77 97Sunny 79 85 28 93 82Smith 85 72...

  • Write the definition of the class Tests such that an object of this class can store...

    Write the definition of the class Tests such that an object of this class can store a student's first name, last name, five test scores, average test score, and grade. (Use an array to store the test scores.) Add constructors and methods to manipulate data stored in an object. Among other things, your class must contain methods to calculate test averages, return test averages, calculate grades, return grades, and modify individual test scores. The method toString must return test data...

  • this is a java course class. Please, I need full an accurate answer. Labeled steps of...

    this is a java course class. Please, I need full an accurate answer. Labeled steps of the solution that comply in addition to the question's parts {A and B}, also comply with: (Create another file to test the class and output to the screen, not an output file) please, DO NOT COPY others' solutions. I need a real worked answer that works when I try it on my computer. Thanks in advance. Write the definition of the class Tests such...

  • Could someone show how to do this in C#? I keep getting errors for mine and...

    Could someone show how to do this in C#? I keep getting errors for mine and the other answers on here that are similar doesn't work. And please make sure it accepts user input. Write the class "Tests". Ensure that it stores a student's first name, last name, all five test scores, the average of those 5 tests' scores and their final letter grade. (Use an array to store test scores.) Add constructors and methods to manipulate the data stored...

  • IN JAVA WITH COMMENTS, The assignment: This program inputs the names of 5 students and the...

    IN JAVA WITH COMMENTS, The assignment: This program inputs the names of 5 students and the (integer) grades they earned in 3 tests. It then outputs the average grade for each student. It also outputs the highest grade a student earned in each test, and the average of all grades in each test. Your output should look like this: Mary's average grade was 78.8% Harry's average grade was 67.7% etc... : In test 1 the highest grade was 93% and...

  • PSEUDOCODE and PYTHON source code! Program 4: Design (pseudocode) and implement (source code) a program (name...

    PSEUDOCODE and PYTHON source code! Program 4: Design (pseudocode) and implement (source code) a program (name it MinMaxAvg) to determine the highest grade, lowest grade, and the average of all grades in a 4-by-4 two-dimensional arrays of integer grades (representing 4 students’ grades on 4 tests). The program main method populates the array (name it Grades) with random grades between 0 and 100 and then displays the grades as shown below. The main method then calls method minMaxAvg()that takes a...

  • THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA...

    THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA that reads students’ names followed by their test scores from "data.txt" file. The program should output "out.txt" file where each student’s name is followed by the test scores and the relevant grade, also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in an instance of class variable of type...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT