Java Program** Write a program for the following problem. You are given a collec
ID: 3739182 • Letter: J
Question
Java Program**
Write a program for the following problem. You are given a collection of scores for the last exam in your computer course. You are to compute the average of these scores, and then assign grades to each student according to the following rule. If a student's score is within 10 points (above or below) of the average, give the student a grade of SATISFACTORY. If the score is more than 10 points higher than the average, give the student a grade of OUTSTANDING. If the score is more than 10 points below the average, give the student a grade of UNSATISFACTORY. Test your program on the following data:
Hint: The output from your program should consist of a labelled three-column list containing the name, exam score, and grade of each student.
RICHARD LUGAR FRANK RIZZO DONALD SCHAEFFER KEVIN WHITE JAMES RIEHLE ABE BEAME TOM BRADLEY WALTER WASHINGTON 71 84 93 74 70 84 68Explanation / Answer
/**The java program that calculates the names,scores and result
* of students on three column table on console.*/
//Testgrades.java
public class Testgrades {
public static void main(String[] args) {
//set names of the array
String names[]={"RICHARD LUGAR",
"FRANK RIZZO",
"DONALD SCHAEFFER",
"KEVIN WHITE",
"JAMES RIEHLE",
"ABE BEAME",
"TOM BRADLEY",
"WALTER WASHINGTON"
};
//set scores as array
int scores[]=
{
55,71,84,93,74,70,84,68
};
String result="";
double totalScore=0;
//calculate total score
for (int i = 0; i < scores.length; i++)
totalScore=totalScore+scores[i];
//calculate average
double avgScore=totalScore/scores.length;
System.out.println("Average score : "+avgScore);
for (int i = 0; i < scores.length; i++)
{
//check if score in above 10 on average score
if(scores[i]>avgScore+10)
result="OUTSTANDING";
//check if score is within 10 witin points on scores
else if(scores[i]>avgScore-10 || scores[i]<avgScore+10)
result="SATISFACTORY";
else
result="UNSATISFACTORY";
System.out.printf("%-25s%-10d%-25s ",
names[i],
scores[i],
result);
}
}
}
Sample Output :
Average score : 74.875
RICHARD LUGAR 55 SATISFACTORY
FRANK RIZZO 71 SATISFACTORY
DONALD SCHAEFFER 84 SATISFACTORY
KEVIN WHITE 93 OUTSTANDING
JAMES RIEHLE 74 SATISFACTORY
ABE BEAME 70 SATISFACTORY
TOM BRADLEY 84 SATISFACTORY
WALTER WASHINGTON 68 SATISFACTORY
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.