Results 1 to 3 of 3
Thread: Need help writing a FracCalc
- 10-27-2012, 11:35 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 1
- Rep Power
- 0
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.
- 10-28-2012, 02:51 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Re: Need help writing a FracCalc
Here's a suggestion for a first step.you 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.)
Similar Threads
-
Writing GUI
By asai in forum New To JavaReplies: 5Last Post: 02-11-2012, 08:42 PM -
Need Help W/ Writing to DB.
By Sabinno in forum JDBCReplies: 2Last Post: 05-26-2011, 09:25 AM -
writing to ram
By Timmins in forum New To JavaReplies: 0Last Post: 04-03-2011, 08:52 AM -
Im writing to a file and i want to skip lines while writing to a text file.
By Broden_McDonald in forum New To JavaReplies: 1Last Post: 02-27-2010, 01:29 AM -
Writing in XLS
By selva.bics in forum Advanced JavaReplies: 1Last Post: 11-09-2009, 09:09 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks