the requirement:
The number of input integers (marks) should be at least 12 (meaning
counted 3 semester advanced standing from somewhere else) and at
most 30 including the failed mark and repeated mark of the same unit
(meaning you are automatically disqualified if you failed more than 6 units
during the course).
i have code following and i would like to know where to add arrays in this code?
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
/**
*
* @author Acer
*/
public class Average2 {
public static void main( String args[] ) {
int gradeCounter, // number of grades entered
gradeValue, // grade value
total; // sum of grades
double average; // average of all grades
String input; // grade typed by user
// Initialization phase
total = 0; // clear total
gradeCounter = 0; // prepare to loop
// Processing phase
// prompt for input and read grade from user
input = JOptionPane.showInputDialog(
"Enter Integer Grade, -1 to Quit:" );
// convert grade from a String to an integer
gradeValue = Integer.parseInt( input );
while ( gradeValue != -1 ) {
// add gradeValue to total
total += gradeValue;
// add 1 to gradeCounter
gradeCounter += 1;
// prompt for input and read grade from user
input = JOptionPane.showInputDialog(
"Enter Integer Grade, -1 to Quit:" );
// convert grade from a String to an integer
gradeValue = Integer.parseInt( input );
}
// Termination phase
DecimalFormat twoDigits = new DecimalFormat( "0.00" );
if ( gradeCounter != 0) {
average = (double) total / gradeCounter;
// display average of exam grades
JOptionPane.showMessageDialog( null,
"Class average is " + twoDigits.format( average ),
"Class Average", JOptionPane.INFORMATION_MESSAGE );
}
else {
JOptionPane.showMessageDialog( null,
"No grades were entered", "Class Average",
JOptionPane.INFORMATION_MESSAGE );
}
}
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment