Question
JAVA CODE, IF USING A DO STATEMENT UNCLUDE THE WHILE WITH IT 1. Design a class called Calculator. [1 point] 2. The class should have
JAVA CODE, IF USING A DO STATEMENT UNCLUDE THE WHILE WITH IT
1. Design a class called Calculator. [1 point] 2. The class should have two private double variables: numarr[] and result. [1 point] 3. The default constructor should initialize the variables to 0. [1 point] 4. Overload the constructor to initialize numarr[] with a user-defined number array as a parameter. The result initialization should always be 0. The numarr[] is an array of type double and each element should be initialized with to be 0. [1 point] 5. Write the appropriate set and get methods which are public. [1 point] 6. Write four public methods add(), subtract(), multiply() and divide(). Include the appropriate parameters. The output of the operation will be stored in the result variable. The add() method will add all the numbers in numarr[] and store the value in result. Similarly, the subtract() method will subtract all the other elements from the first element. The multipy() method will multiply all the elements, and the divide will also divide the first element with the rest of the elements. Eg are: [4 points] {20,30,40} for add will output 100. {20,30,40} for subtract will output -50. {20,30,40} for multiply will output 24000. {20,30,40} for divide will output 0.01667 7. Check to see if any exceptions can occur. Handle as appropriate. [Bonus: 2 points] 8. Use any additional variables or methods as necessary. [1 point] 9. In the main function: [1 point] Create an instance of the Calculator class called calc. Allow the user to input the numbers using the keyboard. After two numbers are input, ask the user If more than two numbers are there to be input. After all the numbers are entered, take the operator (+, -, *, /) as an input from the keyboard as a character. Perform the operation and display the result. Prompt the user with a continuation option (y/n). Loop if y, terminate if n. Submission Instructions:
Step 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