Description
Note that your program must perform the following checks:
1. All the values in the second row of the array Fractions must be different than zero
2. The length of the array Operators must be n-1 where n is the number of columns of the array Fractions.
3. The only 4 characters allowed for the array Fractions are +,-,/,*
The output must be in the form of a fraction (like 13/6 of the previous example) and the fraction must be in its minimal form: for instance 2/4 becomes 1/2 or 12/30 becomes 2/5
General Info
Your project is to write a Java class which implements methods to perform symbolic computations on fractions. The input to your program will be 2 arrays which you will transform into fractions.
Methods
Write and use methods. Try not to repeat any code, create a method and call the method twice.
You must use the two methods LCM and GCD, that take as input 2 positive integers and return respectively the least common multiple and the greatest common divisor of the two given integers (Zybook has examples of these algorithms).
Examples
LCM(6,20) should return 60 and
LCM(8,20) should return 40
GCD(6,20) should return 2 and
GCD(8,20) should return 4
Testing and Commenting
Test your program with different examples, including all 4 arithmetic operators
Test your program also with input errors as described before (values of second row all different than zero, etc.)
Use succinct, thoughtful comments in your program, describe what all the different blocks or methods are doing
Use consistent indentation to make your program readable
Here is a list of methods to think about:
- Multiply 2 fractions
- Divide 2 fractions (call multiply function on the reciprocal)
- Subtract 2 fractions
- Add 2 fractions
- Return the negative of a fraction
- Simplify a fraction
- Scan in a 2D array
- Scan in a 1D array
- Overload print methods to print output as needed