M
me
I am getting the vlaue '0.0' for Percent of Grade A, Garde B, etc.
Everythign else, include total cound for each Grade, average, lowest
score, higest score are working. Can somebody please look at the code
and help me find the logic error?
import java.lang.String;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class test
{
private int countScore, lowestScore, highestScore, gradeA, gradeB,
gradeC, gradeD, gradeF;
private double percentA, percentB, percentC, percentD, percentF;
private double averageScore;
private final double HUNDRED_PERCENT = 100.00;
public static void main( String[] Args)
{
test MyObject = new test();
MyObject.operation();
System.exit(0);
}
private void operation()
{
int score=0, lowestOldScore=0, highestOldScore =0, oldScore=0,
totalScore=0;
String scoreStr="";
scoreStr = JOptionPane.showInputDialog("Enter a score in the range
of 0-100; enter a negative integer to quit..");
score = Integer.parseInt(scoreStr);
lowestScore = score;
highestScore = score;
while ( score>=0 )
{
if (score <= lowestOldScore)
lowestScore = score;
if (score >= highestOldScore)
highestScore = score;
System.out.print(new Integer(lowestScore).toString());
System.out.print("; ");
System.out.println(new Integer(highestScore).toString());
if ( (score >=90) && (score <=100) )
gradeA++;
else if ( (score >=80) && (score <=89) )
gradeB++;
else if ( (score >=70) && (score <=79) )
gradeC++;
else if ( (score >=60) && (score <=69) )
gradeD++;
// if I just use "else", it doesn't count for input '0' as a score
for grade F
else if ( (score >=0) && (score <=59) )
gradeF++;
countScore++;
lowestOldScore = lowestScore;
highestOldScore = highestScore;
totalScore += score;
averageScore = (double)(totalScore)/countScore;
scoreStr = JOptionPane.showInputDialog("Enter a score in the range
of 0-100; enter a negative integer to quit..");
score = Integer.parseInt(scoreStr);
} // end while loop
System.out.println();
System.out.println(" Total Number of scores: " + new
Integer(countScore).toString());
System.out.println();
percentA = (gradeA/countScore) * HUNDRED_PERCENT;
System.out.println("Percent of Grade A: " + new
Double(percentA).toString());
percentB = (gradeB/countScore) * HUNDRED_PERCENT;
System.out.println("Percent of Grade B: " + new
Double(percentB).toString());
percentC = (gradeC/countScore) * HUNDRED_PERCENT;
System.out.println("Percent of Grade C: " + new
Double(percentC).toString());
percentD = (gradeD/countScore) * HUNDRED_PERCENT;
System.out.println("Percent of Grade D: " + new
Double(percentD).toString());
percentF = (gradeF/countScore) * HUNDRED_PERCENT;
System.out.println("Percent of Grade F: " + new
Double(percentF).toString());
}
}
Everythign else, include total cound for each Grade, average, lowest
score, higest score are working. Can somebody please look at the code
and help me find the logic error?
import java.lang.String;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class test
{
private int countScore, lowestScore, highestScore, gradeA, gradeB,
gradeC, gradeD, gradeF;
private double percentA, percentB, percentC, percentD, percentF;
private double averageScore;
private final double HUNDRED_PERCENT = 100.00;
public static void main( String[] Args)
{
test MyObject = new test();
MyObject.operation();
System.exit(0);
}
private void operation()
{
int score=0, lowestOldScore=0, highestOldScore =0, oldScore=0,
totalScore=0;
String scoreStr="";
scoreStr = JOptionPane.showInputDialog("Enter a score in the range
of 0-100; enter a negative integer to quit..");
score = Integer.parseInt(scoreStr);
lowestScore = score;
highestScore = score;
while ( score>=0 )
{
if (score <= lowestOldScore)
lowestScore = score;
if (score >= highestOldScore)
highestScore = score;
System.out.print(new Integer(lowestScore).toString());
System.out.print("; ");
System.out.println(new Integer(highestScore).toString());
if ( (score >=90) && (score <=100) )
gradeA++;
else if ( (score >=80) && (score <=89) )
gradeB++;
else if ( (score >=70) && (score <=79) )
gradeC++;
else if ( (score >=60) && (score <=69) )
gradeD++;
// if I just use "else", it doesn't count for input '0' as a score
for grade F
else if ( (score >=0) && (score <=59) )
gradeF++;
countScore++;
lowestOldScore = lowestScore;
highestOldScore = highestScore;
totalScore += score;
averageScore = (double)(totalScore)/countScore;
scoreStr = JOptionPane.showInputDialog("Enter a score in the range
of 0-100; enter a negative integer to quit..");
score = Integer.parseInt(scoreStr);
} // end while loop
System.out.println();
System.out.println(" Total Number of scores: " + new
Integer(countScore).toString());
System.out.println();
percentA = (gradeA/countScore) * HUNDRED_PERCENT;
System.out.println("Percent of Grade A: " + new
Double(percentA).toString());
percentB = (gradeB/countScore) * HUNDRED_PERCENT;
System.out.println("Percent of Grade B: " + new
Double(percentB).toString());
percentC = (gradeC/countScore) * HUNDRED_PERCENT;
System.out.println("Percent of Grade C: " + new
Double(percentC).toString());
percentD = (gradeD/countScore) * HUNDRED_PERCENT;
System.out.println("Percent of Grade D: " + new
Double(percentD).toString());
percentF = (gradeF/countScore) * HUNDRED_PERCENT;
System.out.println("Percent of Grade F: " + new
Double(percentF).toString());
}
}