Description
ArrayLists, Objects, Classes and Methods
PROGRAM SPECIFICATIONS
For this assignment you will need to write two classes. The first class will be
named Rational.java. A rational number is a fraction, it has a numerator and a denominator. The details of the Rational class are below. The
second class will be named RationalDriver.java. This class will contain the main method. The details of the RationalDriver class are also below.
Rational.java

Default value constructor that sets the numerator to 1 and the denominator to 1

Explicit value constructor that sets the numerator and denominator to values specified by the user

Get Methods

Set Methods

A toString Method

An equals Method

An add Method

A subtract Method

A reduce method (used internally)

Data variables appropriate to a rational class
RationalDriver.java
The RationalDriver class will create and manipulate objects of type ‘Rational’. The class will contain the main method and will accommodate the following:

An ArrayList of rational objects.

Code to load the ArrayList with Rationals. Values are: 2/3, 2/18, 3/12, 9/3, 2/5, and 22/7
(note you must load the ArrayList with enlarged fractions like 2/18 and your program will reduce the fraction during object construction.)

After loading the ArrayList of Rational number objects, a menu is continually displayed.
The menu will have the following options:


Display the value of a Rational object. Prompt for the index.

Eastern Washington University

Change the value of a rational. Prompt for the index of the Rational to be changed, and then the new denominator and new numerator. (You may wish to create a new Rational object to accomplish this.)

Add two Rational objects together and display the sum as a new Rational object. (Prompt for two index values that indicate the two Rationals to be added.)

Subtract two Rational objects and display the difference as a new Rational object. (Prompt for two index values that indicate the two Rationals. The second will be subtracted from the first.)

Sort the array of Rational number objects. Use a sort method from the Java API

Determine if a particular Rational object is in the ArrayList

Print the array of Rational number objects to the screen.

Quit
Note: all rational numbers will be in their reduced form. If the user enters 2/4 the rational number that will be displayed is 1/2.
You are guaranteed that an integer will be entered for the numerator and the denominator. A rational number can be negative.
HINTS

Solve the problems systematically testing as you go

You should be able to write the get, set and default value constructor.

As we cover topics in class you should make the appropriate changes to your code.
TO TURN IN (via the Canvas system)

• A zip file that contains both .java files necessary to run your program.
Eastern Washington University