Write a method called power

Assignment Help Computer Engineering
Reference no: EM132117511

For this question, you will write several methods for your own Math class. These should all be inside a class called Hypotenuse. Write these methods on the provided paper. If you run out of space, more paper will be provided. Make sure that your name and student number are written on the extra paper.

Write a method called absVal. This method takes as input a real number and outputs the absolute value of that number. For example absVal(3.5) should return 3.5, absVal(-4) should return 4, and absVal(0) should return 0. You may NOT use any library methods to help for this question.

Write a method called power. This method takes as input a real number, x, and an integer number, y. It outputs the real number to the power of the integer number, xy. You can assume that the exponent (the integer, y) is non-negative (but it might be 0). You may NOT use any library methods to help for this question.

Write a method called squareRoot. This method takes as input a real number, y, and outputs its square root, vy. You will do this using the Babylonian method described in detail below. You may NOT use any library methods to help for this question.

The Babylonian method for approximating the square root of a number works by making successive "guesses" (denoted by x0 , x1 , ...xk below) which get closer and closer to the actual value. Once the difference between successive guesses is very small, the method stops and the final guess is considered to be the answer.

- The first guess :x0 = y 2

- Subsequent guesses: Repeat xk+1 = 1 (xk + y ) 2 xk

- Stop when the difference between successive values of xk and xk+1 is less than 0.1. - The answer is the last value of xk+1.

For this question, if the method input is negative, you should take the absolute value of the input before computing the square root. Do this using the absVal method you wrote in part 1.

Inside of the class Hypotenuse, write a main method. Your method will ask the user for two floating point numbers as input and obtain them using a Scanner type variable.

These numbers correspond to the base and the height of a right angle triangle. It then calculates and prints the length of the hypotenuse. Recall that c2 = a2 + b2 where c is the length of the hypotenuse and a and b are the lengths of the base and the height. Use the power and squareRoot methods that you wrote previously to do this.

Reference no: EM132117511

Questions Cloud

How you felt as an individual attending the meeting : How you think a "newcomer" with a substance-related problem or mental illness disorder may feel attending the meeting for the first time.
Write the while loop that lets the users enter a number : Write the while loop that lets the users enter a number. The number should be multiplied with produce and the result stored back to the variable product.
Write a single c statement that sets to 1 the sign : Write a single C statement that sets to one bits 7, 9 and 11 of N, leaving the remaining bits unchanged. (Bit 0 is the least significant bit.)
Identify global societal problem in introductory paragraph : Identify the global societal problem within the introductory paragraph. Describe background information on how that problem developed or came into existence.
Write a method called power : Write a method called power. This method takes as input a real number, x, and an integer number, y.
Perform the affine mapping by computing the matrix-vector : Perform the affine mapping by computing the matrix-vector multiplication and addition.
Write code to ask the user how many honor students : Write code to ask the user how many honor students he wishes to add. Then read in from the user using the Scanner class the name.
Improve the companies financial performance : BUACC1508 ACCOUNTING AND FINANCE - Strategies to improve the companies financial performance and results and also improve investor (shareholder/member)
Create an integer array which contains ten elements : Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd