Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface

 
yom Kipp
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
How do I write the method:
public Element head(){}
(returns the first element of the list. This element becomes the actual element.If the list is empty isEmpty ==true then head() returns the null object.)
The code is:
import java.*;
import java.lang.*;
class RentalCarStock implements List{
private static Car[] cars;
private int pos = -1,top= -1;
public RentalCarStock(){
cars = new Car[20];
}

public Element head(){}
}

public interface Element {
public boolean equals(Element toCompareWith);
public boolean lessOrEqual(Element toCompareWith);
}

public interface List {
public Element head();
}
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd better finish your assignment by yourself.
 
yom Kipp
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Roseanne
I would not ask if I know how to do this.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the old days, students did linked list in Pascal/C, it is much harder to do in those languages. In Java, it is much easier. Give you a hint, go to JDK util package, the linked list is already implemented there, not exactly as your teacher wants, but it would be a pretty good teacher for you. It is not a good idea to throw your teachers assignment and code stems here, and wish Java professionals doing it for you.
Roseanne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic