In: Computer Science
Implement the Nickel class. Include Javadoc comments for the class, public fields, constructors, and methods of the class.
I have added the Javadoc comments but please feel free to format them if they are done incorrectly.
public class Nickel implements Comparable {
private int year;
/**
* The monetary value of a nickel in cents.
*/
public final int CENTS = 5;
/**
* Initializes this nickel to have the specified issue year.
*
* @param year
*
* @pre. year must be greater than or equal to 1858
*/
Nickel (int year){
}
/**
* Returns the issue year of this coin.
* @return
*/
public int issueYear() {
}
/**
* Compares this nickel to the specified object for equality. The result is true if obj
* is a nickel. The issue year is not considered when comparing two nickels for equality.
*
* @param obj
*
* @return
*/
public boolean equals(Object obj) {
}
/**
* Returns a hash code for this nickel. Specifically, this method returns the issue year of this nickel.
*/
public int hashCode() {
}
/**
* Compares this nickel to another nickel by their issue year.
* The result is a negative integer if this nickel has an earlier issue year than
* the other nickel, a positive integer if this nickel has a later issue year than
* the the other nickel, and zero otherwise. Specifically, this method returns the
* difference of the issue year of this nickel and the issue year of the other nickel.
*
* @param other
*
* @return
*/
@Override
public int compareTo(Nickel o) {
}
}
public class Nickel implements Comparable<Nickel> {
private int year;
/**
* The monetary value of a nickel in cents.
*/
public final int CENTS = 5;
/**
* Initializes this nickel to have the specified issue year.
*
* @param year
* @pre. year must be greater than or equal to 1858
*/
Nickel(int year) {
if (year < 1858)
throw new IllegalArgumentException();
this.year = year;
}
/**
* Returns the issue year of this coin.
*
* @return
*/
public int issueYear() {
return year;
}
/**
* Compares this nickel to the specified object for equality. The result is true if obj
* <p>
* is a nickel. The issue year is not considered when comparing two nickels for equality.
*
* @param obj
* @return
*/
@Override
public boolean equals(Object obj) {
return obj != null && getClass() == obj.getClass();
}
/**
* Returns a hash code for this nickel. Specifically, this method returns the issue year of this nickel.
*/
public int hashCode() {
return year;
}
/**
* Compares this nickel to another nickel by their issue year.
* <p>
* The result is a negative integer if this nickel has an earlier issue year than
* <p>
* the other nickel, a positive integer if this nickel has a later issue year than
* <p>
* the the other nickel, and zero otherwise. Specifically, this method returns the
* <p>
* difference of the issue year of this nickel and the issue year of the other nickel.
*
* @param other
* @return
*/
@Override
public int compareTo(Nickel other) {
return year - other.year;
}
}