Systematic and Structured Programming
Step Two - Expanding the Solution
While it is true that your step one action was pretty easy, you have accomplished an important thing. Now that you have the overall flow of the program fleshed out, almost all of the remaining programming work will involve "filling in the blanks" in a kind of ever-expanding strategy that includes both a top-down and an iterative refinement process.
If you are working through this with the web page, you must create a new class named in your Project_1/p1_package structure. This class will be named QuadClass_StepTwo. You must then copy the contents of the main method in QuadClass_StepOne into the main method of your QuadClass_StepTwo. At this point, you want to save what was stored as step one for your future review.
Consider the following items from the previous step:
Initialize the program
- You must specify initialization of the variables, which you will almost always do
- Now you can expand this a little bit by adding a title to the program. There is not much more to do to expand on this part
- The pseudocode for this part would look like the following:
// initialize program
// initialize variables
// show title
Get the coefficients from the user
- You should now specify what getting the coefficients means. For this program, it means the following:
- get the coefficient A from the user
- get the coefficient B from the user
- get the coefficient C from the user
- The pseudocode for this part would look like the following:
// get coefficients from user
// get coefficient A
// get coefficient B
// get coefficient C
Process the quadratic roots
- You will now expand on what calculations must be accomplished
- The solution for the roots is shown here:
- To conduct this operation in an appropriately modular way, you will implement the following solution activities:
- you must calculate the value under the radical, called the discriminant
- you must calculate the square root of the discriminant
- you must calculate the denominator
- finally, with all the components or modules calculated, you will be able to calculate root one and root two of the equation; note that this component is broken down to another level of abstraction
- The pseudocode for this part would look like the following:
// process the quadratic roots
// calculate the discriminant
// calculate the discriminant square root
// calculate the denominator
// calculate roots// calculate root one
// calculate root two
Display the Roots
- This process should be easy, but you still have to consider displaying:
- the user input: coefficient a, coefficient b, and coefficient c
- root one
- root two
- The pseudocode for this part would look like the following:
// display roots
// display user input
// display root one
// display root two
End the program
- For this program, the following needs to happen:
- the main method must return zero to the operating system in order to end the program and indicate successful completion of it; this is already in the program since it was added to the original base file
- The pseudocode for this part would look like the following:
// end program
// display program end
The Whole Schlemiel
- When all of the pseudocode pieces shown above are put together in a program, the main method code for step two would look like the following. Again, the class code is left out for clarity:
public static void main( String[] args )
{
// initialize program
// initialize variables
// show title
// get coefficients from user
// get coefficient A
// get coefficient B
// get coefficient C
// process the quadratic roots
// calculate the discriminant
// calculate the discriminant square root
// calculate the denominator
// calculate root one
// calculate root two
// display roots
// display user input
// display root one
// display root two
// end program
// display program end
}
This again does not take very long to write, but you have expanded what the main part of your program will do now. You have prepared yourself for the next part of the programming process, which is to break the problem down into manageable problem-solving components.
Some notes:
- Reminder if you haven't already done it: In order to conduct this part of the process, you must create a new class named in your Project_1/p1_package structure. This class will be named QuadClass_StepTwo. You must then copy the contents of the main method in QuadClass_StepOne into the main method of your QuadClass_StepTwo. You want to keep your step one 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.
- As mentioned previously, you are now involved in a process called iterative refinement. This means that you will repeat the same cycles through the code and descriptions you have generated, but make small improvements during each repetition. For example, your first pass (step one) through this program generated a short program with only a few lines of actual program statements. Now you have gone back through the same program in step two, and refined it by adding and expanding detailed elements of each of the major steps. Your whole process of program development will continue like this; that is, you will go back through the same program code adding and improving to each step in a repetitive action, adding, expanding, and improving your program by a little bit until it is finished
- Remember as you type in your expansion comments, you must still make sure the program compiles without errors or warnings. This continues to be trivial because you are not adding any code. However, it is still important that no unknown issues pop up right now, and besides, it is a great habit to get into (that you will be using a lot later on)
- Note again that even though you have extended your code, you still don't have more than ten (10) actions at any level of the program (i.e., at any indented level). This continues to be critical because if you see this happening, you will recognize that you are trying to solve too big a problem, and that it is time to break the problem down some more. If you are ready to continue, you can move on as instructed next
To see the step two process in action, watch this video; then develop your step two code with or without the video as needed in your own IDE.