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 02:30
If you turn on the lock alpha button , what happens
Answers: 1
question
Computers and Technology, 22.06.2019 03:20
Which of these is a benefit of social networking? oa. hiding your true identity from friendsob. avoiding talking to people in personoc. spending time with friends instead of studyingod. connecting with new people
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
Write a function called checkfactor that takes two arrays of positive numbers, firstnumberrow and secondnumberrow. checkfactor checks if the first entry in firstnumberrow is divisible by the first entry in secondnumberrow, and performs the same operation on the next array elements until all entries have been checked. all the numbers are positive and the number of entries in the arrays are the same. the function should return the identified divisible numbers in two row arrays named firstdivisible and seconddivisible.restrictions: branches or loops should not be used. the code must use the internal mod and logical functions.hint: the mod function should be used to determine if two numbers are divisible. ex: for num1 and num2 if mod(num1,num2) is 0, then the two numbers are divisible.this is matlab
Answers: 2
question
Computers and Technology, 23.06.2019 09:50
Allison and her group have completed the data entry for their spreadsheet project. they are in the process of formatting the data to make it easier to read and understand. the title is located in cell a5. the group has decided to merge cells a3: a7 to attempt to center the title over the data. after the merge, allison points out that it is not centered and looks bad. where would the title appear if allison unmerged the cells in an attempt to fix the title problem?
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, 21.01.2021 01:00
question
Social Studies, 21.01.2021 01:00
question
English, 21.01.2021 01:00
question
Mathematics, 21.01.2021 01:00
question
Chemistry, 21.01.2021 01:00
question
Geography, 21.01.2021 01:00