Unformatted Attachment Preview
/*
* Author: ud17
Project Title: Compute Average Grade
Description: A students enters 10 grades and the application thereafter the application calculates the
average grade.
In case the student average grade is less than 70 points then the program prints a message You need
extra help
from the Professor" otherwise if the average is more than 70 points but less than 80 points,
then the program prints "The You are doing a good job". If the student's average is more than 80 points
but less than 90, then the program will print "You are doing a great job". For averages more than 90
points,
the program will print "You are donig an excellent job, keep it up!"
*/
import javax.swing.JOptionPane;
public class computerAverageGradesFinal {
//Begin the main method.
public static void main(String[] args) {
//Set the averageGrade_NoMaxMin and the feedbackMsg.
double averageGrade_NoMaxMin = fillGradesArray();
String feedbackMsg = "";
feedbackMsg = printGradeMsg(averageGrade_NoMaxMin);
}
//Begin the submethod called, printGradeMs with a parameter of averageGrade_NoMaxMin.
public static String printGradeMsg(double averageGrade_NoMaxMin)
{
//Set the strGrade and the feedbackMsg.
String strGrade= "";
String feedbackMsg="";
//Validate the feedbackMsg based on the averageGrade_NoMaxMin.
if (averageGrade_NoMaxMin < 70)
{
feedbackMsg = "You needs extra help from your Professor";
}
else if (averageGrade_NoMaxMin > 70 || averageGrade_NoMaxMin 80 || averageGrade_NoMaxMin 90 && averageGrade_NoMaxMin < 100)
{
feedbackMsg = "You are doing an excellent job, keep it up!!!";
}
//Return the feedbackMsg to the main method.
return feedbackMsg;
}
//Begin the second submethod, fillGradesArray.
public static double fillGradesArray()
{
//Set maxArrayLength, index, grade, strGrade, averageGrade_NoMaxMin, and initialize allGradesArray.
final int maxArrayLength = 10;
int[] allGradesArray = new int[maxArrayLength];
int index = 0;
int grade = -1;
String strGrade="";
double averageGrade_NoMaxMin = 0.00;
//Use try and catch within a do loop and do loop within a for loop to prompt and validate the grade
user inputs.
for (index = 0; index 100);
strGrade = grade+", "+strGrade;
allGradesArray[index] = grade;
}
//Set maxGrade, minGrade, readAllGrades, sumAllGrades, output, strOutput, and feedbackMsg.
int maxGrade = allGradesArray[0];
int minGrade = allGradesArray[0];
int readAllGrades; //*** 1 bug missing initialization for variable declaration
int sumAllGrades = 0;
String feedbackMsg ="";
int output = 0;
String strOutput ="";
//Begin a for loop to find the maximum and the minimum values.
for (index = 1; index maxGrade)
{
maxGrade = allGradesArray[index];
}
else if (allGradesArray[index] < minGrade)
{
minGrade = allGradesArray[index]
}
//Calculate the sum of all grades.
sumAllGrades += grade;
//Calculate the average grade of all grades with no maximum or minimum values.
averageGrade_NoMaxMin = (float) (sumAllGrades - maxGrade - minGrade)/(maxArrayLength - 2);
}
feedbackMsg = printGradeMsg(averageGrade_NoMaxMin);
//Print the report: strGrade, averageGrade_NoMaxMin, and the feedbackMsg.
JOptionPane.showMessageDialog(null,"\nThe grades you entered are: " + strGrade + "\nThe student's
average grade wit
hout the maximum and the minimum grade is: " + String.format("%.2f", averageGrade_NoMaxMin)+
"\nThe feedback is: "+feedbackMsg);
//Return the averageGrade_NoMaxMin to the main method.
return averageGrade_NoMaxMin
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Author: ud17
Project Title: Compute Average Grade
Description: A students enters 10 grades and the application thereafter the application calculates the average grade.
In case the student average grade is less than 70 points then the program prints a message You need extra help
from the Professor" otherwise if the average is more than 70 points but less than 80 points,
then the program prints "The You are doing a good job". If the student's average is more than 80 points
but less than 90, then the program will print "You are doing a great job". For averages more than 90 points,
the program will print "You are donig an excellent job, keep it up!"
*/
import javax.swing.JOptionPane;
public class computerAverageGradesFinal {
//Begin the main method.
public static void main(String[] args) {
//Set the averageGrade_NoMaxMin and the feedbackMsg.
double averageGrade_NoMaxMin = fillGradesArray();
String feedbackMsg = "";
feedbackMsg = printGradeMsg(averageGrade_NoMaxMin);
}
//Begin the submethod called, printGradeMs with a parameter of averageGrade_NoMaxMin.
public static String printGradeMsg(double averageGrade_NoMaxMin)
{
//Set the strGrade and the feedbackMsg.
String strGrade= "";
String feedbackMsg="";
//Validate the feedbackMsg based on the averageGrade_NoMaxMin.
if (averageGrade_NoMaxMin < 70)
{
feedbackMsg = "You needs extra help from your Professor";
}
else if (averageGrade_NoMaxMin > 70 || averageGrade_NoMaxMin 80 || averageGrade_NoMaxMin 90 && averageGrade_NoMaxMin < 100)
{
feedbackMsg = "You are doing an excellent job, keep it up!!!";
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
}
//Return the feedbackMsg to the main method.
return feedbackMsg;
}
//Begin the second submethod, fillGradesArray.
public static double fillGradesArray()
{
//Set maxArrayLength, index, grade, strGrade, averageGrade_NoMaxMin, and initialize allGradesArray.
final int maxArrayLength = 10;
int[] allGradesArray = new int[maxArrayLength];
int index = 0;
int grade = -1;
String strGrade="";
double averageGrade_NoMaxMin = 0.00;
//Use try and catch within a do loop and do loop within a for loop to prompt and validate the grade user inputs.
for (index = 0; index 100);
strGrade = grade+", "+strGrade;
allGradesArray[index] = grade;
}
//Set maxGrade, minGrade, readAllGrades, sumAllGrades, output, strOutput, and feedbackMsg.
int maxGrade = allGradesArray[0];
int minGrade = allGradesArray[0];
int readAllGrades; //*** 1 bug missing initialization for variable declaration
int sumAllGrades = 0;
String feedbackMsg ="";
int output = 0;
String strOutput ="";
101
102
//Begin a for loop to find the maximum and the minimum values.
103
for (index = 1; index maxGrade)
107
{
108
maxGrade = allGradesArray[index];
109
110
}
111
else if (allGradesArray[index] < minGrade)
112
{
113
minGrade = allGradesArray[index]
114
}
115
116
//Calculate the sum of all grades.
117
sumAllGrades += grade;
118
119
//Calculate the average grade of all grades with no maximum or minimum values.
120
averageGrade_NoMaxMin = (float) (sumAllGrades - maxGrade - minGrade)/(maxArrayLength - 2);
121
122
}
123
feedbackMsg = printGradeMsg(averageGrade_NoMaxMin);
124
125
//Print the report: strGrade, averageGrade_NoMaxMin, and the feedbackMsg.
126
JOptionPane.showMessageDialog(null,"\nThe grades you entered are: " + strGrade + "\nThe student's average grade wit
hout the maximum and the minimum grade is: " + String.format("%.2f", averageGrade_NoMaxMin)+ "\nThe feedback is: "+feedbackMsg);
127
128
//Return the averageGrade_NoMaxMin to the main method.
129
return averageGrade_NoMaxMin
130
131
}
132 }
133