1.Use CRC Cards to identify the classes, responsibilities and collaborators in your design for the Fraction calculator.
You may use any physical manifestation of CRC cards that you like, e.g. 3x5 index cards, scraps of paper, spreadsheets, or text documents.
To help you to get started, think about what's involved? Start with a calculator, identify the responsibilities and collaborators, and then work your way through the solution until you feel you have a complete solution. My solution has two classes but your solution may be different. Be sure to identify the class, the responsibilities of that class, and the collaborators.
If you choose to use 3x5 index cards (or just scraps of paper), take photos of your cards and submit those to Canvas. If you use an electronic solution, then upload the document with the classes, responsibilities and collaborators. I prefer index cards because they are easy to move around, stack, and rip up when a better idea comes along.
2.Write a Python program that includes:
class Fraction with the following methods:
a test_suite() function that demonstrates that your Fraction class works properly. For now, just use print or assertstatements to demonstrate that your code works properly. Next week we'll explore some better techniques for automating test cases.
main() function that asks the user for the first numerator and denominator, the operator, and the second numerator and denominator, then prints the result of applying the operator to the two fractions.
Be sure that your program handles error cases where the user enters invalid input for the fractions or operator.
Here's the sample output from my solution:
Welcome to the fraction calculator!
Fraction 1 numerator: 1 <-- user entered 1
Fraction 1 denominator: 2 <-- user entered 1
Operation (+, -, *, /): + <-- user entered +
Fraction 2 numerator: 3 <-- user entered 1
Fraction 1 denominator: 4 <-- user entered 1
1/2 + 3/4 = 10/8 <-- final result - The code converted 1/2 to 4/8 and 3/4 to 6/8 and returns 10/8
Here's an example of the code for one of my test cases:
f12 = Fraction(1, 2)
f44 = Fraction(4, 4)
print(f12, '+', f12, '=', f12.plus(f12), '[4/4]') # print the oo
print(f44, '-', f12, '=', f44.minus(f12), '[4/8]')
Here's the output from the test cases.
1/2 + 1/2 = 4/4 [4/4]
4/4 - 1/2 = 4/8 [4/8]
The print statement in each test case includes the expected result so the reader can easily determine if the code is working properly by comparing the computed result against the expected result.