CS101-CS102

Java Lab - Design & Implementation

Details & examples of what we expect in Java (structured programming) lab assignments...

Structured Programming Designs

Basic Algorithm Steps

Ultimately, you should aim to have an algorithm comprising only sequence/decision/repetitions of input/output/assignment steps. These correspond to the following common English sentence forms.

 

Important: note that there is no statement/sentence of the form "go to step x". Such forms are a remnant of the older go-to (spaghetti code) paradigm and must be rewritten using one of the structured programming paradigm forms below.

The correct form of the various control algorithm forms is:
(notice how they correspond one-to-one with the Java statements!)

sequence:
1.    do this 
2     do this
3.    do this 

 

decision:
1.    do this 

2     if condition then 
2T.1     do this 
2T.2     and this
      else 
2F.1     do that
2F.2     and that 

3.    do this 

 

while:
1.    do this 

2     while condition do 
2.1      something 
2.2      and something more 
2.3      and yet more 

3.    do this 

 

do-while:
1.    do this 

2     do 
2.1      something 
2.2      and something more 
2.3      and yet more
      while condition 

3.    do this 

 

for:
1.    do this 

2     for each value of i from 0 to number of repetitions do
2.1      something 
2.2      and something more 
2.3      and yet more

3.    do this 

Algorithm development examples:

Also, be sure you are not making any of these Common Algorithm Development Mistakes

Methods

Any step in your algorithm may be implemented as a method. You should already be identifying the data/memory/variable locations used in each step as being  I(nput), O(utput) or L(ocal) to the step, so the only additional consideration is what name you want to give it! Write the algorithm for the method separate from the other parts of your design and then simply "call" -use/refer- to it as necessary (in exactly the same way you already call/use/refer to Java methods such as those for input, output and square roots!)

Implementation

When implementing your program in Java you MUST follow our Java Style Guidelines!



Last updated: 02 Oct 2010
Please report any errors or omissions to the course instructor.