Section 2c

Step One


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Systematic and Structured Programming

Step One - Simple Action Statements

The Problem to Be Solved

The beginning of the process is to identify the problem and try to elicit all the important actions that your program is required to do. Here is an example program specification:

  1. The program solves for the roots of a quadratic equation

  2. For the following equation, it prompts the user for, and acquires, the x2 coefficient (A), the x coefficient (B), and the constant coefficient (C), for the following equation:

  3. Ax2 + Bx + C = 0

  4. Finally, the program provides the roots of the equation to the user as a displayed output. The first step is to identify the main parts of the program and write them in as comments. This program will only require a few simple statements. The following statements are provided with explanations, and then the code itself is provided.

Initialize the program

Get the coefficients from the user

Process the quadratic roots

Display the roots

End the program

The main method code for step 1 would look like the following. Note that the class information is set aside to focus on the process:

public static void main( String[] args )
{
// initialize program

// get coefficients from user

// process quadratic roots

// display results

// end program
}

The program with the Java class information would be set up (in Project_1 and p1_package) as follows:

package p1_package;

public class QuadClass_StepOne
{
public static void main( String[] args )
{
// initialize program

// get coefficients from user

// process quadratic roots

// display results

// end program
}
}

As you may notice, it wouldn't take more than a few minutes to write this, and while it may seem trivial, it is very important because you now have a feeling for how the program will flow. Even more importantly, you have broken the program down into smaller, more manageable problems.

Some notes:


To see the step one process in action, watch this video; then develop your step one code with or without the video as needed in your own IDE.