Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a class definition for the following scenario. You have to write a class called MyFraction which works on fractions of the form a/b
Write a class definition for the following scenario. You have to write a class called MyFraction which works on fractions of the form a/b where a represents the numerator and b represents the denominator. Both a and b are integers (i.e. if a = 1 and b = 2, then the fraction will be 1/2). Your class should perform the following operations: 1. Create two constructors (1) with no parameters that set a = 0 and b = 1; and (2) with 2 integer parameters that sets both a and b. II. Write an instance method for addition which returns the resultant object. [int: a/b + c/d = (ad + bc)/bd] III. Write a static method for multiplication which returns the resultant object. [Hint a/b * c/d = ac/bd] IV. Write a static main() that allocates two Fractions, 1/2 and 3/4 and stores their sum in a third variable.
Step by Step Solution
★★★★★
3.41 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
Here is a class definition for the scenario described java public class MyFraction private int numer...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started