Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Compilation error

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

     
    /**
       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:

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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Compilation error

    The compiler can not find a method named insertionSort() with the arguments coded here:
        VehicleObjectInsertionSorter.insertionSort(ve,"make");
    The only definition I see is:
      public static void insertionSort(int[] array)

    Also posted at http://www.java-forums.org/new-java/...ion-error.html
    Last edited by Norm; August 5th, 2012 at 08:19 AM.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. EJB COMPILATION ERROR(TANMAY SINHA)
    By Tanmaysinha in forum Web Frameworks
    Replies: 4
    Last Post: March 22nd, 2012, 10:58 AM
  2. "Cannot find symbol" compilation error
    By collegejavastudent in forum What's Wrong With My Code?
    Replies: 7
    Last Post: December 12th, 2011, 05:07 PM
  3. Unable to execute the program (no compilation error)
    By Alexie91 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 16th, 2011, 02:39 PM
  4. Dynamic compilation problem
    By hemanth.yerra in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 29th, 2010, 10:51 AM
  5. Replies: 6
    Last Post: April 29th, 2009, 09:35 AM

Tags for this Thread