Skip to main content
RISC
  • Home
  • More
English ‎(en)‎
Deutsch ‎(de)‎ English ‎(en)‎
You are currently using guest access
Log in
RISC
Home
Expand all Collapse all
  1. PractSoftTech15
  2. Exercises
  3. Exercise 4 (Generic Types)

Exercise 4 (Generic Types)

Completion requirements
Opened: Thursday, 23 April 2015, 5:00 PM
Due: Saturday, 2 May 2015, 6:00 AM

Implement a Generic Class Duple:

Implement a generic class which represents a duple of two numbers of the same type.
  • The class should accept all the subtypes of java.lang.Number.
  • Both numbers are of the same type.
  • Implement the following interface:
    /**
    * This interface defines methods to obtain the signum of two numbers.
    */
    public interface Signum {
    /**
    * Returns the signum of the first number. That is, -1 for negative values,
    * 1 for positive values, and 0 otherwise.
    */
    int signumFirst();
    /**
    * Returns the signum of the second number. That is, -1 for negative values,
    * 1 for positive values, and 0 otherwise.
    */
    int signumSecond();
    }
  • Provide a constructor with the two numbers as its arguments, and follow the concept of encapsulation. I.e. provide methods to get (the so called Getter) and set (the so called Setter) the values of the numbers.

Hint:

You can use the abstract method doubleValue from java.lang.Number to determine whether a given number is positive, negative, or zero.

You are currently using guest access (Log in)
Data retention summary
Get the mobile app
Powered by Moodle