I am having a problem with calling a method that is in a different class. This main
method is in a class on its own called lab14
, and the heapSort()
method is in a different class called HeapSort
. Both of these classes are in the default package. I am getting the error “The method heapSort(Vector) is undefined for the type Lab14” and I don’t understand why, please help.
below is the main method in the lab 14 class
public static void main(String args[]) { Heap myheap = new Heap(); Vector<StudentGPA> vec = new Vector(); int [] br = new int[20]; double [] dr = new double[20]; int i = 0; int j = 0; try { //String inputLine; //stores each line from the file Scanner scanLine; Scanner input = new Scanner(new File("students.in")); while (input.hasNextLine()){ scanLine = new Scanner(input.nextLine()); int id = scanLine.nextInt(); //br[i] = id; String name = scanLine.next(); double gpa = scanLine.nextDouble(); //dr[i]= gpa; //myStr.add(name); if(scanLine.hasNext()) { String advisor = scanLine.next(); GraduateStudentGPA grad = new GraduateStudentGPA(id,name,gpa,advisor); vec.add(grad); } else { StudentGPA reg = new StudentGPA(id,name,gpa); vec.add(reg); } i++; j++; } input.close(); } catch (IOException e) { System.out.println("IOException in reading input file!!!"+e); } heapSort(vec); }
Below is the code for the HeapSort class
public class HeapSort <E extends Comparable<? super E>>{ /** sorts the input vector using heap Sort <ul> <li> iterates * through each element of the input vector and inserts each * element to the heap by calling {\tt heapInsert}. <li> deletes * each of the inserted items by calling {\tt heapDelete} the * appropriate number of times, and fills up the vector with the * returned elements. </ul> If you are using the * minheap implementation, this insertion and deletion of all * items will produce a list of items sorted by their key * attribute values. * @param vec input vector */ public void heapSort(Vector<StudentGPA> vec){ // -- TO COMPLETE -- Heap myheap = new Heap<E>(); for(int i = 0; i <vec.size(); i++) { myheap.heapInsert(vec.elementAt(i)); } for(int i = 0; i <vec.size(); i++) { vec.setElementAt((StudentGPA) myheap.heapDelete(), i); } } }