Zum Hauptinhalt
RISC
  • Startseite
  • Kalender
  • Mehr
Deutsch ‎(de)‎
Deutsch ‎(de)‎ English ‎(en)‎
Sie sind als Gast angemeldet
Login
RISC
Startseite Kalender
Alles aufklappen Alles einklappen
  1. PractSoftTech15
  2. Exercises
  3. Exercise 4 (Generic Types)

Exercise 4 (Generic Types)

Abschlussbedingungen
Geöffnet: Donnerstag, 23. April 2015, 17:00
Fällig: Samstag, 2. Mai 2015, 06:00

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.

Sie sind als Gast angemeldet (Login)
Unsere Datenlöschfristen
Laden Sie die mobile App
Powered by Moodle