Jump to content

Objects..

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Guest_idgeitman_*

Guest_idgeitman_*
  • Guests
Hey all,

I've been giving objects a try, but i tryed to make a little search function and it doesn't seem to be working out,


	static void mod(Vector v) {
    
     System.out.print("Reg to search: ");   
      
      String readx = new String();
         Keyboard.skipLine();
         readx = Keyboard.readString();
        
        
        	for(int i = 0; i < v.size(); i++) {

             Object p = v.elementAt(i);
              car c2 = (car)p;	
              	
    if(c2.reg == readx) 
     	 System.out.println(c2.make + "\t:\t" + c2.reg + "\t:\t" + c2.numdays + "\t:\t" + "E " + c2.cost + "\n");
   
         }

Thats the main program code, The car class is has a String called "reg" inside it. What im trying to do is get it to downcast and then compare the readx to the c2.reg and if it matches, then print out that object,

Any help would be great!

Thanks,

~ Idgeitman

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
are readx to the c2.reg strings?

#3
Guest_idgeitman_*

Guest_idgeitman_*
  • Guests
c2.reg is also a string

#4
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
I believe strings are objects and should therefor use the .equals() method to compare rather than the == operator