Results 1 to 3 of 3
Thread: Compilation error
- 08-05-2012, 02:25 PM #1
Member
- Join Date
- Aug 2012
- Location
- Tamworth, Australia
- Posts
- 42
- Rep Power
- 0
Compilation error
Can someone please explain why I am getting this compilation error?
C:\Users\Benni\Documents>cd comp132/assignment2
C:\Users\Benni\Documents\Comp132\assignment2>javac VehicleTest.java
VehicleTest.java:32: insertionSort(int[]) in VehicleObjectInsertionSorter cannot
be applied to (Vehicle[],java.lang.String)
VehicleObjectInsertionSorter.insertionSort(ve,"mak e");
^
1 error
C:\Users\Benni\Documents\Comp132\assignment2>
this is my insertion sort java code
My main program:Java Code:/** The IntInsertionSorter class provides a public static method for performing an insertion sort on an int array. */ public class VehicleObjectInsertionSorter { /** The insertionSort method performs an insertion sort on an int array. The array is sorted in ascending order. @param array The array to sort. */ public static void insertionSort(int[] array) { int unsortedValue; // The first unsorted value int scan; // Used to scan the array // The outer loop steps the index variable through // each subscript in the array, starting at 1. This // is because element 0 is considered already sorted. for (int index = 1; index < array.length; index++) { // The first element outside the sorted subset is // array[index]. Store the value of this element // in unsortedValue. unsortedValue = array[index]; // Start scan at the subscript of the first element // outside the sorted subset. scan = index; // Move the first element outside the sorted subset // into its proper position within the sorted subset. while (scan > 0 && array[scan-1] > unsortedValue) { array[scan] = array[scan - 1]; scan--; } // Insert the unsorted value in its proper position // within the sorted subset. array[scan] = unsortedValue; } } }
and my Vehicle class:Java Code:public class VehicleTest { public static int MAX = 4; public static void main(String[] args) { //make instances of different vehicles (these are the vehicle objects) Vehicle carVehicle = new Vehicle("car", "Ford", "red"); carVehicle.displayMessage(); Vehicle truckVehicle = new Vehicle("truck", "Nissan", "green"); truckVehicle.displayMessage(); Vehicle busVehicle = new Vehicle("bus", "Mercedes", "white"); busVehicle.displayMessage(); Vehicle motorBikeVehicle = new Vehicle("motorbike", "Honda", "silver"); motorBikeVehicle.displayMessage(); System.out.println(""); //create an array of these Vehicles Vehicle[] ve = new Vehicle[MAX]; ve[0] = carVehicle; ve[1] = truckVehicle; ve[2] = busVehicle; ve[3] = motorBikeVehicle; System.out.println("\nOutput of array before being sorted"); for(int i = 0; i < MAX; i++) System.out.println(ve[i]); // Sort the array by vehicle make. VehicleObjectInsertionSorter.insertionSort(ve,"make"); System.out.println("\nOutput of array after being sorted by vehicle make"); for(int i = 0; i < MAX; i++) System.out.println(ve[i]); // Sort the array by vehicle type. //VehicleObjectInsertionSorter.insertionSort(ve,"type"); System.out.println("\nOutput of array after being sorted by vehicle type"); for(int i = 0; i < MAX; i++) System.out.println(ve[i]); // Sort the array by vehicle colour. //VehicleObjectInsertionSorter.insertionSort(ve,"colour"); System.out.println("\nOutput of array after being sorted by vehicle colour"); for(int i = 0; i < MAX; i++) System.out.println(ve[i]); } }
Java Code:public class Vehicle { private String type; private String make; private String colour; //Constructor public Vehicle(String t, String m, String c) { type = t; make = m; colour = c; } public void displayMessage(){ System.out.printf("The type of vehicle is a %s ", type); System.out.printf(" and the make is %s ", make); System.out.printf(" and the colour is %s\n", colour); } }
- 08-05-2012, 02:57 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Compilation error
Your insertionSort class or method expects only an integer array (insertionSort(int[] array)) and not a vehicle array + String!
the error message says that also clearly:
insertionSort(int[]) in VehicleObjectInsertionSorter cannot be applied to (Vehicle[],java.lang.String
- 08-05-2012, 03:18 PM #3
Re: Compilation error
Also posted at Compilation error
If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
MIB compilation error - lexical error [0050]
By ajuthani4@hotmail.com in forum NetworkingReplies: 0Last Post: 02-28-2012, 06:09 PM -
compilation error - pls help
By codejava in forum New To JavaReplies: 11Last Post: 09-27-2011, 09:14 AM -
Help with a compilation error
By m_mccutcheon in forum New To JavaReplies: 5Last Post: 08-15-2011, 05:20 PM -
compilation error
By NoufalpRahman in forum Java ServletReplies: 0Last Post: 04-26-2011, 08:08 PM -
bean compilation error
By technical_helps@yahoo.com in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 07-29-2009, 11:21 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks