# Defining a rational class. Simple but i cant figure it out to save my life

• October 26th, 2011, 09:48 PM
spetillo3
Defining a rational class. Simple but i cant figure it out to save my life
Define 3 constructors and a toString method, setters, and getters
Define arithmetic methods for add, subtract, multiply, divide, and negate. The negate method will return the negative of the calling Rational object – return new Rational (-num,denom);
Define logical methods for equals, notEquals, lessThan, lessThanOrEqual, greaterThan, and greaterThanOrEqual.

All negative values should be represented with the negative sign in the numerator – do this in the setDenom method and call it in the constructor.

Extra Credit: add a greatestCommonDivisor method to reduce a Rational number to its lowest terms. If you write this method, add the reduced values to your output. For example:
½ + ¾ = 10/8 reduced to 5/4

Run three times with the following data: (read in the data then use one of the constructors or the setter methods to fill objects with data)

Input 1: 1/2, 3/4 - entered as 1 2 3 4

Input 2: 1/2, 5/10 – entered as 1 2 5 10

Input 3: 3/-5, 2 – entered as 3 -5 2 1

Output (using the first set of numbers):

Rational 1 –>1/2 reduced to _______
Rational 2 -> 3/4 reduced to_______
½ + ¾ ______ reduced to_______
½ - ¾ ______ reduced to_______
½ * ¾ ______ reduced to_______
½ / ¾ ______ reduced to_______
- ½ ______ reduced to_______
½ == ¾ ______ print true or false
½ != ¾ ________ print true or false
½ > ¾ ______ print true or false
½ >= ¾ ______ print true or false
½ < ¾ ______ print true or false
½ <= ¾ ______ print true or false
• October 26th, 2011, 09:58 PM
copeg
Re: Defining a rational class. Simple but i cant figure it out to save my life
Dumping homework assignments is unproductive at best. Please see the link in my signature entitled getting help, as well as the following:
http://www.javaprogrammingforums.com...e-posting.html
• October 26th, 2011, 10:20 PM
spetillo3
Re: Defining a rational class. Simple but i cant figure it out to save my life
im not dumping it. i literally have no idea what to do to get started
• October 27th, 2011, 12:02 AM
copeg
Re: Defining a rational class. Simple but i cant figure it out to save my life
Quote:

Originally Posted by spetillo3
im not dumping it. i literally have no idea what to do to get started

Did you read the links I provided? Without knowing any context - from whether you know how to make a hello world program to whether you know loops to whether you know object oriented programming - we will have a hard time pointing you in the right direction. Break the problem down, and concentrate on one requirement at a time...ask a specific question about that requirement.