Question: Create a CalculatorTest class that contains the main method. 1. Get two double numbers as input and create an object of the ScientificCalculator Class with
Create a CalculatorTest class that contains the main method. 1. Get two double numbers as input and create an object of the ScientificCalculator Class with those two numbers. 2. Then call the 8 operations one by one sequentially and display the result. Code must be written in Java.
(Sample input/output: Enter number 1: 2 Enter number 2: 3 Add() result is : 5 Sub() result is: -1 . Power() result is: 8 sqrtNum1 result is:)
The Problem:
Given the following class diagram (see Chapter 3 Slide 34 and 36
if you are not familiar
with the diagram).
The diagram is
self
-explanatory
. Remember
means private and
+ means public
in the diagram
.
Conver
t the class diagram into a java code. You can easily see the class name, variables and methods from
the diagram.
The diagram says that
Scientific
Calculator
class
inherits
the
Calculator
class. In many operations in the
scientific calculator class
, you can utilize the
java.Math class
s methods
(https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html
).
Calculator
-
num1: double
-
num2: double
<
num1: double, num2:double)
+set
Num1(num1: double)
+setNum2(num2: double)
+getNum1(): double
+getNum2(): double
+add(): double
+sub(): double
//num1
-num2
+mul(): double
+div(): double
//num1/num2
Create a CalculatorTest class that contains the main method.
1.
Get two double numbers as input and create an object of the Scientific
Calculator Class
with
those two numbers.
2.
The
n call
the
8 operations one by one sequentially
and display the result.
ScientificCalculator
<
double, num2:double)
//dont forget to call
the super classs constructor from here
. Otherwise it willshow error as we dont have a
constructor without any parameter.
+power(): double //returns num1 ^ num2
+reminder(): int
//returns the reminder of num1/num2 as integer. So,
convert num1 and num2 to int before performing the operation
+sinNum1(): double
//r
eturns the trigonometric sine of num1.
+sqrtNum1(): double
//returns the square root o
f Num1
Sample input/output:
Enter number 1: 2
Enter number 2: 3
Add() result is : 5
Sub() result is: -
1
.......
Power()
result is: 8
......
sqrtNum1 result is:
The code structure should look like the following
. Note
that
all the classes ar
e written in a single file.
So, in eclipse you can just create one class and write everything in the same file
:
File name: CalculatorTest.java
//all the require import statements
class Caclulator {
class body
}
Class .....{
Class body
}
Public class CalculatorTest{
Class body.
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
