Question
//class MathOperation public class MathOperation { //A int intNum1; int intNum2; float fNum1; float fNum2; int op; //B public MathOperation() { intNum1 = 0; intNum2
//class MathOperation
public class MathOperation {
//A
int intNum1;
int intNum2;
float fNum1;
float fNum2;
int op;
//B
public MathOperation()
{
intNum1 = 0;
intNum2 = 0;
fNum1 = 0;
fNum2 = 0;
op = 0;
}
//C
public MathOperation(int n1, int n2, int n)
{
intNum1 = n1;
intNum2 = n2;
fNum1 = 0;
fNum2 = 0;
op = n;
}
//D
public MathOperation(float d1, float d2, int n)
{
fNum1 = d1;
fNum2 = d2;
iNum1 = 0;
iNum2 = 0;
op = n;
}
//E
public String toString()
{
String str = "CALCULATOR OF LIEM LE";
String str2 = "", str3 = "";
int iRet= 0;
float fRet = 0.0f;
switch (op)
{
case 1: // add 2 int
str2 = "ADD TWWO INTEGERS";
iRet = intNum1 + intNum2;
str3 = intNum1 + " + " + intNum2 + " = " + iRet;
break;
case 2: // minus 2 int
str2 = "MINUS TWWO INTEGERS";
iRet = intNum1 - intNum2;
str3 = intNum1 + " - " + intNum2 + " = " + iRet;
break;
case 3: // multiply 2 int
str2 = "MULTIPLY TWWO INTEGERS";
iRet = intNum1 * intNum2;
str3 = intNum1 + " * " + intNum2 + " = " + iRet;
break;
case 4: // divide 2 int
str2 = "DIVIDE TWWO INTEGERS";
iRet = intNum1 /intNum2;
str3 = intNum1 + " / " + intNum2 + " = " + iRet;
break;
case 5: // add 2 float
str2 = "ADD TWWO DECIMAL NUMBERS";
fRet = dNum1 + dNum2;
str3 = dNum1 + " + " + dNum2 + " = " + fRet;
break;
case 6: // minus 2 floaf
str2 = "MINUS TWWO DECIMAL NUMBERS";
fRet = dNum1 - dNum2;
str3 = dNum1 + " + " + dNum2 + " = " + fRet;
break;
case 7: // multiply float
str2 = "MULTIPLY TWWO DECIMAL NUMBERS";
fRet = dNum1 * dNum2;
break;
case 8: // divide float
str2 = "DIVIDE TWWO DECIMAL NUMBERS";
fRet = dNum1 / dNum2;
str3 = dNum1 + " + " + dNum2 + " = " + fRet;
break;
}
return str + " " + str2 + " " + str3 + " ";
}
}
java coding with comments will be helpful to understand
Create the project named SP2019 LAB1PART1 then add data type MathOperation and driver class named SP2019_DriverClass yourLastName: a. Draw UML of class MathOperation b. Write the pseudo-code or draw flowchart the provide the java code of a driver class named DriverClass of the application that first will display the followwing menu MENU-CALCULATOR ON TWO NUMBERS 1. Add two integers 2. Subtract two integers 3. Multiply two integers 4. Divide two integers 5. Add two decimal numbers 6. Subtract two decimal numbers 7. Multiply two decimal numbers 8. Divide two decimal numbers 0. Exit Then read the task selected by users by typing a number from the keyboard If users select the task from 1 to 4, ask for 2 integer numbers If users select the task from 5 to 8, ask for 2 decimal numbers Create the object of data type class MathOperation to pass the selected task and 2 numbers that read above Finally, display the result but using the object name of MathOperation to call the method toString of class MathOperation The output has the following format that includes 3 lines for each operation For example the output of adding two integers as below: CALCULATOR OF JAMES SMITH ADD TWO INTEGERS 56+27 83 For example the output of dividing two decimal numbers as below: CALCULATOR OF JAMES SMITH ADD TWO DECIMAL NUMBERS 234.123/12.6 18.58 The program should redisplay the menu again to allow users have the chance to select another task to Continue using the program until they select task 0 to exit Notes: -you have to add the file name as the first comment line Wrirte the comments into your program before each action -Change the name James Smith in the output to your name -Provide at least one user-defined functionStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started