Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello I could use a bit of help with this one, thank you so much for the help. /** * A class that represents a

Hello I could use a bit of help with this one, thank you so much for the help.image text in transcribed

/** * A class that represents a rational number. * * @author Charles Hoot * @version 5.0 */

public class Rational { // PUT PRIVATE DATA FIELDS HERE

/** * The default constructor for objects of class Rational. Creates the rational number 1. */ public Rational() { // ADD CODE TO THE CONSTRUCTOR }

/** * The alternate constructor for objects of class Rational. Creates a rational number equivalent to n/d. * @param n The numerator of the rational number. * @param d The denominator of the rational number. */ public Rational(int n, int d) { // ADD CODE TO THE ALTERNATE CONSTRUCTOR } /** * Get the value of the Numerator * * @return the value of the numerator */ public int getNumerator() { // CHANGE THE RETURN TO SOMETHING APPROPRIATE return 0; } /** * Get the value of the Denominator * * @return the value of the denominator */ public int getDenominator() { // CHANGE THE RETURN TO SOMETHING APPROPRIATE return 0; }

/** * Negate a rational number r * * @return a new rational number that is negation of this number -r */ public Rational negate() { // CHANGE THE RETURN TO SOMETHING APPROPRIATE return null; }

/** * Invert a rational number r * * @return a new rational number that is 1/r. */ public Rational invert() { // CHANGE THE RETURN TO SOMETHING APPROPRIATE return null; }

/** * Add two rational numbers * * @param other the second argument of the add * @return a new rational number that is the sum of this and the other rational */ public Rational add(Rational other) { // ADD NEW CODE AND CHANGE THE RETURN TO SOMETHING APPROPRIATE return null; } /** * Subtract a rational number t from this one r * * @param other the second argument of subtract * @return a new rational number that is r-t */ public Rational subtract(Rational other) { // CHANGE THE RETURN TO SOMETHING APPROPRIATE return null; }

/** * Multiply two rational numbers * * @param other the second argument of multiply * @return a new rational number that is the sum of this object and the other rational. */ public Rational multiply(Rational other) { // ADD NEW CODE AND CHANGE THE RETURN TO SOMETHING APPROPRIATE return null; } /** * Divide this rational number r by another one t * * @param other the second argument of divide * @return a new rational number that is r/t */ public Rational divide(Rational other) { // CHANGE THE RETURN TO SOMETHING APPROPRIATE return null; } /** * Put the rational number in normal form where the numerator * and the denominator share no common factors. Guarantee that only the numerator * is negative. * */ private void normalize() { // ADD CODE TO NORMALIZE THE RATIONAL NUMBER } /** * Recursively compute the greatest common divisor of two positive integers * * @param a the first argument of gcd * @param b the second argument of gcd * @return the gcd of the two arguments */ private int gcd(int a, int b) { int result = 0; if(a

/** * The counter class implements a counter that will roll over to the initial * value when it hits the maximum value. * * @author Charles Hoot * @version 5.0 */ public class Counter { // PUT PRIVATE DATA FIELDS HERE

/** * The default constructor for objects of class Counter. Minimum is 0 and the maximum * is the largest possible integer. */ public Counter() { // ADD CODE FOR THE CONSTRUCTOR } /** * The alternate constructor for objects of class Counter. The minimum and maximum values are given as parameters. * The counter starts at the minimum value. * @param min The minimum value that the counter can have * @param max The maximum value that the counter can have * */ public Counter(int min, int max) { // ADD CODE FOR THE ALTERNATE CONSTRUCTOR } /** * Determine if two counters are in the same state * * @param otherObject the object to test against for equality * @return true if the objects are in the same state */ public boolean equals(Object otherObject) { boolean result = true; if (otherObject instanceof Counter) { // YOUR CODE GOES HERE } return result; }

/** * Increases the counter by one */ public void increase() { // ADD CODE TO INCREASE THE VALUE OF THE COUNTER } /** * Decreases the counter by one */ public void decrease() { // ADD CODE TO INCREASE THE VALUE OF THE COUNTER } /** * Get the value of the counter * * @return the current value of the counter */ public int value() { // CHANGE THE RETURN TO GIVE THE CURRENT VALUE OF THE COUNTER return -50; } /** * Accessor that allows the client to determine if the counter * rolled over on the last count * * @return true if the counter rolled over */ public boolean rolledOver() { // CHANGE THE RETURN TO THE ROLLOVER STATUS OF THE COUNTER return true; } /** * Override the toString method to provide a more informative * description of the counter * * @return a descriptive string about the object */ public String toString() { // CHANGE THE RETURN TO A DESCRIPTION OF THE COUNTER return ""; } } You are going to need both of these programs, once again thank you so much

In this lab you will explore constructing and testing an object. Refer to the for background on this lab. Note that we will NOT be going through the Pre-Lab Visualization or Post-Lab Follow-Ups exercises described in the lab manual. Students should focus on completing the implementation of the starting code following the steps in the Directed Lab Work section of the manual so that the included JUnit tests pass. To get started, download the Eclipse Project Lab 1 Objects.zip and import into Eclipse. This lab has two JUnit G_test classes named RationalTest and CounterTest. To complete the lab, you will need to extend the implementation of the classes Rational and Counter so that the JUnit tests pass, following the Directed Lab Work steps outlined in the lab manual. You should NOT modify the JUnit test code although you may wish to uncomment the @Disabled JUnit annotations to disable tests that you are not working on. To get 8 points out of 10 for the lab, Rational.java should be complete and correct. You may optionally implement Counter.java for up to 2 points. When you have completed the lab, you should submit the Eclipse Project files Rational.java and Counter.java (if implemented) as the solution to this assignment. If you are unable to complete the lab in class, you should still submit your files with a comment that the lab is incomplete. You are welcome to complete the lab either on your own device or in class during Office Hours. Note! Due to time constraints, please just implement and submit Rational.java for full credit. Hints - When calling the gcd method in your normalize method implementation, make sure to use the Math.abs G_method to avoid passing any negative values to gcd. - To implement the Rational division method, consider calling the multiply method passing the inverted value of the other Rational object. You can implement Rational division this way due to the following relationship: yxba=yxab - Recall that to add two fractions, you need to use a common denominator, add the numerators, then reduce the number and denominator by the greatest common divisor. yx+ba=ybxb+ybay

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

7. What decisions would you make as the city manager?

Answered: 1 week ago

Question

8. How would you explain your decisions to the city council?

Answered: 1 week ago