Question

In: Computer Science

Implement the Nickel class. Include Javadoc comments for the class, public fields, constructors, and methods of...

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) {

}

}

Solutions

Expert Solution

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;
    }
}

Related Solutions

In java, (include javadoc comments for each method) design a class named Contacts that has fields...
In java, (include javadoc comments for each method) design a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contacts objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to...
Overloaded Constructors Add a pair of constructors to the Height class that implement the initializations provided...
Overloaded Constructors Add a pair of constructors to the Height class that implement the initializations provided by the two setHeight operations in Figure 7.11. Minimize the total number of statements by having the one parameter constructor call the one-parameter setHeight method and having the two-parameter constructor call the two-parameter setHeight method. Provide a complete rewritten main method for the HeightDriver class such that the new method uses one of the new constructors from part a) to generate this output: 6.0...
Java programming! Implement a static stack class of char. Your class should include two constructors. One...
Java programming! Implement a static stack class of char. Your class should include two constructors. One (no parameters) sets the size of the stack to 10. The other constructor accepts a single parameter specifying the desired size of the stack a push and pop operator an isEmpty and isFull method . Both return Booleans indicating the status of the stack Change this cods according to instructions please: public class Stack { int stackPtr; int data[]; public Stack() //constructor { stackPtr=0;...
write the program in java. Develop a class RentCabin that does the following: (use JavaDoc comments)...
write the program in java. Develop a class RentCabin that does the following: (use JavaDoc comments) // declare the constructor that sets the type and rate based in the sqft parm        // set values based on sqft <1000 is small with $100 per night, // sqft between 1000 and 2000, mid-sized $200 per night, and // over 2000 as a large cabin with $300 per night        //declare getRate        //declare getType        //declare setRate with int rate parm...
Implement a VotingMachine class that can be used for a simple election. Include the methods to...
Implement a VotingMachine class that can be used for a simple election. Include the methods to voteForDemocrat and voteForRepublican. Add a method to clear out all votes. Additionally, add a method to print the results. Write the driver code to simulate the voting. in java
Working with arrays in our class, reinforce constructors and setters and getters and implement dynamic variables....
Working with arrays in our class, reinforce constructors and setters and getters and implement dynamic variables. Create a class called Movie that contains information about a movie. The class has the following attributes (you choose the data type for the member variables): ■ The movie name ■ The MPAA rating (for example, G, PG, PG-13, R) ■ Array of size 5 called Ratings, each index will hold the following. [0] The number of people that have rated this movie as...
Design and implement a class Rectangle to represent a rectangle. You should provide two Constructors for...
Design and implement a class Rectangle to represent a rectangle. You should provide two Constructors for the class, the first being the default constructor and the second which takes the basic dimensions and sets up the private member variables with the appropriate initial values. Methods should be provided that allow a user of the class to find out the length, width, area and perimeter of the shape plus a toString()method to print the values of the basic dimensions. Now implement...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score (int). A constructor expects a name as a parameter. A method getLevel to get the level(char) of the student. score level table: A: score >= 90 B: score >= 80 and < 90 C: score >= 60 and < 80 D: score < 60 Example:          Student student = new Student("Zack"); student.score = 10; student.getLevel(); // should be 'D'. student.score = 60; student.getLevel(); //...
class A { public: //constructors // other members private: int a; int b; }; Give declatations...
class A { public: //constructors // other members private: int a; int b; }; Give declatations of operator functions for each of the following ways to overload operator + You must state where the declatation goes, whether within the class in the public or private section or outside the class. The operator + may be overloaded. a) as friend function b) as member function c) as non-friend, non-member function
JAVA Implement a public class method named comparison on a public class Compare that accepts two...
JAVA Implement a public class method named comparison on a public class Compare that accepts two Object arguments. It should return 0 if both references are equal. 1 if both objects are equal. and -1 otherwise. (SUPER IMPORTANT) Either reference can be null, so you'll need to handle those cases carefully! Here is what I have so far: public class Compare { public static int comparison(Object a, Object b) {   if (a == null || b == null) {    return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT