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 19:20
Write a program that prompts the user to input a string. the program then uses the function substr to remove all the vowels from the string. for example, if str = "there", then after removing all the vowels, str = "thr". after removing all the vowels, output the string. your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel.
Answers: 2
question
Computers and Technology, 23.06.2019 11:30
Auser is given read permission to a file stored on an ntfs-formatted volume. the file is then copied to a folder on the same ntfs-formatted volume where the user has been given full control permission for that folder. when the user logs on to the computer holding the file and accesses its new location via a drive letter, what is the user's effective permission to the file? a. read b. full control c. no access d. modify e. none of the above
Answers: 1
question
Computers and Technology, 23.06.2019 22:20
If i uninstall nba 2k 19 from my ps4 will my career be gone forever?
Answers: 2
question
Computers and Technology, 24.06.2019 15:50
Andy would like to create a bulleted list. how should he do this? andy should click on the bullet icon or select the bullet option from the menu and then type the list. andy should press the shift key and the 8 key at the beginning of each line of text. andy should type the text and then click on the bullet command. andy should press return and the bullets will automatically
Answers: 2
You know the right answer?
Build a class called Calculator that emulates basic functions of a calculator: add, subtract, multip...
Questions
question
Mathematics, 12.10.2020 09:01
question
Mathematics, 12.10.2020 09:01
question
Mathematics, 12.10.2020 09:01
question
Mathematics, 12.10.2020 09:01
question
Mathematics, 12.10.2020 09:01
Questions on the website: 13722362