CISC 1115
Introduction to Programming Using Java
Lab #3
Testing for Divisibility / User-specified Loop Limits, Cascaded if/else

How to Develop and Submit your Labs

Lab 3.1 — A General Multiples Checker

Modify Program3.1 so that the user is prompted for:

Lab 3.2 — PicoSoft Damage Control (Approval)

That last idea at PicoSoft didn't work out too well … management has a massive public relations disaster on their hands, and thus they decide to revise the bonus structure, as well as give eveyone some additional vacation time.

Write a program that reads in (from the keyboard) the following information about an employee:

An employee's vacation time is based upon the following table:

Years worked Weeks of vacation
0-3 1
4-6 2
7 or more 3

Bonuses are determined by the following table:

Years worked Bonus
0-4 None
5-9 $200
10 or more 5% of annual salary

Your program should read in the information for an employee, calculate the vacation time and bonus amount for the employee, and display the employee's name, number of years worked, number of weeks of vacation and amount of bonus (on a single line). Please note that you are to print the actual amount of the bonus (calculated as 5% of the annual salary), and not simply the words 5% of salary".

This should be done for eight (8) employee (using a for loop).

Sample Test Run

Enter last name: Weiss
Enter first name: Gerald
Enter years worked: 1
Enter salary: 100
Gerald Weiss gets 1 weeks vacation, and a bonus of $0

Enter last name: Arnow
Enter first name: Davis
Enter years worked: 3
Enter salary: 200
Davis Arnow gets 1 weeks vacation, and a bonus of $0

Enter last name: Tenenbaum
Enter first name: Aaron
Enter years worked: 4
Enter salary: 100
Aaron Tenenbaum gets 2 weeks vacation, and a bonus of $0

Enter last name: Thurm
Enter first name: Joe
Enter years worked: 6
Enter salary: 100
Joe Thurm gets 2 weeks vacation, and a bonus of $200

Enter last name: Whitlock
Enter first name: Paula
Enter years worked: 7
Enter salary: 400
Paula Whitlock gets 3 weeks vacation, and a bonus of $200

Enter last name: Jones
Enter first name: Jackie
Enter years worked: 9
Enter salary: 500
Jackie Jones gets 3 weeks vacation, and a bonus of $200

Enter last name: Dreizen
Enter first name: Phil
Enter years worked: 10
Enter salary: 1000
Phil Dreizen gets 3 weeks vacation, and a bonus of $50

Enter last name: Augenstein
Enter first name: Moshe
Enter years worked: 12
Enter salary: 1500
Moshe Augenstein gets 3 weeks vacation, and a bonus of $75

This exercise is simply scaling things up as bit — in particular the conditions are a bit more challenging, and there are several of them

Lab 3.3 — Monkey in the Middle (Optional)

The median of a set of numbers is that number that falls into the middle when the numbers are in order. Thus the median of the numbers 12 19 4 24 27 84 6 is 19 (4 6 12 19 24 27 84). In particular the median of a set of three numbers if the number that falls in the middle, i.e., neither the minimum nor the maximum.

We presented in class a somewhat intricate method to calculate the maximum of three values, involving nested if/else statements (Program 3.3). Using the same approach (i.e.,nested if/else's enumerating all the possibilities) write a program that prompts for three integers and prints their median.

Though this exercise is optional, it is worth spending a bit of time on — it will help you appreciate the alternative methods.

Sample Test Run

Enter first number: 1
Enter second number: 2
Enter third number: 3
The median is: 2
The problem stated in this exercise — finding the median, is a classic, and at first appears to be similar to the minimum/maximum problems. The purpose of this exercise — other than presenting you with an interesting problem, and more coding pratice, is to show you that sometimes similar (even closely related) problems, sometimes require different approaches.