Question: Write a program that works with fractions. You are first to implement three methods, each to perform a different calculation on a pair of fractions:

Write a program that works with fractions. You are first to implement three methods, each to perform a different calculation on a pair of fractions: subtract, multiply, and divide. For each of these methods, you are supplied two fractions as arguments, each a two-dimensional array (the numerator is at index 0, the denominator is at index 1), and you are to return a resulting, simplified fraction as a new two-dimensional array (again, with the numerator at index 0, and denominator at index 1). You have been provided an add method as an example. You must compute the resulting fraction using fraction-based math (working with numerators and denominators) do not convert the fractions to double values (like 1.5), do the math, and convert back to a fraction. You have been provided a method to simplify a fraction using the gcd method a previous last lab. As a reminder for fraction arithmetic ! ! + ! ! = !! + !! !! ! ! ! ! = !! !! !! ! ! ! ! = !! !! ! ! ! ! = !! !! Once the operation methods are complete and pass the JUnit tests, now focus your attention on the main method. You first need to input the two fractions from the keyboard (numerator then denominator for each; you can assume integers) as well as one of the four valid operations (+, -, *, /). Then validate the inputs: make sure a valid operation was input, make sure neither of the denominators are zero, and make sure that the numerator of the second fraction isnt zero if the operation is division (error messages have been provided for each of these situations). Finally, compute the result of the operation and output the answer. Note that if the denominator of the answer is 1, you should just output the numerator (this includes if the answer is 0). Here are two example runs of the program:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!