need help with interface use

Please help for put the interface working well

Page 1 of 1

5 Replies - 533 Views - Last Post: 11 May 2009 - 08:56 PM Rate Topic: -----

#1 bonkerspr  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 92
  • Joined: 05-December 08

need help with interface use

Posted 11 May 2009 - 06:51 PM

I am making a Final project for my Object Oriented class.

on my class library i have already the interface and the methods declare but we need some help for implements

for example i have:
public class Library implements Searchable {

public Object getKey(){
	//how to implements here
}
}



the Searchable class have:

public interface Searchable {

 
public abstract Object getKey();

}



Is This A Good Question/Topic? 0
  • +

Replies To: need help with interface use

#2 gigantic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 13-April 09

Re: need help with interface use

Posted 11 May 2009 - 06:55 PM

by looking at the code, what i understood is the method in your interface
public abstract Object getKey();

}


should return an object type.
but you are not returning the object type in your Library class.
public class Library implements Searchable {

public Object getKey(){
	//here you should return an object type
}
}



do whatever you want in the getkey() method based on your requirement and then return an object datatype.

then it should work
hope it works for you
Was This Post Helpful? 0
  • +
  • -

#3 bonkerspr  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 92
  • Joined: 05-December 08

Re: need help with interface use

Posted 11 May 2009 - 07:19 PM

Yes but can you give any example how hot to implements that method for return an object ?
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: need help with interface use

Posted 11 May 2009 - 07:32 PM

View Postbonkerspr, on 11 May, 2009 - 06:19 PM, said:

Yes but can you give any example how hot to implements that method for return an object ?

And what type of getKey() ius supposed to return ?

If getKey() had a keyId as parameter I would understand

String[] book = {"Gulliver at Liliput", "Robinson Crusoee", "I love Java"};
int[] isbn = {123456, 654321, 123654};

Object getKey(id) {
   for(int i = 0; i < isbn.length; i++) {
	  if(id == isbd[i])   // book found
		return book[i];
   }
// book not found
return  null;
}


Was This Post Helpful? 0
  • +
  • -

#5 bonkerspr  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 92
  • Joined: 05-December 08

Re: need help with interface use

Posted 11 May 2009 - 08:35 PM

it should return an object
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: need help with interface use

Posted 11 May 2009 - 08:56 PM

View Postbonkerspr, on 11 May, 2009 - 07:35 PM, said:

it should return an object

String is an object
May be you can an array of Book(that contains Title, Author, Isbn) and return a Book

This post has been edited by pbl: 11 May 2009 - 08:58 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1