Hi, i have been having a problem with this program, everytime i keep trying to fix it, another error keeps coming up, so would someone be able to sort the errors out for me please? thanks /** * Write a description of class Statistics here. * * @author (Ernie Douglus) * @version (04/10/2003) */ import java.awt.*; import javax.swing.*; import java.text.DecimalFormat;
public class Statistics { public static void main ( String args[] ) { int classTotal, mark; //hold user entered numbers int first = 0, upperSecond = 0, lowerSecond = 0, third = 0, pass = 0, fail = 0;
// for the count of each category int count=0, largest=0, smallest=100, total=0; //displaying results double average = 0.0; //float to display correct average double firstPC = 0.0, upperSecondPC = 0.0, lowerSecondPC = 0.0, thirdPC = 0.0, passPC = 0.0, failPC = 0.0; //displaying averages
String inputString; //get total in class number inputString = JOptionPane.showInputDialog( "Enter the Number of Students in the Class (0 - 20): " ); classTotal = Integer.parseInt ( inputString ); //validate this number
while (classTotal < 0 || classTotal > 20) { JOptionPane.showMessageDialog( null, "Must be between 0 and 20", "Input Error", JOptionPane.ERROR_MESSAGE ); inputString = JOptionPane.showInputDialog( "Incorrect Entry - Please Re-Enter:"); classTotal = Integer.parseInt (inputString); } if (classTotal == 0) { JOptionPane.showMessegeDialog( null, "The Program Is Closing Down", "Exit Messeage", JOptionPane.INFORMATION_MESSAGE ); } else { //get marks for (int i = 1; i <= classTotal; i++) { inputString = JOptionPane.showInputDialog( "Student Number" + i + " Mark (0 - 100): "); mark = Integer.parseInt (inputString); //validate this number while (mark < 0 || mark > 100) { JOptionPane.showMessageDialog( null, "Must Be Between 0 and 100", "Input Error", JOptionPane.ERROR_MESSAGE); inputString = JOptionPane.showMessageDialog( "Incorrect Entry - Please Re-Enter:" ); mark = Integer.parseInt (inputString); }//end while total += mark; // running total to calculate average if (mark > largest) // check for largest number largest = mark;
if (mark < smallest) // check for smallest number smallest = mark; //calculate category and increment category total if (mark >69) first++; else if (mark >59) upperSecond++; else if (mark >49) lowerSecond++; else if (mark >38) pass++; else fail++; } //end for
DecimalFormat twoPlaces = new DecimalFormat ("0.00"); //format float to 2 decimal places average = (double) total / classTotal; //ensure correct average using //cast to float //calculate percentages firstPC = ((double) first *100)/classTotal; upperSecondPC = ((double) upperSecond *100)/classTotal; lowerSecondPC = ((double) lowerSecond *100)/classTotal; thirdPC = ((double) third *100)/classTotal; passPC =((double) pass *100)/classTotal; failPC = ((double) fail *100)/classTotal;
How about a clue as to what kind of errors you are experiencing...maybe what you are doing to cause the errors ...etc also that is the most horribly formatted code ive ever seen ...very hard to read ...
you had a typo on line 48 Messege rather than Message and were trying to assign void to a String object on 65. It compiles like this ...im not going to try to figure out what this thing is sposed to do...why do i feel like im doing someones homework??
/** * Write a description of class Statistics here. * * @author (Ernie Douglus) * @version (04/10/2003) */ import java.awt.*; import javax.swing.*; import java.text.DecimalFormat;
public class Statistics { public static void main ( String args[] ) { int classTotal, mark; //hold user entered numbers int first = 0, upperSecond = 0, lowerSecond = 0, third = 0, pass = 0, fail = 0;
// for the count of each category int count=0, largest=0, smallest=100, total=0; //displaying results double average = 0.0; //float to display correct average double firstPC = 0.0, upperSecondPC = 0.0, lowerSecondPC = 0.0, thirdPC = 0.0, passPC = 0.0, failPC = 0.0; //displaying averages
String inputString; //get total in class number inputString = JOptionPane.showInputDialog("Enter the Number of Students in the Class (0 - 20): " ); classTotal = Integer.parseInt ( inputString ); //validate this number
while (classTotal < 0 || classTotal > 20) { JOptionPane.showMessageDialog(null, "Must be between 0 and 20", "Input Error", JOptionPane.ERROR_MESSAGE ); inputString = JOptionPane.showInputDialog("Incorrect Entry - Please Re-Enter:"); classTotal = Integer.parseInt (inputString); } if (classTotal == 0) { JOptionPane.showMessageDialog(null, "The Program Is Closing Down", "Exit Messeage", JOptionPane.INFORMATION_MESSAGE ); } else { //get marks for (int i = 1; i <= classTotal; i++) { inputString = JOptionPane.showInputDialog( "Student Number" + i + " Mark (0 - 100): "); mark = Integer.parseInt (inputString); //validate this number while (mark < 0 || mark > 100) { JOptionPane.showMessageDialog(null, "Must Be Between 0 and 100", "Input Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "Incorrect Entry - Please Re-Enter:" ); mark = Integer.parseInt (inputString); }//end while total += mark; // running total to calculate average if (mark > largest) // check for largest number largest = mark;
if (mark < smallest) // check for smallest number smallest = mark; //calculate category and increment category total if (mark >69) first++; else if (mark >59) upperSecond++; else if (mark >49) lowerSecond++; else if (mark >38) pass++; else fail++; } //end for
DecimalFormat twoPlaces = new DecimalFormat ("0.00"); //format float to 2 decimal places average = (double) total / classTotal; //ensure correct average using //cast to float //calculate percentages firstPC = ((double) first *100)/classTotal; upperSecondPC = ((double) upperSecond *100)/classTotal; lowerSecondPC = ((double) lowerSecond *100)/classTotal; thirdPC = ((double) third *100)/classTotal; passPC =((double) pass *100)/classTotal; failPC = ((double) fail *100)/classTotal;
> ...etc also that is the most horribly formatted > code ive ever seen ...very hard to read ...
Yours too. You just need to use the java tags as described in the Formatting Your Post in the gray box to the right, while writing your post.
For example:
Before: class IncredibleDigitAnalyzerTechnology { public static void main(String args[]) { IncredibleDigitAnalyzerTechnology idat = new IncredibleDigitAnalyzerTechnology(); for( int index = 0; index < args.length; index++ ) idat.update(args[index]); System.out.println( idat.getZeroCount() + " zero digits." ); System.out.println( idat.getOddCount() + " odd digits." ); System.out.println( idat.getEvenCount() + " even digits." ); System.out.println( idat.getOtherCount() + " other digits." ); }
private int zero = 0; private int odd = 0; private int even = 0; private int other = 0;
public void update( String s ) { for( int index = 0; index < s.length(); index++ ) switch( s.charAt(index) ) { case '0': zero++; break; case '1': case '3': case '5': case '7': case '9': odd++; break; case '2': case '4': case '6': case '8': even++; break; default: other++; break; } }
public void reset() { zero = 0; odd = 0; even = 0; other = 0; }
public int getZeroCount() { return zero; } public int getOddCount() { return odd; } public int getEvenCount() { return even; } public int getOtherCount() { return other; } }
After:
class IncredibleDigitAnalyzerTechnology
{
publicstaticvoid main(String args[])
{
IncredibleDigitAnalyzerTechnology idat = new IncredibleDigitAnalyzerTechnology();
for( int index = 0; index < args.length; index++ )
idat.update(args[index]);
System.out.println( idat.getZeroCount() + " zero digits." );
System.out.println( idat.getOddCount() + " odd digits." );
System.out.println( idat.getEvenCount() + " even digits." );
System.out.println( idat.getOtherCount() + " other digits." );
}
privateint zero = 0;
privateint odd = 0;
privateint even = 0;
privateint other = 0;
publicvoid update( String s )
{
for( int index = 0; index < s.length(); index++ )
switch( s.charAt(index) )
{
case '0': zero++; break;
case '1': case '3': case '5': case '7': case '9': odd++; break;
case '2': case '4': case '6': case '8': even++; break;
default: other++; break;
}
}
publicvoid reset()
{
zero = 0;
odd = 0;
even = 0;
other = 0;
}
publicint getZeroCount() { return zero; }
publicint getOddCount() { return odd; }
publicint getEvenCount() { return even; }
publicint getOtherCount() { return other; }
}
Good one Matt :-) I am not sure how many more time you are going to repeat this before everyone post code to this forum get that [ java][ /java] tag into their head.