Question
Hello guys, Please I need help for this homework in Java language: Assignment Rational Numbers Objects, Classes and Methods PROGRAM SPECIFICATIONS For this assignment you
Hello guys, Please I need help for this homework in Java language:
Assignment Rational Numbers 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 Additional methods you deem necessary 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 array of rational objects. Code to load the array with Rationals. Values are: 2/3, 2/18, 3/12, 9/3, 2/5, and 22/7 (note you must load the array with enlarged fractions like 2/18 and your program will reduce the fraction during object construction.) After loading the array of Rational number objects, a menu is continually displayed. The menu will have the following options: 1. Display the value of a Rational object. Prompt for the index. 2. 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.) 3. 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.) 4. 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.) 5. Sort the array of Rational number objects. Use a sort method from your SortSearchUtil class. 6. Print the array of Rational number objects to the screen. 7. 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started