Question: How do I write a coding to the checkpoints -especially for checkpoint 2? Thank you! Fraction Calculator 1 INTRODUCTION The objective of this assignment is
How do I write a coding to the checkpoints -especially for checkpoint 2? Thank you!
Fraction Calculator 1 INTRODUCTION The objective of this assignment is to create a calculator to compute arithmetic operations between integers and/or fractions and output the result as a reduced mixed fraction. Many students have done this project and gotten working code, but cannot pass my testing because they did not follow this guide to the letter. You must provide all the static methods listed in section 6 or your project will not pass the checkpoints! 3 SPECIFICATIONS: 3.1 INPUT Input will be in the form of a value, followed by an arithmetic operator, and then another value. Values and operators will be separated by a single space. Values will contain no spaces. Input values may be in the form of mixed fractions, proper fractions, improper fractions or integers.
The integer and fraction parts of a mixed fraction will be separated by an underscore (_) (e.g., 1_3/4 is one and three fourths to distinguish it from 13/4 which is thirteen fourths).
The calculator will support the 4 basic arithmetic operations: add (+), subtract (-), multiply (*), and divide (/).
The program should accept an expression, calculate the result in the proper form, print it to screen, and then be ready to accept another expression.
The user should be able to exit the program by entering the command quit" instead of an equation.
3.2 OUTPUT The output value must always be reduced and never improper (it may be an integer, fraction, or mixed fraction, as appropriate). Example: a result of 10/4 should be printed to the screen as 2_1/2).
4 GETTING STARTED This spec sheet should be kept on hand at all times while working on your fraction calculator. Your fraction calculator will do exactly that, calculate the basic operations on fractions. Examples: Input> 1_3/4 + 5_1/4 Output> 7 Input> 5_2/3 2_1/3 Output> 3_1/3 Input> 7 * -2_1/2 Output> -17_1/2 Input> 1/2 / 3/4 Output> 2/3 1) Check Point 1: This check point is intended to b) Implement a sentinel loop: A loop checking for a quit command. c) Implement the process command method. This method will change as the program advances. At this point, you will take input from the user in the while loop and send it to the process command. d) processCommand(String input) e) To pass checkpoint 1, your input will need to return the input given. 2) Check Point 2: This check point is intended to: b) Implement the process fraction method. This method will take the users input fraction String and return it as a String in either improper fraction or proper fraction form.
The String needs to be in: I) Integer form [ex: 4 returns 4/1],
II) Fraction Form [ex 5/4 returns 5/4, & 6/4 returns 6/4] or
III) Mixed fraction form [ex 1_2/3 returns 5/3].
c) processFraction(String frac)
d) You only need to worry about positive numbers at this time (negative numbers are handled in check point 3) 3) Check Point 3: This check point is intended to: b) Change Process Fraction to accept negative values.
c) Change Process Fraction to reduce the fraction.
a. To do this the GCF function (Euclids method) will be given in class. This is a pretty cool algorithm! It will be given the day check point 2 is due.
b. Implement the Convert To Output method to accept a String and return a proper whole number, proper fraction or mixed fraction in String form i. 4/1 4, ii. 5/3 1_2/3 iii. 4/-3 -1_1/3 iv. -7/-5 1_2/5 d) convertToOutput(String frac)
e) Update the comments to the Process Fraction. Add a comment to the Convert to Output methods and the GCF method. 4) Check Point 4: b) Change Process Input to accept input in the form #_# / # + #_# / #
a. Your input must have spaces between the fractions and the operators!
b. The spaces are there for you to split the fractions and the operator. Index of the space!
c) Implement the calculation method. The calculation will accept two processed fractions in order as well as the character for the operation. a. calculation(String frac1, String frac2, char op) b. You must pass one of the four operations. 5) Final This final submission should: For this project you need to implement a few mandatory static methods to pass the checkpoints, these are listed below. You are not limited to these, but these are the minimum. You can create more helper methods, just make sure you comment each of them about your intention for them. Below is a description of the final form of the methods. These methods will be worked on throughout the project and may be different in checkpoint 1! 1) public static String processCommand(String input) a. Take a String from a user, break it apart, do calculations on it and return a String that is, A) a number, B) a proper fraction, or C) a mixed fraction. b.
EXAMPLE TEST CASES: i. 5/4 1_1/4, ii. 6/3 + 2/1 4 iii. 1_1/2 * 1/2 3/4 iv. -3/4 * 1_1/3 -1 v. 3_1/2 / 1/3 10_1/2 2) public static String processFraction(String frac) a. This method will take a String and will convert it to its numerator and denominator parts and return it in a String. It will convert a mixed fraction to an improper. It will reduce and simplify. 4 b. EXAMPLE TEST CASES: i. 1_1/4 5/4 ii. -3_2/8 -13/4 iii. 4 4/1 iv. 21/49 3/7 v. -2_7/21 -7/3 3) public static String convertToOutput(String frac) a. This method take a String with in the form of #/# and will convert to a String that is either a representation of an integer, proper fraction or a mixed fraction. b. EXAMPLE TEST CASES: i. 11/4 2_3/4 ii. -21/8 -2_5/8 iii. 4/1 4 iv. 3/4 3/4 4) public static String calculation(String frac1, String frac2, char op) a. This method will accept 2 processed fraction strings and an operator character, will convert the parts of the string to integers (numerator and denominator). It will then perform an operation indicated by the character and return a proper or improper reduced fraction as a String. b. EXAMPLE TEST CASES: i. 1 + 2 (1/1, 2/1, +) 3/1 ii. 1/2 - 3/4 (1/2, 3/4, -) -1/4 iii. 6/3 + 2/1 (2/1 + 2/1, +) 4/1 iv. 1_1/2 * 1/2 (3/2, 1/2, *) 3/4 v. -3/4 * 1_1/3 (-3/4, 4/3, *) -1/1 vi. 3_1/2 / 1/3 (7/2, 1/3, /) 21/2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
