CS 280 Spring 2008

Assignment 8 – Multiple Classes Working Together

100 points

 

Assigned: 03/12/2008

Due: 03/19/2008 (after spring break) at the start of class

 

Pre-Lab (Do Before Lab):  Bring materials – a USB for a take home copy. Plan out your GUI, tasks, objects, and events needed for program.  Download, unzip and familiarize yourself with the partial Employee Class that I’m providing. Plan out how you will solve the problem.

 

Main Assignment:

You are writing some parts of an employee payroll (simplified demo) program. We are still quite a ways away from being able to do the whole job, so please pay attention to what I’m asking for. Your job is to 1) Write a Week class as described below (and in Javadoc documentation); 2) Add to the Employee class as described below (and in Javadoc documentation);  3) Write a GUI that demonstrates some of the capabilities as described below. You will be updating my provided Employee class, and will also be using (a tiny bit) another class I am providing (ID). These are provided in a zip file on Blackboard.  The zip also includes the javadoc generated html documentation for the classes. Your Week class should include static constants for minimum wage (currently $7.15 in PA) and full time work hours (40), and instance variables for: week number, pay rate (hourly), and hours worked (can be decimal). It should also provide the following methods:

·         3 constructors – the default, one that is passed the week number and pay rate (hours worked defaulting to 40), and one that is passed values for all 3 instance variables.

·         Simple inspectors for all 3 instance variables

·         Simple mutators for all 3 instance variables. Each should check the passed value, and if valid set the appropriate instance variable to the passed value and return true (return false if invalid). Valid values are:

o    Week number – positive

o    Pay rate – at or above minimum wage

o    Hours worked – from 0-100

·         A pseudo inspector that reports the amount of pay earned in the week. This info IS NOT stored, but rather is calculated based on hours worked and pay rate.  A person is paid their hourly salary for all hours worked, plus for any hours over full time (40), they are paid an extra 50%. E.g. A person paid $10 / hour who works 41 hours gets $10 / hour for 40 hours and $15 / hour for the 1 overtime hour.

·         A controlled mutator to add a passed value to the number of hours worked (useful if hours are being added day by day instead of waiting until the end of the week)

·         A toString method that turns a Week into a reasonable String representation of a Week. Show total pay earned in addition to the instance variables.

The Employee class has its instance variables declared already. These include an employee ID that uses the provided ID class, a last and first name, a current pay rate, and a Vector of Weeks that holds the Employee’s work info to enable paying them. Some methods are already provided. You need to add:

·         3 non-default constructors – one that is passed just the last name and first name; one that is passed the last name, first name, and current pay rate; and one that is passed the last name, first name, current pay rate and length of the employee ID. The later 2 constructors need to check that passed values are valid. If the pay rate is below the minimum wage, set it to minimum wage instead (Use Week’s constant). If the employee ID length is 3 or less, use 8 as the length. (Using the proper ID constructor will automatically create random employee ID numbers with check digits).

·         5 pseudo inspectors that report 1) total pay across all weeks, total hours worked across all weeks, average (mean) pay across all weeks, average (mean) hours worked across all weeks, and average pay per hour (total pay divided by total hours). Hint: to loop through Vector elements, I recommend a “foreach” loop.

·         A controlled mutator to give the employee a raise (for future weeks; past weeks are not changed). The mutator should check the passed increase to make sure it is reasonable (positive and no more than 0.50 (which is 50%!)). It should return true is passed value is valid, false if invalid.

·         A nice, friendly toString method that shows employee ID, name, current pay rate, and all of the work info by Week (with week number, hours worked, pay rate, and earned pay).

The user specifies general employee info first, then moves into week by week work information. While working week-by-week, the user can give the employee a raise. See my simple sample interface below – But don’t let that constrain your creativity. Use it to help understand what I see as the inputs and outputs. The paper version of this assignment shows a couple of screen shots from different points running my program. The version on my www site shows 13 screen shots from various points. We definitely want to control what the user can do at any given time (mostly by enabling and disabling buttons and jTextFields and jPanels). Details are given below. You should create buttons to:

1.      Start a new employee – will generate an employee Id and check that the current pay rate is valid. If valid, make the rest of the GUI available and disable new customer capabilities

2.      Update – adds a new week to the employee’s work info based on their current pay rate, and hours worked specified by the user (check if valid first). Display info for the week (continued) in a jTextArea

3.      See totals – see current info about the employee, including summary information

4.      Give Raise – check if raise amount is valid (greater than 0, less than or equal to 0.5). If valid, update current pay rate text field (and of course the employee object). Do not go back to previous weeks.

5.      Clear All – put GUI back in the condition it was at the start. AND, any variables global to the GUI class should be set back to their initial value as well.

6.      Write Results – capability removed – no longer required

7.      Exit – quits the demo.

·         You’re still really just beginning at setting up GUIs. Don’t worry too much about making the interface nice.

·         But, if you plan on working with 5.5 or higher version of the IDE, ask me about using layouts, panels, java version, etc so that your program will work with 5.0. (Java version needs to be 1.5, NOT 1.6).

 

Hand in:

 

Miscellaneous:

·         Please set the name of the project to something other than the default name (JavaApplication1, …). 

·         Put  your name in a jlabel on the GUI form OR on the Title Bar.

·         If the user enters letters into their current pay rate, hours, or their raise, parseDouble / parseInt will crash – no worries – we won’t deal with this until we cover exceptions a little more.

o    MAKE SURE YOUR PROGRAM WORKS! (i.e. gets correct results, controls what is displayed/enabled).  It must provide all of the requested capabilities AND provide them in the expected way – don’t change my code to make your code work!  Check that the desired parameters and return types are provided.

o    You MUST include some comments that explain your program in order to get full credit,  including a javadoc compatible comment for each method!!

 


On Start up

 

 

Trying to pay less than the minimum wage?

 

 

After Clicking New Button (with valid pay rate)

 

 

Trying to enter an invalid number of work hours for a week?

 

 

After entering one week’s hours

 

 

Two weeks:

 

 

Invalid raise amount?

 

 

After valid raise (0.10 – is 10%)

 

 

Higher pay after raise:

 

 

See Totals:

 

 

We haven’t really covered writing to files yet, so that is not allowed:

 

 

After Clear:

 

 

It really is cleared. When we come back in, the first employee’s results aren’t still hanging around: