Results 1 to 3 of 3
- 10-28-2012, 12:35 AM #1Member
- Join Date
- Oct 2012
- Rep Power
Need help writing a FracCalc
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.
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.
- 10-28-2012, 03:51 AM #3Moderator
- Join Date
- Feb 2009
- New Zealand
- Rep Power
Re: Need help writing a FracCalcyou break down the problem into its constituent steps and then try to solve each step one at a time
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.)
- By asai in forum New To JavaReplies: 5Last Post: 02-11-2012, 09:42 PM
- By Sabinno in forum JDBCReplies: 2Last Post: 05-26-2011, 10:25 AM
- By Timmins in forum New To JavaReplies: 0Last Post: 04-03-2011, 09:52 AM
- By Broden_McDonald in forum New To JavaReplies: 1Last Post: 02-27-2010, 02:29 AM
- By selva.bics in forum Advanced JavaReplies: 1Last Post: 11-09-2009, 10:09 AM