Answered step by step
Verified Expert Solution
Link Copied!

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions