class Fraction private int num, denom; public Fraction(int num, int denom) (/code elided"/> public Fraction add(Fraction another){ / code elided/) public Fraction subtract (Fraction another) { / code elided / ) public Fraction multiply (Fraction another){ / code elided/1 public Fraction divide (Fraction another){ / code elided */ } public int getNumerator(){ / code elided */ } public int getDenominator() { / code elided / ) can be seate with the foll wing data combination

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Instruction:
Given the definition of methods and fields available to the Fraction class below, extend it to a Generic Mixed Number class that can perform the different arithmetic operations.
Requirement: use Fraction class methods in performing the different mixed number operations.
class Fraction
private int num, denom;
public Fraction(int num, int denom) { / code elided */ }
public Fraction add(Fraction another){ / code elided */)
public Fraction subtract (Fraction another){ /
public Fraction multiply (Fraction another){ /
code elided/)
code elided */ }
public Fraction divide (Fraction another) (/ code elided */ }
public int getNumerator (){ / code elided */ }
public int getDenominator() { / code elided +/ )
>
A mixed number can be created with the following data combination.
1.1 number - treated as the whole part, the numerator defaults to 0 and denominator defaults to 1
2.2 numbers-treated as numerator and denominator, hence whole defaults to 0
3.3 numbers-treated as whole, numerator and denominator respectively.
Examples for initialization
1. mn1 = new MixedNumber<Float>(0.25f) results into whole - 0, numerator - 1. denominator - 4
2. mn2 = new Mixed Number<Long>(341, 61) results into whole - 5. numerator - 2, denominator - 3
3. mn3 = new MixedNumber<Double>(11d, 18d, 10d) results into whole - 12, numerator - 4, denominator - 5
Operations Example
mn1 + mn2 - Mixed Number(whole 5, numerator-11, denominator - 12)
mn3 - mn2 - MixedNumber(whole-7, numerator - 2, denominator - 15)
mn3 mn1 - Mixed Number(whole 3, numerator 1, denominator - 5)
mn2/mn3 - MixedNumber(whole = 0, numerator - 85, denominator - 192)
Notes
a. all fraction operators including creation result into a correct simplified fraction (lowest terms).
b. the data in mixed number creation can be any form of a number (byte, short, int, long, float, or double)
c. Assumption is all number to entered are positive (no need to worry about negative values)
Transcribed Image Text:Instruction: Given the definition of methods and fields available to the Fraction class below, extend it to a Generic Mixed Number class that can perform the different arithmetic operations. Requirement: use Fraction class methods in performing the different mixed number operations. class Fraction private int num, denom; public Fraction(int num, int denom) { / code elided */ } public Fraction add(Fraction another){ / code elided */) public Fraction subtract (Fraction another){ / public Fraction multiply (Fraction another){ / code elided/) code elided */ } public Fraction divide (Fraction another) (/ code elided */ } public int getNumerator (){ / code elided */ } public int getDenominator() { / code elided +/ ) > A mixed number can be created with the following data combination. 1.1 number - treated as the whole part, the numerator defaults to 0 and denominator defaults to 1 2.2 numbers-treated as numerator and denominator, hence whole defaults to 0 3.3 numbers-treated as whole, numerator and denominator respectively. Examples for initialization 1. mn1 = new MixedNumber<Float>(0.25f) results into whole - 0, numerator - 1. denominator - 4 2. mn2 = new Mixed Number<Long>(341, 61) results into whole - 5. numerator - 2, denominator - 3 3. mn3 = new MixedNumber<Double>(11d, 18d, 10d) results into whole - 12, numerator - 4, denominator - 5 Operations Example mn1 + mn2 - Mixed Number(whole 5, numerator-11, denominator - 12) mn3 - mn2 - MixedNumber(whole-7, numerator - 2, denominator - 15) mn3 mn1 - Mixed Number(whole 3, numerator 1, denominator - 5) mn2/mn3 - MixedNumber(whole = 0, numerator - 85, denominator - 192) Notes a. all fraction operators including creation result into a correct simplified fraction (lowest terms). b. the data in mixed number creation can be any form of a number (byte, short, int, long, float, or double) c. Assumption is all number to entered are positive (no need to worry about negative values)
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY