Question: Write a Java class (name it TwoNumbers) that will manage two numbers. The class should have two integer variables. The class should have the following
Write a Java class (name it TwoNumbers) that will manage two numbers.
The class should have two integer variables.
The class should have the following constructors:
- TwoNumbers();
- TwoNumbers(3, 4);
The first constructor should initialize the class variables to zero.
The second constructor should initialize the class variables to the passed variables.
The class should have the following methods:
- setNumbers(3, 4);
- setFirstNum(3);
- setSecondNum(4);
- getSum();
- getDiff();
- getProd();
The setNumbers(3, 4) method should initialize the two variables of the class to the passed values.
The setFirstNum(3) method should initialize the first variable of the class to the passed value.
The setSecondNum(4) method should initialize the second variable of the class to the passed value.
The getSum() method should return the sum of the two variables in the class.
The getDiff() method should return the difference of the two variables in the class.
The getProd() method should return the product of the two variables in the class.
Also add the method main to call on the methods above.
Please write out the code. No screen shots please.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
