Compiling error

  • 13 years ago

    Hi, I am having problems when I call getUnion.
    The error message are "getUnion(IntergerSet) in IntergerSet cannot be applied to ()" and "incompatible types"
    where the arrows are.
    Here is my code:

    public void inputSet ()
     {
      Scanner input = new Scanner (System.in);
          
         int value;
         boolean arraySet[] = new boolean[100];
         do
         {  
          System.out.println("\nPlease enter a value or -1 to finish: ");
          value = input.nextInt();
          if(validEntry(value))
           arraySet[value] = true;
          else
           System.out.printf("\nYou enter %d to finish entering values", value, "\n");
         }while(value != -1);
         
         System.out.println("\n\nIf you want to find the union of two sets press 'u': ");
            String unionSets = input.next();
            if("u".equalsIgnoreCase(unionSets))
    --->         System.out.printf("\nUNION", getUnion());
             
        }
       
        //Finding the union of two sets
        public String getUnion(IntergerSet other)
        {
         IntergerSet res = new IntergerSet();
          
         for(int i=0; i<SIZE; i++) 
         {
          res.arraySet[i] = this.arraySet[i]||other.arraySet[i];
         }
    --->     return res;
     }

  • 13 years ago

    There is no overloaded form of getUnion which takes 0 parameters. you only have one which takes 1 parameter. System.out.printf("\nUNION", getUnion()); generates an error because you make a call to getUnion without passing it any argument.

    return res; fails because the type of the method is String and you're trying to return an IntergerSet. change the type of the function to either IntergetSet or make the function return a string. Or overload the toString() method in IntergerSet to make it return what you would view as a string interpretation of the class and then add res.toString() as return.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.” - Edward V Berard