Steps
to creating a program with methods
Step 1: Design
- Determine the parts that repeat or that you want to separate
- Pick a name for your class
- Pick a name for each part (method)
Step 2: Create the class
- Open BlueJ
- Take menu option Project / Open Project / click on your
project
- click "New Class"
- Name the class the name you picked in Step 1
- Delete everything after public class (your name)
Step 3: Create the structure
- Enter Open close brackets under the class
{ }
- Enter One line for the main method: public static void main
()
- Enter One line for each method: public static void
yourMethodName ()
- Enter Open close brackets under each method
{ }
- Compile and see no errors
Step 4: Write comments
- Type
a comment between /* */ on the top of the class to describe
what the class does.
- Type
a comment between /* */ right on top of the method to
describe what the method does.
- Compile and see no errors
Step 5: Code the parts (methods)
Inside the method brackets (the ones underneath the
method) type the statements needed to create the part.
Inside the method brackets (the ones underneath the
method) type the statements needed to create the part.
Compile and see no errors.
You can also right click on the class in the BlueJ window and
execute the individual methods to be sure they work on their own.
Step 6: Call the parts (methods)
Inside the main method brackets (the ones underneath
the main method):
- Inside the main method brackets (the ones underneath the main
method):
- type the name of the first part you want the computer to do.
(You can find the name of the part by looking after "public static
void".)
- type ();
- repeat for all the parts you want the computer to do, in the
order you want them done.
- Compile and see no errors