Results 1 to 3 of 3
  1. #1
    gnarkill10 is offline Member
    Join Date
    Aug 2012
    Location
    Tamworth, Australia
    Posts
    42
    Rep Power
    0

    Default 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
    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;
          }
       }
    }
    My main program:

    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]);
    
      }
    }
    and my Vehicle class:

    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);
    	}
    
    
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default 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

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Compilation error

    Also posted at Compilation error
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. MIB compilation error - lexical error [0050]
    By ajuthani4@hotmail.com in forum Networking
    Replies: 0
    Last Post: 02-28-2012, 06:09 PM
  2. compilation error - pls help
    By codejava in forum New To Java
    Replies: 11
    Last Post: 09-27-2011, 09:14 AM
  3. Help with a compilation error
    By m_mccutcheon in forum New To Java
    Replies: 5
    Last Post: 08-15-2011, 05:20 PM
  4. compilation error
    By NoufalpRahman in forum Java Servlet
    Replies: 0
    Last Post: 04-26-2011, 08:08 PM
  5. bean compilation error
    By technical_helps@yahoo.com in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 07-29-2009, 11:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •