Computers and Technology

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());}}

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 21:00, bryanatwin1536
Describir textbook icon_person mira los dibujos y describe lo que está pasando. usa los verbos de la lista.
Answers: 1
image
Computers and Technology, 23.06.2019 17:00, Alexaisokay1
In which of the following ways can using test-taking tips you? a. you can focus on the information that you need to study. b. you will see the answers to the test. c. you will study more. d. you will be less organized.
Answers: 1
image
Computers and Technology, 24.06.2019 02:50, rurbanok12
Be sure to answer all parts. synthesize the following compound from benzene. a. b. c. d. e. f. reaction [1] conditions: a b c d e f reaction [1] product: draw structure reaction [2] conditions: a b c d e f reaction [2] product: draw structure reaction [3] conditions: a b c d e f reaction [3] product:
Answers: 3
image
Computers and Technology, 24.06.2019 10:50, latresyn
In 2009 to 2010, how many social network users were reported as being victims of online abuse? a. 1 in 10 b. 100% c.1 in 100 d. 50%
Answers: 2
Do you know the correct answer?
Build a class called Calculator that emulates basic functions of a calculator: add, subtract, multip...

Questions in other subjects:

Konu
Chemistry, 23.06.2019 23:20