The Power function calculates the power of a base "a" raised to an exponent "n". Write a class which that you will call Power class with a method "power(a,n)" that prints the corresponding power value. Remember to use "float" for a and "long" for n and the returned value to be a "float" because the number is ***** real number.
Design and write a Dialog box for Input/Ouput that allows the users to input a base "a" and an exponent "n" and outputs the result of the power of a raised to the exponent of n.
Example:
Power(5.0,2)=(5.0)2= 25.0
Power(5.0,-2)=(5.0)-2 = (1/25)=0.04
Remember the values of n can be postive or negative. Your code should be able to deal with both cases. Remember to limit the value of n to the value 40 maximum.
The Assigment will require you to create 2 files:
1- Power.java which contain the details of creating the Power class and the method power which should calculate the power of any number a raised to the exponent n. (Use the Discussion 'Hints on Assign6" for help with writing the code for Power.java as an example). Remember that you are to create 2 loops in the "power(a,n)" method that you need to write: one loop for n>0 and one loop for n0. You need to cover both >0 and <0.
class Power{
float power (float x,long n){
float pow=1;
for(int i=0;i<n;++i)
pow=pow*x;
return pow;
}
}

 

 

 

    • 8 years ago
    A+ Work
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      qyih65i.zip