Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pleazze do it soon.... System.out.println(tPrint.numerator+T+tPrint.denominator): public static void negate(Rational test) { test.numerator = test.numerator -1; if (test.denominator = 0) { test.numerator = test.numerator -1; test.denominator

Pleazze do it soon....

image text in transcribedimage text in transcribed

System.out.println(tPrint.numerator+T+tPrint.denominator): public static void negate(Rational test) { test.numerator = test.numerator -1; if (test.denominator = 0) { test.numerator = test.numerator -1; test.denominator = test.denominator -1: } public static void invert(Rational test) { int tempN = test.numerator. int temp = test.denominator; test.numerator = tempD; test.denominator = tempN: } public static double toDouble(Rational test) { double retval = (double) test.numerator / (double) test denominator; return retval public static void reduce(Rational test) { int remain, num 1, num2: num1 = test.numerator: num2 = test.denominator; remain = num1 % num2; while (remain !=0){ remain = num1 % num2; num1 = num2; num2 = remain: } int GCD = num; Rational ret = new Rational(test.numerator / GCD, test.denomirator / GCD): printRationaliret): 1 public static Rational add(Rational test. Rational testAdd) { Rational retAdd new Rational, 0); if (test.denominator == testAdd.denominator) { retAdd.numerator = test.numerator + testAdd.numerator, retAdd.denominator = test denominator; return retAdd; } else { retAdd.numerator = test.numerator testAdd.denominator; retAdd.denominator = test denominator testAdd.denominator, testAdd.numerator = testAdd.numerator test.denominator; testAdd.denominator = testAdd. denominator test denominator; retAdd.numerator += testAdd.numerator; int remain, num1num2: num1 = retAdd.numerator, num2 = retAdd.denominator: remain = num1 % num2; while remain !=0){ remain - num 1% num2; num1 = num2; num2 remain: } int GCD = num 1: retAdd.numerator = retAdd.numerator / GCD; retAdd.denominator = retAdd.denominator / GCD; return retAdd: C Question: Java-----&Gt Please Modify The Code Below. Please Read! one n. Please Read!!!!!!! *** Please Read!!!!!!! This Will Be Different From The Old Version That You Can Easily Find From Chegg. I Already Put The Answer To The Old Version Below (Please This problem has been solved! See the answer Java-----> Please modify the code below. *********** Please read!!!!! ***** ************** Please read!!!!!!! ************** Please read!!!!!!! This will be different from the old version that you can easily find from Chegg. I already put the answer to the old version below (please modify from it---please!!!!) You guys need to update the code with the description below. MARINIR. Please read!!!!!!! **** ******************* Please read!!!!!!! KIRIKKALE KIRI RI*t. Please read!!!! Task 4 - Creative Java Project A rational number is a number that can be represented as the ratio of two integers. For example, 23 is a rational number, and you can think of 7 as a rational number with an implicit 1 in the denominator or 7/1. Continue from Lab 4: (You can see the code from Lab 4 below) 1. Make the instance variables private and create a proper accessor and mutator methods to get and set the instance variables. 2. Write three constructors that, 1. one takes two arguments and sets the numerator and denominator with these two parameters. This constructor should call the reduce method to always reduce the rational to its simplest form. 2. one takes one argument and sets the numerator to this number and denominator to 1. This constructor should call the first constructor with two arguments, using this 3. one that takes no argument and sets both numerator and denominator to 1. This constructor should call the first constructor with two arguments using this 3. Write a void recursive method named reduce that reduces a rational number to its lowest terms by finding the greatest common divisor (GCD) of the numerator and denominator and dividing through. This method should be a mutator and should modify the instance variables of the object on which it is invoked. Hint Finding the GCD only takes a few lines of code. Search the web for 'Euclidean algorithm'. 4. Write a main method that creates a new object with type Rational, sets its instance variables to some values, and displays the object. -The code from Lab 4 public class Rational int numerator, denominator, public static void main(String[] args) { Rational test = new Rational.0); Rational testAdd = new Rational(10.20): reset test): printRational(test): reset(test): negate(test); printRational(test): reset(test): invert(test); printRational(test): reset(test): double doubleValue = toDouble(test); System.out.println(doubleValue) reset(test): reduce(test): printRational(add(test, testAdd)): public Rational { this.numerator = 0 this.denominator = 1; } public Rational(int n, int d) { this numerator = 0, this.denominator = d. } public static void reset(Rational test) { test.numerator = 10: test.denominator = 20; } public static void printRational (Rational tPrint) {

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions