Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Passing objects as parameters and using this in Java: Do you remember Fractions project from last year? Find Fractions-Start project in Week 6 learning materials.

Passing objects as parameters and using this in Java: Do you remember Fractions project from last year? Find Fractions-Start project in Week 6 learning materials. Copy and paste it into Lab5 - PassingObjects. Please don't change the class names. Keep them as Fraction and Fraction Tester. Fraction class contain fields, getters, setters, overrided toString() and service methods. First, change the constructor to use the same name for the parameter as the field name. You'll have to use this in front of your field references to get this to work. Next add two new service methods addFractions and multiplyFractions. These methods should take another Fraction as a parameter and return a Fraction object. You have to add and multiply using numerators and denominators, not using decimals. You don't need to simplify the resulting fraction. You can use the following formula for addition: (a d) + (b+c) b*d You can use the following formula for multiply: ac bdbud Change your Tester to get input for two fractions instead of one, and to call addFractions and multiplyFractions. Save the fractions returned by the methods, and convert them to decimals using a Fraction method (getDecimal()) before displaying the answers. Here is the sample output: Please enter numerator: 2 Please enter denominator: 3 Please enter numerator: 4 Please enter denominator: 0 Denominator cannot be 0 Please enter denominator: 5 After Fractionl and Fraction2 are added: The fraction's numerator is: 22.0, denominator is: 15.0 and decimal version of fraction is: 1.4666666666666666 After Practionl and Praction2 are multiplied: The fraction's numerator is: 8.0, denominator is: 15.0 and decimal version of fraction is: 0.5333333333333333

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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_2

Step: 3

blur-text-image_3

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Why is it a good idea to avoid being judgmental? (p. 177)

Answered: 1 week ago