Computer Science & Engineering 501
Lab Assignment 2


http://www.cs.wustl.edu/~sck/501/current-semester/lab/lab2/

Lab number 2: Rational Computation

Assigned: January 22, 2008
Demo: February 5, 2008
Due date: February 7, 2008

Objective:

Fractions are very useful when doing calculations and often are the most natural way to express a quantity. Under the right circumstances, they can provide more accurate computations than floating point arithmetic. This assignment requires that you implement the functionality of rational numbers (i.e., fractions) so that this can become a useful and reusable class in other Java programs.

Once you have completed this assignment, you will understand how classes are designed and specified in Java. You will know how to implement and test methods that define behavior for the objects that you have created. You will appreciate the difference between mutable and immutable classes. You will have written your first sizeable Java program and begin to understand the concept of object orientation.

Preparation:

  1. Portions of Ch. 4 of Core Java which discusses the creation and instantiation of classes in Java are relevant to this assignment.
  2. Portions of the Java tutorial on Classes are relevant to this assignment.
  3. Portions of the wikipedia discussion on Fractions may be useful in reviewing the operations of fractions.
  4. Review class notes and examples. Some hints for how best to perform labs are always given in class.
  5. Review the Style Guide to make sure you are not violating any of the style principles that make programs better organized and easier to read.

Assignment:

Develop a rational number package, which contains an immutable class named Rational, to support manipulation of fractional values. You should include the following methods in your implementation:

Computation:

The proper formulas to use should be obvious to a great extent, but some of them will be discussed in class. The numerator and denominator values are stored in two integer variables. Use accessor methods to access those values.

Hints: Do not try to do define all of the methods at once. Here are some ideas:


Extras:

To receive a maximum score out of 80%, you may simply complete the assignment as described above.
To be eligible to receive a score out of 100%, you must complete at least some of the following extra parts. The quality and quantity of the extra work will determine how many points are awarded.

Note about extras: We encourage you to attempt at least the easier problems. Points assigned for implementing extras are completely at our discretion. However, you do NOT have to implement ALL of these suggestions to earn maximum points. Both the quality and quantity of extra work will be taken into consideration. Trust us to make reasonable decisions in this regard.


Stan Kwasny (sck@wustl.edu)