Systematic and Structured Programming, Part 2
Step Five - Creating Smaller Solutions
Step four probably took a little longer then step three because you were writing code and fixing little syntax errors as you worked through it. However, it should still have been straightforward because you had specific instructions to follow from your prior steps. You will now be reusing that process on a smaller scale.
Just as you did for the main program and method, you will now be creating the solution pseudocode for your individual methods. Here in the fifth step of the process, you will actually go back and use steps one, two, and three on each of the methods. As mentioned previously, this is a recursive process because your original six step process is now incorporating three parts of the same six step process into one of the steps. Recursion will be discussed later in this course, but you will find it handy sometimes to repeatedly reuse processes you have already created rather than having to create new ones
As a note of review here, when you have finished step four you should have a fully working main method. You should not have to go back and mess with the main method any more. One of the many benefits of this system is that you don't have to retrace any steps - you can keep moving forward. With forward motion in mind, your next step now is to design (i.e., write the pseudocode for) your supporting methods.
If you are working through this with the web page, you should change your program file name from QuadClass_StepFour.java to QuadClass_StepFive.java now so that you don't overwrite your fourth step. You will be reminded again to make this change at the end of this web page. Note that the version numbers are not added to the file names in this text since you will be in charge of knowing when you update your files.
Your nearly final iterative pass will not be through the program as it has been before. Now you will work your way through the stub methods, creating pseudocode solutions as steps one, two, and three as you go.
It should also be noted here that to make this tutorial reasonable in length, the methods are pretty simple. Thus, the step one and step two statements will not be very different. However, you should recognize as your programs become more complex, there will be more need to create the simple solution (i.e., step one), and then expand on it to a full pseudocode solution (i.e., step two). Step three will also be brief here because very few methods need to be called by these methods.
Start here
printTitle
Here is the “process” specification for this method:
Process: display the program title on the monitor
Prior to input for the printTitle stub, step one will identify the main steps. Note that you should always have an initialize method/variables comment line at the beginning of every method, even if some methods do not actually need variables:
void printTitle()
{
// initialize method/variables
// print title
// print underline
// print extra endline
}
Again, step three identifies any methods needed by this method, which in this case includes use of both iostream output and input operations:
void printTitle()
{
// initialize method/variables
// print title with underline and vertical space
// print title
// method: printString, printEndline
// print underline
// method: printString, printEndline
// print extra endline
// method: printString, printEndline
}
promptForCoefficient
Here is the "process" specification for this method:
Process: prompt user for appropriate coefficient, get coefficient, return coefficient
For the promptForCoefficient stub, here is step one:
int promptForCoefficient( char coefLetter )
{
// initialize method/variables
// prompt user for coefficient
// return user input
return 0; // temporary stub return
}
Step three identifies any methods needed by this method, which in this case includes use of iostream output and input operations:
int promptForCoefficient( char coefLetter )
{
// initialize method/variables
// prompt user for coefficient
// method: promptForCoefficient
// return input
return 0; // temporary stub return
}
calcDiscriminant
Here is the method "process" specification:
Process: calculate discriminant with three coefficients and return
Here are the step one statements
int calcDiscriminant( int cof_A, int cof_B, int cof_C )
{
// initialize method/variables
// calculate discriminant
// return discriminant
return 0; // temporary stub return
}
In this method, there is no more needed beyond what was stated as step one statements, so there is no need to add step two statements to this method
As it turns out, step three for this method will also be the same since no methods are called by this method; thus the method is complete with its step one statements, as shown:
int calcDiscriminant( int cof_A, int cof_B, int cof_C )
{
// initialize method/variables
// calculate discriminant
// return discriminant
return 0; // temporary stub return
}
calcDenominator
Here is the "process" specification for the calcDenominator method:
Process: calculate denominator with coefficient A and return
Again because of the simplicity of this method, steps one, two and three are all the same. methods that are well developed and concise such as this one will always be easy to write
int calcDenominator( int cof_A )
{
// initialize method/variables
// calculate denominator
// return denominator
return 0; // temporary stub return
}
calcRoot
You must now create the pseudocode for the calcRoot method. Here is the "process" specification for the method:
Process: calculate single root solution with previously processed equation components, and return
Here are steps one, two, and three for this simple method:
double calcRoot( int cof_B, int denom, double discSqrRoot )
{
// initialize method/variables
// calculate the numerator
// calculate the root
// return root
return 0.0; // temporary stub return
}
displayRoot
Finally, you must implement the displayRoot method, with the following "process" specification:
Process: display root number and root solution
Here is step one of the development process for this stub method:
void displayRoot( int rootNum, double rootSolution )
{
// initialize method/variables
// show root display
// end line
}
Here is step two of the development process:
void displayRoot( int rootNum, double rootSolution )
{
// initialize method/variables
// show root display
// display root number
// display root solution
// end line
}
And here is step three of the development process:
void displayRoot( int rootNum, double rootSolution )
{
// initialize method/variables
// show root display
// display root number
// method: printString, printEndline
// display root solution
// method: printString, printEndline
// end line
// method: printString, printEndline
}
As you can see, your steps 1, 2, and 3 should never be very complicated with supporting methods, but again it should be noted that this is a pretty simple program. As your programs grow in complexity and size, you will have many opportunities to apply all three steps to this part of the programming process. However, you must also note that because you broke the larger program down into smaller sub-programs, it should never be particularly difficult to develop any of the methods
Wrapping Up the Final Design Component
- In order to conduct this part of the process, you must remember to save yourQuadClass_StepFour.java file to QuadClass_StepFive.java before you make any changes. You want to keep your step four program exactly as it was so that if there are questions in the future about your overall strategy, you can go back and review the code.
- To finish the program off in the next step (six), you only need to fill in the code necessary to meet your pseudocode specifications provided in this step (five); it really never needs to be very complicated
To see the step five process in action, watch this video; then develop your step five code with or without the video, as needed