Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2: Create a Calculator class in the com.day1.practice3 package. This is how you would write the add method (create the remaining three methods on

image text in transcribedimage text in transcribedimage text in transcribed

Part 2:

image text in transcribedimage text in transcribed

Create a Calculator class in the com.day1.practice3 package. This is how you would write the add method (create the remaining three methods on your own). public static double add(double num1, double num2) return num1 + num2; ( Note that the method has the key word "static". This means that we can all this method without havin to create a calculator class! In other words, we don't have to put in the main method: Calculator calculator = new Calculator(); double result = calculator. add ( num 1 , num 2)); We can simply call the method as follows: double result = Calculator. add ( num 1 , num2)); CalculatorDemo class Create a CalculatorDemo class in the com.day1.practice3 package. Put the following code in the main method: public static void main(String[] args) \{ Scannerscanner=newScanner(System.in); System.out.println("Enter a number:"); double num1 = scanner.nextDouble(); System.out.println("Enter another number:"); double num2 = scanner.nextDouble(); System.out.println(num1 +"+"+ num2 + "=+ Calculator.add(num1, num2)); scanner.close(); Update the main method to call the remaining three methods in the calculator class. Sample output: > CalculatorDemo [Java A Enter a number: 10 Enter another number: 5 10.0+5.0=15.0 10.05.0=5.0 10.05.0=50.0 10.0/5.0=2.0 Update the Calculator class. Overload the add and multiply methods to allow three doubles to be passed in. public static double add(double num1, double num2, double num3) public static double multiply(double num1, double num2, double num3) Then add the following methods: average - this method takes in three doubles and returns the average. Example: passing in 7, 11, and 21 would return 13. power - this method takes in a double and an int. It returns the double multiplied x times, where x is the integer passed in (For example: calling power (2.5,7) is 2.57=610.3515625 ). This will require doing a loop of some sort (if you are unfamiliar with loops, we will cover them on day two). See the class outline on the next page for the method signatures. Update the CalculatorDemo to test these new methods

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions