CSE 1301 Project 4: Rational Number Class, Study Guides, Projects, Research of Computer Science

A project for a cse 1301 class, where students are required to define a rational class with constructors, arithmetic and logical methods, and setters and getters. The project also includes an extra credit assignment to add a greatestcommondivisor method. Specifications and examples for the input and output of the program.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/03/2009

koofers-user-pr5
koofers-user-pr5 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 1301 Project#4
Rational Number Class
Due: Monday July 13, 2009
Define the Rational class according to the specifications given on the
handout and in class discussions
Define 3 constructors and a toString method, setters, and getters
Define arithmetic methods for add, subtract, multiply, divide, and
negate.
Define logical methods for equals, notEquals, lessThan,
lessThanOrEqual, greaterThan, and greaterThanOrEqual.
All negative values should be represented with – sign in the numerator
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
Input 2: 1/2, 16/32
Input 3: 3/-5, 2
Output (using the first set of numbers):
Rational 1 –> ½ reduced to _______
Rational 2 -> ¾ 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
pf2

Partial preview of the text

Download CSE 1301 Project 4: Rational Number Class and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CSE 1301 Project# Rational Number Class Due: Monday July 13, 2009 Define the Rational class according to the specifications given on the handout and in class discussions Define 3 constructors and a toString method, setters, and getters Define arithmetic methods for add, subtract, multiply, divide, and negate. Define logical methods for equals, notEquals, lessThan, lessThanOrEqual, greaterThan, and greaterThanOrEqual. All negative values should be represented with – sign in the numerator 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/ 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/ Input 2: 1/2, 16/ Input 3: 3/-5, 2 Output (using the first set of numbers): Rational 1 –> ½ reduced to _______ Rational 2 -> ¾ 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

Submit a UML for the whole application rather than an algorithm for main. The UML will be page 2 of the folder (after the assignment sheet). NOTE: This project is due the class day after Quiz 2 but the material on this project is covered in Quiz 2. Be sure to complete this project before the due date to be completely prepared for the quiz. I just didn’t want to make it due on the day of the quiz.