CS 341 Data Structures Homework 1 (Due via E-mail by 10:00PM, 1/26/2011)
(60 points)
- (12 pts) Exercise 17 Chapter 2.
- (6 pts) Exercise 1 Chapter 4.
- (6 pts) Exercise 3
Chapter 4.
- (6 pts) Exercise 18 Chapter 4.
- (30 pts) Consider a Java interface
called Rational that specifies the operations on rational numbers. Mathematically
a rational number is defined as the ratio of two integers, where the
denominator cannot be zero. Common
methods or operations for such an interface include:
- "set()" which sets the
numerator and denominator values of "this" Rational
- "add()" which adds a Rational
and "this" Rational and returns a third Rational without changing the value of
this Rational
- "addTo()" which adds a Rational
to "this" Rational
- "divide()" which divides "this" Rational by second Rational and returns a third Rational
- "equals()" which determines if "this" Rational is equal to the second Rational
Your tasks are:
- Provide a formal
specification of the Rational interface with the above five methods. Define
this specification as a Java interface, compile that interface, and submit the java file.
- Use Java exceptions to deal with any error situations.
- Include as part of this
specification the behavior for any constructors of a class that implements this
interface.
Note that this is a specification
not an implementation question.