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:/** 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; } } }
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]); } }
My vehicle class 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); } }