subject

Build a class called Calculator that emulates basic functions of a calculator: add, subtract, multiply, divide, and clear. The class has one private member field, double value, for the calculator's current value. Implement the following Constructor and instance methods as listed below:public Calculator() - Constructor method to set the member field to 0.0public void add(double val) - add the parameter to the member fieldpublic void subtract(double val) - subtract the parameter from the member fieldpublic void multiply(double val) - multiply the member field by the parameterpublic void divide(double val) - divide the member field by the parameterpublic void clear( ) - set the member field to 0.0public double getValue( ) - return the member fieldGiven two double input values num1 and num2, the program outputs the following values:The initial value of the instance field, valueThe value after adding num1The value after multiplying by 3The value after subtracting num2The value after dividing by 2The value after calling the clear() methodEx: If the input is:10.0 5.0the output is:0.010.030.025.012.50.0import java. util. Scanner;public class Calculator {// TODO: Build Calculator class with methods and fields listed above/* Type your code here. */public static void main(String[] args) {Calculator calc = new Calculator(); Scanner keyboard = new Scanner(System. in); double num1 = keyboard. nextDouble(); double num2 = keyboard. nextDouble(); // 1. The initial value System. out. println(calc. getValue()); // 2. The value after adding num1 calc. add(num1); System. out. println(calc. getValue()); // 3. The value after multiplying by 3 calc. multiply(3); System. out. println(calc. getValue()); // 4. The value after subtracting num2 calc. subtract(num2); System. out. println(calc. getValue()); // 5. The value after dividing by 2 calc. divide(2); System. out. println(calc. getValue()); // 6. The value after calling the clear() method calc. clear(); System. out. println(calc. getValue());}}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:30
What is a costume plot? why is it important to a film or theater production?
Answers: 2
question
Computers and Technology, 23.06.2019 17:00
The more powerful, 60 volt cables and the main power shut-off on an hev are both colored orange.
Answers: 1
question
Computers and Technology, 25.06.2019 01:30
If the average computer chip had 1,200 transistors per square inch in 1970, approximately how many transistors per square inch would one have in 1976? use moore's law to calculate your answer
Answers: 1
question
Computers and Technology, 25.06.2019 05:10
Maia notices that her paragraphs are too close to one another. she wants to increase this space. which arrangement of steps does maia follow after she goes to the paragraph command group in the ribbon? type in the space needed, go to the after menu, go to the spacing part of the box, and open the paragraph dialog box. go to the spacing part of the box, go to the after menu, open the paragraph dialog box, and type in the space needed. open the paragraph dialog box, go to the spacing part of the box, go to the after menu, and type in the space needed. type in the space needed, open the paragraph dialog box, go to the after menu, and go to the spacing part of the box.
Answers: 1
You know the right answer?
Build a class called Calculator that emulates basic functions of a calculator: add, subtract, multip...
Questions
question
Chemistry, 27.05.2021 07:20
question
Mathematics, 27.05.2021 07:20
question
Mathematics, 27.05.2021 07:20
Questions on the website: 13722363