Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Need help writing a FracCalc

  1. #1
    midgetmon44 is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default 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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default 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.
    SJF likes this.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: Need help writing a FracCalc

    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.)

Similar Threads

  1. Writing GUI
    By asai in forum New To Java
    Replies: 5
    Last Post: 02-11-2012, 09:42 PM
  2. Need Help W/ Writing to DB.
    By Sabinno in forum JDBC
    Replies: 2
    Last Post: 05-26-2011, 10:25 AM
  3. writing to ram
    By Timmins in forum New To Java
    Replies: 0
    Last Post: 04-03-2011, 09:52 AM
  4. Replies: 1
    Last Post: 02-27-2010, 02:29 AM
  5. Writing in XLS
    By selva.bics in forum Advanced Java
    Replies: 1
    Last Post: 11-09-2009, 10:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •