Mike
2011-06-07 04:36:13 UTC
I have to a program that simulates a fraction calculator. It should be menu-based and provide options for addition, subtraction, multiplication, and division. Answers have to be displayed in simplest terms.
extra notes:
• You may assume a precondition that user input will be “correct”, i.e., only consist of integers and, if applicable, a slash (fraction bar).
• Input may be a fraction or integer only, i.e., both 2/3 and 3 are both legal inputs. Your program needs to be able to recognize whether a fraction or just an integer is entered and deal with them appropriately. Suggestion-append “/1” to an input integer to make it into a fraction.
• All answers should be in simplest terms.
o 1/2, not 3/6
• If answer is a whole number (including 0), output should reflect so.
o 1, not 4/4
o 3, not 3/1
o 0, not 0/5
• Program should work for negative values
• Error checking should be used to ensure non-zero denominators
• Methods should be used
• Watch out for negatives:
o -2/3, not 2/-3
o 2/3, not -2/-3
• Fractions should be entered as String objects, then split into the fraction components using String and Integer methods.