Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!

# Explanation

Heba Hus
Greenhorn
Posts: 14
Good Afternoon

I have an assignment due Sunday ... The problem is that i don't understand the question cam someone explain it for me

Question:

Create a class Power that contains two methods:
Write a method power(double a , int n) that calculates and displays the result of the double parameter a raised to the power n. For example

power(3.0 , 2); display 3 to the power 2=9
power(2.0 , 3); display 2 to the power 3=8

Call it from the main method

Horatio Westock
Ranch Hand
Posts: 221
Create a class Power that contains two methods:

OK, you need to create a class called Power.

Write a method power(double a , int n) that calculates and displays the result of the double parameter a raised to the power n. For example

power(3.0 , 2); display 3 to the power 2=9
power(2.0 , 3); display 2 to the power 3=8

OK, you need to add a method power(double a, int n) with the given behaviour. Seems straight forward so far.

You don't say what the second of the two methods is.

Think about these steps:

1. Write an empty class called Power
2. Add a method power(double a, int n) which works out a[SUP]n[SUP] and prints out a line "a to the power n = ?", where you replace a, n and ? with the correct values.
3. Add second method, whatever that is.
4. Write a method

and in the method body, call your two new methods with some test data.

Heba Hus
Greenhorn
Posts: 14
Ok ill do it step by step ...

OK, you need to create a class called Power.

2. Add a method power(double a, int n) which works out a[SUP]n[SUP]

and prints out a line "a to the power n = ?", where you replace a, n and ? with the correct values.

^^^ I didn't get this

4. Write a method

mmmmmmmmmmmmm :roll:

Horatio Westock
Ranch Hand
Posts: 221
Do you have a class textbook? It should have examples of things like how to write a basic class, a main method and how to write out messages to the console.

I recommend you read The Java Tutorial, before going any further.

Lets get you started:

I'm not going to do this for you, so you really need to read about:

- how to make the calculation in the power method
- how to use System.out to print out your results
- how to call your power method from your main method

Do some reading, then come back with the code your write. If you write some code and still have problems, come back, and we will help you.

Good luck!

[ March 25, 2005: Message edited by: Horatio Westock ]
[ March 25, 2005: Message edited by: Horatio Westock ]

Heba Hus
Greenhorn
Posts: 14
Hi ... Thank you so much

I have a question ... is it right to use the pow() method here??

Horatio Westock
Ranch Hand
Posts: 221
Try it

Heba Hus
Greenhorn
Posts: 14
ok LoOl ;p

Heba Hus
Greenhorn
Posts: 14
mmmmmmmmmmm ... will i take anything from the user???

Horatio Westock
Ranch Hand
Posts: 221
Originally posted by Heba Hus:
mmmmmmmmmmm ... will i take anything from the user???

Why would you? Does your assignment require you to accept user input?

I'd follow the step you were trying, get that working first. You should only have to write a few lines of code.

Heba Hus
Greenhorn
Posts: 14

It doesnt work ... but am i close?

Abhishek Roy
Greenhorn
Posts: 4
Here You Go ...

Replace values of power and number to whatever you want.

[ March 25, 2005: Message edited by: Abhishek Roy ]
[ March 25, 2005: Message edited by: Abhishek Roy ]

Heba Hus
Greenhorn
Posts: 14
this is what i did

Power p = new Power();

what is happening here??

Heba Hus
Greenhorn
Posts: 14
Help ???