473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

ClassTypeIsSame

6
i was assign to this project and here's the problem:

"Determines if the pair of objects contained in the array is of the same class target array of objects. The array can contain nulls. Returns true if the objects contained in the array are ofthe same class, false otherwise..."

public boolean validate(Object target)

and that's the method, i should use..

pls help me i need that ASAP.. tnx very much appreciated if you could help me now.. ehhehe tnx again.. Godbless
Oct 2 '07 #1
6 1621
Ganon11
3,652 Expert 2GB
OK, what work have you done to implement this function?
Oct 2 '07 #2
smile
6
Expand|Select|Wrap|Line Numbers
  1. Object normTarget[];
  2.         normTarget = (Object[])target;
  3.  
  4.  
  5.         for(int x=0; x<=normTarget.length; x++)
  6.         {
  7.             if((normTarget[x].getClass()).equals(normTarget[x+1].getClass()))
  8.  
  9.             return true;
  10.  
  11.         }
  12.         return false;
  13.      }

as of now, im still with this problem, actually this is a big project and my assignment is just one of those method we need to accomplish... and now, i have error "nullpointer"..
Oct 2 '07 #3
Ganon11
3,652 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. Object normTarget[];
  2.         normTarget = (Object[])target;
  3.  
  4.  
  5.         for(int x=0; x<=normTarget.length; x++)
  6.         {
  7.             if((normTarget[x].getClass()).equals(normTarget[x+1].getClass()))
  8.  
  9.             return true;
  10.  
  11.         }
  12.         return false;
  13.      }

as of now, im still with this problem, actually this is a big project and my assignment is just one of those method we need to accomplish... and now, i have error "nullpointer"..
First, please use [code] tags surrounding your code - if you're not sure how to use them, you can find a section about them in our FAQ, found under the Help link at the bottom of your window.

Now, this loop isn't working properly - basically, it's saying that if any pair of Objects in this array have the same class, then all of them must be of the same class. You should be checking if they are unequal inside the loop - if so, return false. If the whole loop executes without having returned a value, they must all be the same - return true.
Oct 2 '07 #4
smile
6
so, i wont be checking if they are the same, but rather, i'd check if not?!!
Oct 2 '07 #5
Ganon11
3,652 Expert 2GB
Exactly .
Oct 2 '07 #6
smile
6
thanks!! i'll try to solve it
Oct 2 '07 #7

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.