CSC 171 LAB #4

FALL 2001

 

GOAL:

1.        Become familiar with the use of pseudocode as a tool for algorithm development

2.        Become familiar with the if/else selection structure

3.        Become familiar with the while repetition structure

 

TASKS:

·         Read and understand the requirements, below

·         Write a pseudocode description of the program meeting the requirements

·         Implement your pseudocode in JAVA

·         Demonstrate the program in your lab

 

 

REQUIREMENTS:

 

You a JAVA application that will determine payroll information for the employees of the latest new Silicon Valley dot-bomb www.we-don’t-do-or-sell-anything-but-the-VCs-gave-us-money-anyway.com . Employees are paid $1,000 per week, plus $30 per hour if, by some coincidence, they actually happen to work during the week. Federal law requires that they are paid time and a half for overtime (>40 hours in any one week). Calculate tax withholdings at 35% of gross pay for part-time employees (<20 hours), 45% for full time employees (>= 20 hours).

 

Your program should use input dialogs for data entry. The user enters the number of hours worked by the employee. Calculate the gross pay, the tax withholdings and the net pay. Write these values out to the command line. Because the company never really knows how many people are working for it at any given time sentinel controlled repetition is in order. The user enters a negative value for the hours to signal end of input.

 

 

STEPS:

 

1.        Read Chapter 4. Pay special attention to Example 4.9 – the sentinel case study.

2.        Read the requirements and write a pseudocode description of the algorithm. You will be handing in the pseudocode. (Don’t give in to the temptation to write the program and then do the pseudocode. It is important to get into the habit of writing down your design before you start coding. While it is easy to write small programs without this design step it is a vital skill for large systems. If you do not practice this technique on small programs, it will be too cumbersome to learn when it is time to write large programs. Many studies of the programming practice demonstrate that code written without good design process contains more bugs and is of lower quality than well designed code. All top programmers use some form of these techniques, but in order to be effective they must be habitual – second nature. It is important to develop this habit early.)

3.        Write your pseudocode as a big block comment in a .java file. When you are done, copy the entire block comment (so that your java file starts as two copies of your algorithm). Keep one of the copies as a single block comment. Convert the second copy to a sequence of single line comments. Then, write your code around the single line comments. (If in the course of actually writing the program you decide to do something different than what you designed, that is ok – don’t delete the old comment – just add a new one.)

4.        In writing the pseudocode ask yourself the following questions:

1.        What is the containment structure of the program. (e.g. do the loops contain the if statements, or vica versa?)

2.        What repetitions must your program have? How may loops do you need? What do they each do?

3.        What decisions must your program make? How many ifs do you need?

5.        Once you have the pseudocode in terms of comments, write your code around each comment.

6.         Ok, you are done to get credit for all this work you need to get a piece of paper ready for your lab TA. This paper must have 2 things on it.

1.        Your name and lab section

2.        Your final version of the program with the pseudocode comments

7.        When you get the paper ready call your lab TA over and demo the program for her/him. Give the paper to your TA. This completes the hand in process. The deadline is one week – no late assignments accepted.