Learning the process makes much of your class design and implementation "no-brainer". This frees up your brain to work on the parts that really are difficult and you can usually re-use the code you've already written and tested.
Later, you may find a method that works better for you, but learn this one first before you try to use your own.
At each step, if you can't think of anything more, or aren't clear what to do, skip it and go back to it later. In other words, don't let yourself get stuck. If it's not essential, skip it! Also, try to make your design match the way people think about it in real life.
Ok, enough pep talk - let's get started!
Write down all the nouns. Don't analyze them, this step is more like brainstorming!
Double check it with hasa - a class hasa data member.
If it's not clear, skip it for now!
A getter typically takes no arguments and just returns the data member/instance variable.
Sometimes a getter does a calculation using the instance variable(s) and returns the calculated value.
Write all the contructors that make sense, not just the ones that your program will use.
Not all constructors make sense, so do NOT write them if they don't fit in with the design or are dangerous.
Ok, time for a small test program! Make sure you test every constructor and every access function. Fix any errors before going on.
Next are the "in-between" steps:
The signature must match this exactly:
When an object of this class is sent to println(), it will be called automatically and the resulting
string is displayed.
public String toString()
A setter typically takes one argument, sets the private instance variable to the passed-in value, and has a return type of void.
A good name for this method would be print() or trace().
Now, time for more testing! Make sure it's perfect before you go on!
The goal is that by working on the nouns first you have worked out many of the details of how your class should work and maybe even done most of the work (and tested it) already.
Ok, time to do the verbs - usually the hard part! Write down all the verbs (or verb phrases).
public void paintComponent(Graphics g)
It should draw the correct picture based on the current values of the instance variables.
Finish up your main program. Don't forget your test plan and you're done!