Need help writing a FracCalc

OVERVIEW

You will be writing “FracCalc”, a fractional calculator that can take integers, proper and improper fractions,

and mixed fractions, and perform addition, subtraction, multiplication and division on them, then display the

resulting value as a reduced standard mixed fraction.

EXAMPLES

Input … should calculate and display:

1/4 + 1_1/2 → 1_3/4

8/4 + 2 → 4

-1 * -1/2 → 1/2

11/17 - -1/17 → 12/17

1/2 + 2/3 → 1_1/6

i just got this assignment in my AP computer science class and have no idea what to do, any help would be appreciated.

Re: Need help writing a FracCalc

Same as any programming assignment, you break down the problem into its constituent steps and then try to solve each step one at a time. I suggest that you start doing that, and then work first on the getting the input part. If you get stuck, then please come back, show us your code and ask your questions.

Re: Need help writing a FracCalc

Quote:

you break down the problem into its constituent steps and then try to solve each step one at a time

Here's a suggestion for a first step.

I notice that one of the input strings you are trying to recognise takes the form "1_1/2". It might be good to write a method that accepts a string like this and extracts its three parts (the 1 unit, the 1 numerator and the 2 denominator). What makes this slightly tricky is that there may not be a units part. Eg, "1/2" would have to be recognised as having a zero in the units place. Also (both) the numerator and denominator might be missing, as in "2" which is rather like "2_0/?" where ? is irrelevant, say 1.

Finally there could be an optional leading -. So, in fact, this step would have to analyse (the technical term is "parse") the string and extract out the four parts that are important.

Once you have precisely settled in your own mind the diverse range of the input strings, you have to come up with a precise, step by step, recipe to determine the units, numerator, denominator and whether the quantity is negative. Figure out that recipe in plain language first, and be able to explain it to others, before attempting to translate it into Java code. It will probably use the methods of the String class, so keep these in mind as you figure out an algorithm. (But, again, don't rush into code.)