Question: A Java Programming Language Fraction class detail public class Fraction { private int num; private int denom; public Fraction() { System.out.println( ... Calling Fraction() ...);

A Java Programming Language

Fraction class detail

public class Fraction {

private int num;

private int denom;

public Fraction() {

System.out.println(" ... Calling Fraction() ...");

}

public Fraction(int n) {

System.out.println(" ... Calling Fraction(int) ...");

num = n;

}

public Fraction(Fraction fr) {

System.out.println(" ... Calling Fraction(Fraction) ...");

num = fr.num;

denom = fr.denom;

}

public int getNum() {

return num;

}

public void setNum(int n) {

num = n;

}

public int getDenom() {

return denom;

}

public void setDenom(int d) {

if (d > 0) {

denom = d;

} else if (d < 0) {

num = -num;

denom = -d;

} else {

System.out.println(" ... No Change ...") ;

}

}

}

1.Add and update all class constructors for your Fraction class to handle the initialization appropriately. i. There must be as least 4 constructors of ii. Default, iii. Copy, iv. Convert taking on an int. v. One constructor with 2 arguments of int. The constructor should have code to confirm the call/use of itself through the printing (e.g., Calling Fraction(int, int)) and continue with the display of numerator and denominator after being initialized/built. 2. Provide get()/set() method members for each private data member. 3. Provide a method member print() that will print the current Fraction object.

B. Provide the following member methods, a. A method add() to add a Fraction object; and b. A method subtract() to subtract a Fraction object; and c. A method multiply() to multiply a Fraction object; and d. A method divide() to divide a Fraction object; and

C. Provide the following stand-alone (non-member) methods, a. A method init() to set up or update the 3 required Fraction objects. b. A method add() to add 2 Fraction objects; and c. A method subtract() to subtract 2 Fraction objects; and d. A method multiply() to multiply 2 Fraction objects; and e. A method divide() to divide 2 Fraction objects; and f. A method print() to print the required Fraction objects; and g. An appropriate menuHw5() method to produce the required output as displayed below.

D. Write a menu program to produce and display the output as specified as below,

/** REQUIRED PROGRAM OUTPUT

*********************

* MENU Hw #4 *

* 1. Initializing *

* 2. Adding *

* 3. Subtracting *

* 4. Multiplying *

* 5. Dividing *

* 6. Printing *

* 7. Quit *

*********************

Select an option (use integer value only): 6

Printing Option --

*********************

* MENU Hw #4 *

* 1. Initializing *

* 2. Adding *

* 3. Subtracting *

* 4. Multiplying *

* 5. Dividing *

* 6. Printing *

* 7. Quit *

*********************

Select an option (use integer value only): 2

Adding Option --

Not a proper call as no Fractions are available!

*********************

* MENU Hw #4 *

* 1. Initializing *

* 2. Adding *

* 3. Subtracting *

* 4. Multiplying *

* 5. Dividing *

* 6. Printing *

* 7. Quit *

*********************

Select an option (use integer value only): 1

Initializing Option --

*********************

* MENU Hw #4 *

* 1. Initializing *

* 2. Adding *

* 3. Subtracting *

* 4. Multiplying *

* 5. Dividing *

* 6. Printing *

* 7. Quit *

*********************

Select an option (use integer value only): 6

PRINTING Option

********************************

* PRINTING MENU *

* (leftOp, rightOp, result) *

* 1. print() - Member *

* 2. print() Stand Alone *

* 3. Return to Previous MENU *

***********************************

Select an option (1, 2, or 3): 1

********************************

* PRINTING MENU *

* (leftOp, rightOp, result) *

* 1. print() - Member *

* 2. print() Stand Alone *

* 3. Return to Previous MENU *

***********************************

Select an option (1, 2, or 3): 2

********************************

* PRINTING MENU *

* (leftOp, rightOp, result) *

* 1. print() - Member *

* 2. print() Stand Alone *

* 3. Return to Previous MENU *

***********************************

Select an option (1, 2, or 3): 3

*********************

* MENU Hw #4 *

* 1. Initializing *

* 2. Adding *

* 3. Subtracting *

* 4. Multiplying *

* 5. Dividing *

* 6. Printing *

* 7. Quit *

*********************

Select an option (use integer value only): 2

ADDING Option

********************************

* ADDING MENU *

* *

* 1. add() - Member *

* 2. add() Stand Alone *

* 3. Return to Previous MENU *

************************************

Select an option (1, 2, or 3): 5

WRONG OPTION ...

********************************

* ADDING MENU *

* *

* 1. add() - Member *

* 2. add() Stand Alone *

* 3. Return to Previous MENU *

************************************

Select an option (1, 2, or 3): 1

Calling member add()

********************************

* ADDING MENU *

* *

* 1. add() - Member *

* 2. add() Stand Alone *

* 3. Return to Previous MENU *

************************************

Select an option (1, 2, or 3): 2

Calling stand alone add()

********************************

* ADDING MENU *

* *

* 1. add() - Member *

* 2. add() Stand Alone *

* 3. Return to Previous MENU *

************************************

Select an option (1, 2, or 3): 3

*********************

* MENU Hw #4 *

* 1. Initializing *

* 2. Adding *

* 3. Subtracting *

* 4. Multiplying *

* 5. Dividing *

* 6. Printing *

* 7. Quit *

*********************

Select an option (use integer value only): 3

SUBTRACTING Option

*********************************

* SUBTRACTING MENU *

* *

* 1. subtract() - Member *

* 2. subtract() Stand Alone *

* 3. Return to Previous MENU *

**********************************

Select an option (1, 2, or 3): 5

WRONG OPTION ...

*********************************

* SUBTRACTING MENU *

* *

* 1. subtract() - Member *

* 2. subtract() Stand Alone *

* 3. Return to Previous MENU *

**********************************

Select an option (1, 2, or 3): 1

*********************

* MENU Hw #4 *

* 1. Initializing *

* 2. Adding *

* 3. Subtracting *

* 4. Multiplying *

* 5. Dividing *

* 6. Printing *

* 7. Quit *

*********************

Select an option (use integer value only): 7

Having Fun...!

1. Reminder!

In your program, no GLOBAL DATA are allowed, and you must write all needed functions (no package methods are allowed Except for input/ouput methods)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!