| Junior Member with 3 posts. THREAD STARTER | | Join Date: Aug 2007 Experience: Beginner | |
compiling errors I have several errors when I try to build this and don't have too much experience fixing them please give me some guidance.
import java.util.*;
public class UMUC_Comparable {
public static void main(String[] args) {
Student[] studentArray = { new Student("Tom", 87),
new Student("Cindy", 100),
new Student("Pat", 75),
new Student("Anne", 92),
new Student("Matt", 82)};
Student smallestStudent;
int value = 100;
int found = 0;
int index = 0;
for(Student t : studentArray) {
if(t.getAverage() < value) {
value = t.getAverage();
found = index;
}
++index;
}
System.out.println("Smallest student = "
+ studentArray[found].getName()
+ " average = "
+ studentArray[found].getAverage());
}
}
class Student extends UMUC_Comparable {
private int average;
private String name;
public Student (String name, int average) {
this.average = average;
this.name = name;
}
public String getName() {
return name;
}
public int getAverage() {
return average;
}
public int compareTo(Student ) {
}
return (this.average - s.average);
}
}//CRR end findSmallest
static UMUC_Comparable findSmallest (UMUC_Comparable[] array )
{
UMUC_Comparable Smallest = array[0];
for (int i=1; i<array.length; ++i){
}
if (array [i].compareTo( Smallest ) < 0 );
Smallest=array[i];
}
return Smallest;
}//end
public static void main ( String[] args)
{
int studentArray1 [] = {0 , 1, 2, 3, 4};
Student studentArray[] = { new Student("Tom", 87),
new Student("Cindy", 100),
new Student("Pat", 75),
new Student("Anne", 92),
new Student("Matt", 82)};
//end function
for (int i = 0; i < studentArray.length; i++) {
//end for loop
System.out.println( "The smallest int is: " + findSmallest (studentArray1));
System.out.println ("smallest student is: " +
( (Student) findSmallest ( studentArray ) ).getName());
}
} |