Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

H5a Input consists of integers representing the numerator and denominator of fractions. NOTE that some numerators and some denominators will be negative. As you input

H5a

Input consists of integers representing the numerator and denominator of fractions. NOTE that some numerators and some denominators will be negative.

As you input 2 integers create a Fraction object. Your constructor should not allow negative denominators. If both numerator and denominator are negative make both positive, if the denominator is negative but the numerator is positive then flip those signs so that the numerator is negative and the denominator positive. Your constructor should also reduce the fractions.

NOTE: when trying to reduce a fraction you still need to find the biggest POSITIVE integer that divides numerator and denominator without leaving a remainder, even if your numerator or denominator is negative . So your constructor (and any other method) calls your gcd method like this:

int g = gcd(Math.abs(n), Math.abs(d)); so that the parameters are positive even if n or d are negative. (Math.abs gives you the absolute value)

After creating each Fraction object, add it to an arraylist.

Output the entire arrayList. (I want to see that your gcd method is working even for negative numbers). I DO NOT want to see any negative denominators.

At the end of your program output the biggest and the smallest Fraction (as a Fraction).

For example: The biggest Fraction was 119/120

The smallest Fraction was -2/37

Hint: Some students are having problems because they are calling the gcd method even when the numerator is zero. This leads to a problem within gcd, because it finds the smallest positive integer, which will be zero, and then tries to test if zero divides the integers leaving no remainder. So consider when to call gcd. If n==0, do you really want to write int g = gcd(n.d)??

H5

Input consists of integers representing the numerator and denominator of fractions. NOTE that some numerators and some denominators will be negative.

As you input 2 integers create a Fraction object. Output the Fraction. (I want to see that your gcd method is working even for negative numbers). I DO NOT want to see any negative denominators. If both numerator and denominator are negative make both positive, if the denominator is negative but the numerator is positive then flip those signs so that the numerator is negative and the denominator positive. This is so that you do not output 3/-4, but rather -3/4.

DO NOT store these Fractions in any data structure (such as an array or ArrayList). Just keep track of the biggest and the smallest. (Use your compareTo method to help you with this)

At the end of your program output the biggest and the smallest.

You will need to alter your Fraction class to include a compareTo method, and you will need to consider carefully how you know one fraction is less than another. (Hint: make it into a double. double one = (double) numerator/(double) denominator; )

H5.txt:

4 10 3 7 4 5 6 15 1 -4 8 23 -19 -21 1 -8 0 10 1 -12

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

Mastering Big Data Interview 751 Comprehensive Questions And Expert Answers

Authors: Mr Bhanu Pratap Mahato

1st Edition

B0CLNT3NVD, 979-8865047216

More Books

Students also viewed these Databases questions

Question

Derive expressions for the rates of forward and reverse reactions?

Answered: 1 week ago

Question

Write an expression for half-life and explain it with a diagram.

Answered: 1 week ago

Question

What do you mean by underwriting of shares ?

Answered: 1 week ago

Question

Define "Rights Issue".

Answered: 1 week ago