|
|
Java Student Project |
||
|
|||
| The Cube | |||
|
|
|
||
| Ability Level: | Beginner | ||
|
|
|
||
| Estimated Time: | 40 minutes | ||
|
|
|
||
| Objectives: |
|
||
|
|
|
||
| Materials & Resources: |
|
||
|
|
|
||
| Overview: |
Write
a program that displays the result of cubing a number. Pass a
number from one method to another method that cubes a number and
returns the result. The display should execute within the method
that calls the cube method. |
||
|
|
|
||
| Instructions: |
Use the following template to help you get started:
|
||
|
|
|
||
| Hints: | Some
important points to keep in mind in
doing this project:
1. A method is a
series of statements that carry out some task. Using a method
makes programs easier to follow. Methods are easily reusable. 6. Any method that is a class-wide method requires the keyword modifier static. 7. A method is placed within a program that will use it, but not within any other method. If you place a method call within a class that does not contain the method, to call the method you must use the class name, followed by a dot, followed by the method. 8. Some methods require a message or argument. 9. Implementation hiding (abstraction), concealing details of how the method is executed, is an important principal of object-oriented programming. 10. When writing the method declaration for a method that can receive an argument, the type of the argument and a local name for the argument need to be included within the method declaration parentheses. 11. A method can be called within a program using either a constant value or a variable to an argument. 12. Multiple arguments can be passed to methods by listing the arguments and separating them by commas within the call to the method. 13. The arguments sent to the method must match in both number and type the parameters listed in the method declaration. 14. The return type for a method (the method's type) can be any Java type, including void. 15. A return statement is used to send a value back to a program that calls a method. Sample:
|
||
|
|
|||