Instruction: Given the definition of methods and fields available to the Fraction class below, extend it...
Fantastic news! We've Found the answer you've been seeking!
Question:
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) { /* code elided */ } public Fraction multiply (Fraction another){ /* 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 Mixed Number (0.25f) results into whole = 0, numerator = 1, denominator = 4 2. mn2 = new Mixed Number (341, 61) results into whole = 5, numerator = 2, denominator = 3 3. mn3 = new Mixed Number (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 = Mixed Number(whole = 7, numerator = 2, denominator = 15) mn3*mn1 = Mixed Number(whole = 3, numerator = 1, denominator = 5) mn2/mn3 = Mixed Number(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) 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) { /* code elided */ } public Fraction multiply (Fraction another){ /* 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 Mixed Number (0.25f) results into whole = 0, numerator = 1, denominator = 4 2. mn2 = new Mixed Number (341, 61) results into whole = 5, numerator = 2, denominator = 3 3. mn3 = new Mixed Number (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 = Mixed Number(whole = 7, numerator = 2, denominator = 15) mn3*mn1 = Mixed Number(whole = 3, numerator = 1, denominator = 5) mn2/mn3 = Mixed Number(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 Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
What is the final pressure of a gas whose initial conditions are 1.407 L, 2.06 atm, and 67C and whose final volume and temperature are 608 mL and 449 K, respectively? Assume the amount remains...
-
The decomposition of slaked lime, Ca(OH)2(s), into lime, CaO(s), and H2O(g) at constant pressure requires the addition of 109 kJ of heat per mole of Ca(OH)2. (a) Write a balanced thermo-chemical...
-
For this project, you will create ONE excel file with many tabs. Each tab will represent the detail for Berkshire Hathaway's holdings for that quarter. The Information will include the Name of the...
-
Is the development life cycle over with deployment?
-
Donald Barker, a wealthy Oregon resident, went to the law firm Winokur, Schoenberg, Maier, Hamerman & Knudson to have his estate planned. An attorney at the firm repeatedly told Barker that he could...
-
How should the total consideration given to acquire control through a share purchase be allocated prior to preparing consolidated financial statements?
-
What is the output of this code? Show exactly what will appear on the screen. (Do not use an IDE for this question) int n 0; while (n < 10) { if (n % 2 == 0) { n + 5; } else { n - 1; }...
-
The assessment of strategies and related processes that promote superior performance from both market and environmental perspectives is known as _________. A. CSR B. managerial ethics C. management...
-
Which of the following is not part of the marketing strategy? A. pricing B. distribution C. promotion D. none of the above
-
Strategies are formulated in the strategic management stage that occurs immediately after __________. A. the assessment of internal strengths and weaknesses B. implementation of the strategy C....
-
How are the business strategy typologies by Porter and those by Miles and Snow similar? How are they different?
-
Businesses adopting the same generic strategy are referred to as _________. A low-cost businesses B. differentiated businesses C. a strategic group D. none of the above
-
Select a biblical book Gospel of Luke, read it in its entirety, and research its historical background, literary structure, major themes, place in the biblical storyline, and theological message....
-
Tiger, Inc. signed a lease for equipment on July 1, 2007.The lease is for 10 years (the useful life of the asset).The first of 10 equal annual payments of $500,000 was made on July 1, 2007.The...
-
Define the "identification" problem in simultaneous equations models.
-
Define the reduced form of a simultaneous equations model and explain its usefulness.
-
Explain why it is acceptable to estimate reduced-form equations by least squares.
Study smarter with the SolutionInn App