My bubble sort doesn't work, and does anyone know
how to count and print the scores of a certain grade.... all the 90's with a's, all the 80's with b's etc.... This is my first java program with two classes. I've been messing with it for about 24hours over the last week. :O. Any suggestions?
import java.util.Scanner;
public class GradeSort {
public static void main(String [] args){
//Scanner keyboard = new Scanner(System.in);
System.out.println("How many students took the test?");
Scanner kbd = new Scanner(System.in);
int NUM_STUDENTS = kbd.nextInt();
double [] grades = new double[NUM_STUDENTS];//Assn array
readReadingsInto(grades);
System.out.printf( "\nThe average is %.3f%n", average(grades));
print(grades);}
private static void readReadingsInto(double [] array){
Scanner keyboard = new Scanner(System.in);
for (int i =0; i < array.length; i++) {
System.out.print("enter grade # " + (i+1)+ "/" );
array = keyboard.nextInt();
}}
public static double average(double [] anArray){
double sum = 0.0;
for (double item : anArray){
sum += item;
}
return sum/anArray.length;
}
public static void bubbleSort ( double [] anArray )
{
for (double i = anArray.length-1; i > 0; i-- )
{
for ( int j = 0; j < i; j++ )
{
if ( anArray[j] > anArray[j+1] )
{
double temp = anArray[j];
anArray[j] = anArray[j+1];
anArray[j+1] = temp;}
}}}
public static void print(double [] arr) {
for (int i = 0; i < arr.length; i++){
Grade gRade = new Grade(arr);
System.out.println("Reading #" + (i+1)+" " + arr + " " + gRade.letter() );
//Grade gRade = new Grade(reading);
//System.out.println( gRade.letter() );
//System.out.print ( grades[1] );
}}}
public class Grade {
public static final double MIN = 0.0;
public static final double MAX = 100.0;
public Grade(double gRade){
if (gRade < MIN || gRade > MAX){
System.err.println("Grade(): bad argument recievived: " + gRade);
} else {
myValue = gRade;
}
}
public String letter(){
if (myValue < MIN || myValue > MAX){ return "error";}
else if (myValue >= 90){return "A";}
else if (myValue >= 80){return "B";}
else if (myValue >= 70){return "C";}
else return "Fail";}
private double myValue;
}
[2518 byte] By [
McCujoa] at [2007-11-27 10:01:00]

Let me see if I can fix the formatting for you. The bubble sort, isn't sorting? The print after the sort is in the same order as I input the data.
import java.util.Scanner;
public class GradeSort {
public static void main(String [] args){
//Scanner keyboard = new Scanner(System.in);
System.out.println("How many students took the test?");
Scanner kbd = new Scanner(System.in);
int NUM_STUDENTS = kbd.nextInt();
double [] grades = new double[NUM_STUDENTS];//Assn array
readReadingsInto(grades);
System.out.printf( "\nThe average is %.3f%n", average(grades));
print(grades);}
private static void readReadingsInto(double [] array){
Scanner keyboard = new Scanner(System.in);
for (int i =0; i < array.length; i++) {
System.out.print("enter grade # " + (i+1)+ "/" );
array[i] = keyboard.nextInt();
}}
public static double average(double [] anArray){
double sum = 0.0;
for (double item : anArray){
sum += item;
}
return sum/anArray.length;
}
public static void bubbleSort ( double [] anArray )
{
for (double i = anArray.length-1; i > 0; i-- )
{
for ( int j = 0; j < i; j++ )
{
if ( anArray[j] > anArray[j+1] )
{
double temp = anArray[j];
anArray[j] = anArray[j+1];
anArray[j+1] = temp;}
}}}
public static void print(double [] arr) {
for (int i = 0; i < arr.length; i++){
Grade gRade = new Grade(arr[i]);
System.out.println("Reading #" + (i+1)+" " + arr[i] + " " + gRade.letter() );
//Grade gRade = new Grade(reading);
//System.out.println( gRade.letter() );
//System.out.print ( grades[1] );
}}}
The other class is:
public class Grade {
public static final double MIN = 0.0;
public static final double MAX = 100.0;
public Grade(double gRade){
if (gRade < MIN || gRade > MAX){
System.err.println("Grade(): bad argument recievived: " + gRade);
} else {
myValue = gRade;
}
}
public String letter(){
if (myValue < MIN || myValue > MAX){ return "error";}
else if (myValue >= 90){return "A";}
else if (myValue >= 80){return "B";}
else if (myValue >= 70){return "C";}
else return "Fail";}
private double myValue;
}
> All right I think that it is formatted with the code.
> When I print the Array it appears to be in the same
> order as I input.
See reply 5.
> I know how to print A next to a
> 90, but what I wanted do do was print 90,98,95 as an
> A, then 80, 87 as B's all the scores on on line with
> the letter grade.
Again: Figure out the simple, precise steps to do it without Java, then translate it to Java. If you want help, be specific about the problems you're having.