Help with Java Programming

Associate
Joined
25 May 2006
Posts
13
Hi Guys,

I'm hoping (and praying) someone will be able to help me here.

I'm trying to teach myself a bit of Java coding before starting a programming course in the next few weeks. I'm OK with simple programs but am struggling with some of those which are a little more advanced (for me at least).

Lately, I've been battling with this question from an example exam paper I found, but really am having trouble figuring out even where to start.


"Consider the following Java Library interface


public interface Comparable<T>

{

int compareTo(T rhs);

}


Complete the implementation of the class below that implements the above interface. The compareTo method should return -1 if value is less than rhs.value, 0 if both sides are equal and +1 if value is greater than rhs.value.


public class MyInt implements Comparable<MyInt>

{

private int value;


MyInt(int x) {...}

public String toString() {...}

public int intValue() {...}

public int compareTo(MyInt rhs){...}

public boolean equals(Object rhs) {...}

}


Would anyone be kind enough to show me how they'd go about it (assuming it's not too time consuming)? Or at least explain how to go about it? At least then I'd be able to go through it and see how it's done.

Thanks very much for any help.
 
Last edited:
Lame it may be, and I'm sorry to have to do it but if you understood the difficulties I'm having with Java then you might appreciate my position a bit better. The truth is unfortunately that I don't have anything so far. I have been able to write very simple programmes (ie, get methods, if statements etc) but I was hoping that someone would be able to show me how a more complex one was done -- I don't really want to start this course with no experience of Java at all.

I'm sure it's very easy to hardened Java programmers, but as Subliminal Aura so eloquently put it, I am indeed a Noob :)
 
Back
Top Bottom