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, 23.06.2019 11:30
Which excel file extension stores automated steps for repetitive tasks?
Answers: 1
question
Computers and Technology, 23.06.2019 17:10
Ac++an of of pi. in , pi is by : pi = 4 – 4/3 + 4/5 – 4/7 + 4/9 - 4/11 + 4/13 - 4/15 + 4/17 . ., to pi (9 ). , if 5 to pi,be as : pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 = 4 – 1. + 0.8 - 0. + 0. = 3.. atoofbe to pi?
Answers: 2
question
Computers and Technology, 24.06.2019 17:00
Anew author is in the process of negotiating a contract for a new romance novel. the publisher is offering three options. in the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. in the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. in the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. the author has some idea about the number of copies that will be sold and would like to have an estimate of the royal- ties generated under each option. write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. the program then outputs he royalties under each option and the best option the author could choose. (use appropriate named constants to store the special values such as royalty rates and fixed royalties.
Answers: 1
question
Computers and Technology, 25.06.2019 23:30
What the heck is a motherboard and why is my computer not working when i take it out
Answers: 1
You know the right answer?
Build a class called Calculator that emulates basic functions of a calculator: add, subtract, multip...
Questions
question
Social Studies, 30.03.2021 21:00
question
Mathematics, 30.03.2021 21:00
question
Mathematics, 30.03.2021 21:00
Questions on the website: 13722361