Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

Gui Question

Thread view: 
IanH - 29 Mar 2006 11:47 GMT
Hi

I have to create a gui interface for employees to calculate their
salaries.  I have five separate classes. I can create the gui myself
and have been given the other five classes.  Now i need to link them
but not sure how to do so.  Is it through action listener and event
handlers? Or is there anywhere i could see an example

cheers
Ian
Thomas Weidenfeller - 29 Mar 2006 14:36 GMT
> I have to create a gui interface for employees to calculate their
> salaries.  I have five separate classes. I can create the gui myself
> and have been given the other five classes.  Now i need to link them
> but not sure how to do so.  Is it through action listener and event
> handlers? Or is there anywhere i could see an example

You could work for example through Sun's GUI tutorial. The TSC articles
about the AWT and Swing architecture, and about Java threading might
also be a good idea. Pointers are in the FAQ.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

bluesnake - 29 Mar 2006 14:52 GMT
I have learnt a lot from the book "Thinking in Java", you can get it
from http://www.mindview.net/Books/TIJ/

lqx
Rhino - 29 Mar 2006 15:32 GMT
> Hi
>
[quoted text clipped - 3 lines]
> but not sure how to do so.  Is it through action listener and event
> handlers? Or is there anywhere i could see an example

It's very  hard to suggest anything specific since you haven't given us any
idea what your five existing classes do beyond saying that they have
_something_ to do with employee salaries.

However, as a broad generalization - that may not be valid in your
situation - I would say that most programs using a GUI construct the GUI
very early on in the life of the program, then let the user initiate various
actions via buttons, menus or other controls in the GUI. Listeners and/or
event handlers will be attached to the GUI components and then initiate the
appropriate activities for responding to each GUI component.

I would suggest that you begin by reading through the examples that are
linked into this page of the Java Tutorial to get a good general overview of
how GUIs are constructed:
http://java.sun.com/docs/books/tutorial/uiswing/learn/index.html.

Then, if you want to explore particular components, go to
http://java.sun.com/docs/books/tutorial/uiswing/components/components.html
and click on the graphic for the GUI component(s) that you want to use to
see how to use it. In each case, you will be taken to a topic that explores
that control and how to use it via one or more small but useful examples.
The key lines of the source code for each example are explained in the topic
and links are provided so that you can run the example and see/download the
entire source code.

--
Rhino
IanH - 29 Mar 2006 20:43 GMT
Hi,
I have posted my code for the interface if anyone can help.  I have to
create an interface for employees pay.  I think i need to create an
instance of the object (object names are Employee, SalariedEmployee,
CommissionEmployee and BasePlusCommission)for each type of employee but
not sure.
Ian

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public interface Payable
{
double getPaymentAmout();
}

public class MyPanel extends JFrame implements ActionListener
{
   private JLabel labelfirstname;//
   private JTextField first;
   private JLabel labellastname;
   private JTextField last;
   private JLabel labelssn;
   private JTextField ssn;
   private JLabel labelhoursworked;
   private JLabel labelrateofpay;
   private JTextField hoursWorked;
   private JTextField rateOfPay;
   private JLabel labelsalary;
   private JTextField salary;
   private JLabel labeltotalsales;
   private JLabel labelcommission;
   private JTextField totalSales;
   private JTextField commission;
   private JButton buttonSubmit;
   private JLabel labeltype;
   private JComboBox type;
   private JLabel labeltext;
   private JTextArea textareaResults;
   private JLabel labelrenumeration;

   public MyPanel(String str)
   {
       super(str);

       //construct preComponents
       String[] typeItems = {"Hourly", "Salary", "Commission", "Base
plus Commission"};

       Container c = getContentPane();
       c.setLayout(null);
       setSize(850,650);
       setLocationRelativeTo(null);

       //construct components
       labelfirstname = new JLabel ("  First Name");
       add (labelfirstname);
       first = new JTextField (5);
       add (first);
       labellastname = new JLabel ("  Last Name");
       add (labellastname);
       last = new JTextField (5);
       add (last);
       labelssn = new JLabel ("  Social Security Number");
       add (labelssn);
       ssn = new JTextField (5);
       add (ssn);
       labelhoursworked = new JLabel ("  Hours Worked");
       add (labelhoursworked);
       labelrateofpay = new JLabel ("  Rate of Pay");
       add (labelrateofpay);
       hoursWorked = new JTextField (5);
       add (hoursWorked);
       rateOfPay = new JTextField (5);
       add (rateOfPay);
       labelsalary = new JLabel ("  Salary");
       add (labelsalary);
       salary = new JTextField (5);
       add (salary);
       labeltotalsales = new JLabel ("  Total Sales");
       add (labeltotalsales);
       labelcommission = new JLabel ("  Commission Rate");
       add (labelcommission);
       totalSales = new JTextField (5);
       add (totalSales);
       commission = new JTextField (5);
       add (commission);
       buttonSubmit = new JButton ("SUBMIT");
       add (buttonSubmit);
       labeltype = new JLabel (" Type of Employee");
       add (labeltype);
       type = new JComboBox (typeItems);
       add (type);
       labeltext = new JLabel ("  Please fill in only text boxes
appropriate to the type of Employee");
       add (labeltext);
       textareaResults = new JTextArea (5, 5);
       add (textareaResults);
       labelrenumeration = new JLabel ("  Renumeration");
       add (labelrenumeration);
       //adjust size and set layout
       setPreferredSize (new Dimension (646, 571));
       setLayout (null);

       //set component bounds (only needed by Absolute Positioning)
       labelfirstname.setBounds (15, 31, 72, 25);
       first.setBounds (90, 31, 110, 25);
       labellastname.setBounds (214, 31, 71, 25);
       last.setBounds (285, 31, 100, 25);
       labelssn.setBounds (400, 31, 144, 25);
       ssn.setBounds (545, 31, 100, 25);
       labelhoursworked.setBounds (15, 250, 100, 25);
       labelrateofpay.setBounds (225, 250, 76, 25);
       hoursWorked.setBounds (110, 250, 100, 25);
       rateOfPay.setBounds (305, 250, 100, 25);
       labelsalary.setBounds (10, 315, 51, 25);
       salary.setBounds (60, 315, 100, 25);
       labeltotalsales.setBounds (170, 315, 100, 25);
       labelcommission.setBounds (379, 315, 112, 25);
       totalSales.setBounds (246, 315, 100, 25);
       commission.setBounds (494, 315, 100, 25);
       buttonSubmit.setBounds (505, 350, 100, 25);
       labeltype.setBounds (15, 110, 110, 20);
       type.setBounds (125, 105, 135, 25);
       labeltext.setBounds (15, 185, 370, 25);
       textareaResults.setBounds (50, 410, 565, 140);
       labelrenumeration.setBounds (50, 385, 100, 25);

   //register event handlers

       buttonSubmit.addActionListener( this );

   }//end MyPanel constuctor

       //process events

       public void actionPerformed( ActionEvent event)
       {

   if (event.getSource() == buttonSubmit)

   {
            //Enabling the Text Area's
            first.setEnabled (true);
           last.setEnabled (true);
           ssn.setEnabled (true);
           type.setEnabled (true);
           hoursWorked.setEnabled (true);
           rateOfPay.setEnabled (true);
           salary.setEnabled (true);
           totalSales.setEnabled (true);
           commission.setEnabled (true);

            //Setting the Text Area's to Null
           first.setText("");
           last.setText("");
           ssn.setText("");
           //type.setText("");
           hoursWorked.setText("");
           rateOfPay.setText("");
           salary.setText("");
           totalSales.setText("");
           commission.setText("");

        }

     // create subclass objects

    // SalariedEmployee salariedEmployee =  new SalariedEmployee;

     //HourlyEmployee hourlyEmployee = new HourlyEmployee();

    // CommissionEmployee commissionEmployee =   new
CommissionEmployee();

     //BasePlusCommissionEmployee basePlusCommissionEmployee =  new
BasePlusCommissionEmployee();

}

   public static void main (String[] args)
   {

       MyPanel pr = new MyPanel("ww");
       pr.show();
       //JFrame frame = new JFrame ("MyPanel");
       //frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
       //frame.getContentPane().add (new MyPanel());
       //frame.pack();
       //frame.setVisible (true);
   }
}
//
Rhino - 29 Mar 2006 22:01 GMT
> Hi,
> I have posted my code for the interface if anyone can help.  I have to
> create an interface for employees pay.  I think i need to create an
> instance of the object (object names are Employee, SalariedEmployee,
> CommissionEmployee and BasePlusCommission)for each type of employee but
> not sure.

At the very least, I think you need to post the complete text of the
assignment. It is impossible to guide you very far without knowing what you
are trying to do. You can't do the assignment without having a clear
understanding of what is required and it is just as hard for us to help you
if we don't know what you are trying to accomplish.

I also think it would be a good idea for you to work through the general
overview of how GUIs are constructed in the Java Tutorial -
http://java.sun.com/docs/books/tutorial/uiswing/learn/index.html - to get
the basic concepts down before we try to tackle this specific problem. Even
if you don't have the time to actually play with the examples, just reading
that section through carefully will give you a foundation of concepts and
techniques that we need to have in common before we can talk about your
assignment. It really shouldn't take you very long to read through this
section so I highly recommend that you do this.

Naturally, if you have course notes or a textbook that you like better which
covers the same sort of material, feel free to read that instead of this
section of the Java tutorial. Everyone has their own best way of learning
and you need to use the learning techniques that work best for you. But I
think you need to get some of the concepts under your belt before we can
really converse about what you are going to do.

--
Rhino
IanH - 29 Mar 2006 22:47 GMT
I'm reading through the java sun tutorials but finding it pretty hard
as i'm new to all of this.

My assignment is to develop an interface that will run the Payroll
System application for five classes we have been given.  Using a
JComboBox and JTextFields, allow the user to specify the type of
employee they wish to create and specify the data concerning that
employee. Have the output displayed in a JTextArea. I have included the
five classes plus the test class which just outputs the predefined
data.

Ian

Employee Class
_________________________________________________

public abstract class Employee implements MyPanel
{
  private String firstName;
  private String lastName;
  private String socialSecurityNumber;

  // three-argument constructor
  public Employee( String first, String last, String ssn )
  {
     firstName = first;
     lastName = last;
     socialSecurityNumber = ssn;
  } // end three-argument Employee constructor

  // set first name
  public void setFirstName( String first )
  {
     firstName = first;
  } // end method setFirstName

  // return first name
  public String getFirstName()
  {
     return firstName;
  } // end method getFirstName

  // set last name
  public void setLastName( String last )
  {
     lastName = last;
  } // end method setLastName

  // return last name
  public String getLastName()
  {
     return lastName;
  } // end method getLastName

  // set social security number
  public void setSocialSecurityNumber( String ssn )
  {
     socialSecurityNumber = ssn; // should validate
  } // end method setSocialSecurityNumber

  // return social security number
  public String getSocialSecurityNumber()
  {
     return socialSecurityNumber;
  } // end method getSocialSecurityNumber

  // return String representation of Employee object
  public String toString()
  {
     return String.format( "%s %s\nsocial security number: %s",
        getFirstName(), getLastName(), getSocialSecurityNumber() );
  } // end method toString

 // we do not implement Payable method getPaymentAmount here so
 // this class must be declared abstract to avoid a compilation error
} // end abstract class Employee

Salaried Employee
______________________________

   public class SalariedEmployee extends Employee
{
  private double weeklySalary;

  // four-argument constructor
  public SalariedEmployee( String first, String last, String ssn,
     double salary )
  {
     super( first, last, ssn ); // pass to Employee constructor
     setWeeklySalary( salary ); // validate and store salary
  } // end four-argument SalariedEmployee constructor

  // set salary
  public void setWeeklySalary( double salary )
  {
     weeklySalary = salary < 0.0 ? 0.0 : salary;
  } // end method setWeeklySalary

  // return salary
  public double getWeeklySalary()
  {
     return weeklySalary;
  } // end method getWeeklySalary

  // calculate earnings; implement Payable method that was
  // abstract in superclass employee
  public double getPaymentAmount()
  {
     return getWeeklySalary();
  } // end method getPaymentAmount

  // return String representation of SalariedEmployee object
  public String toString()
  {
     return String.format( "salaried employee: %s\n%s: $%,.2f",
        super.toString(), "weekly salary", getWeeklySalary() );
  } // end method toString
} // end class SalariedEmployee

Commission Employee
_________________________

public class CommissionEmployee extends Employee
{
  private double grossSales; // gross weekly sales
  private double commissionRate; // commission percentage

  // five-argument constructor
  public CommissionEmployee( String first, String last, String ssn,
     double sales, double rate )
  {
     super( first, last, ssn );
     setGrossSales( sales );
     setCommissionRate( rate );
  } // end five-argument CommissionEmployee constructor

  // set commission rate
  public void setCommissionRate( double rate )
  {
     commissionRate = ( rate > 0.0 && rate < 1.0 ) ? rate : 0.0;
  } // end method setCommissionRate

  // return commission rate
  public double getCommissionRate()
  {
     return commissionRate;
  } // end method getCommissionRate

  // set gross sales amount
  public void setGrossSales( double sales )
  {
     grossSales = ( sales < 0.0 ) ? 0.0 : sales;
  } // end method setGrossSales

  // return gross sales amount
  public double getGrossSales()
  {
     return grossSales;
  } // end method getGrossSales

  // calculate earnings; implement interface Payable method that was
  // abstract in superclass Employee
  public double getPaymentAmount()
  {

     return getCommissionRate() * getGrossSales();
  } // end method getPaymentAmount

  // return String representation of CommissionEmployee object

  // return String representation of CommissionEmployee object
  public String toString()
  {
     return String.format( "%s: %s\n%s: $%,.2f; %s: %.2f",
        "commission employee", super.toString(),
        "gross sales", getGrossSales(),
        "commission rate", getCommissionRate() );
  } // end method toString
} // end class CommissionEmployee

Hourly Employee
_______________________

public class HourlyEmployee extends Employee
{
  private double wage; // wage per hour
  private double hours; // hours worked for week

  // five-argument constructor
  public HourlyEmployee( String first, String last, String ssn,
     double hourlyWage, double hoursWorked )
  {
     super( first, last, ssn );
     setWage( hourlyWage ); // validate and store hourly wage
     setHours( hoursWorked ); // validate and store hours worked
  } // end five-argument HourlyEmployee constructor

  // set wage
  public void setWage( double hourlyWage )
  {
     wage = ( hourlyWage < 0.0 ) ? 0.0 : hourlyWage;
  } // end method setWage

  // return wage
  public double getWage()
  {
     return wage;
  } // end method getWage

  // set hours worked
  public void setHours( double hoursWorked )
  {
     hours = ( ( hoursWorked >= 0.0 ) && ( hoursWorked <= 168.0 ) ) ?
        hoursWorked : 0.0;
  } // end method setHours

  // return hours worked
  public double getHours()
  {
     return hours;
  } // end method getHours

  // calculate earnings; implement interface Payable method that was
  // abstract in superclass Employee
  public double getPaymentAmount()
  {
     if ( getHours() <= 40 ) // no overtime
        return getWage() * getHours();
     else
        return 40 * getWage() + ( getHours() - 40 ) * getWage() * 1.5;
  } // end method getPaymentAmount

  // return String representation of HourlyEmployee object
  public String toString()
  {
     return String.format( "hourly employee: %s\n%s: $%,.2f; %s:
%,.2f",
        super.toString(), "hourly wage", getWage(),
        "hours worked", getHours() );
  } // end method toString
} // end class HourlyEmployee

BasePlus Commission
__________________

public class BasePlusCommissionEmployee extends CommissionEmployee
{
  private double baseSalary; // base salary per week

  // six-argument constructor
  public BasePlusCommissionEmployee( String first, String last,
     String ssn, double sales, double rate, double salary )
  {
     super( first, last, ssn, sales, rate );
     setBaseSalary( salary ); // validate and store base salary
  } // end six-argument BasePlusCommissionEmployee constructor

  // set base salary
  public void setBaseSalary( double salary )
  {
     baseSalary = ( salary < 0.0 ) ? 0.0 : salary; // non-negative
  } // end method setBaseSalary

  // return base salary
  public double getBaseSalary()
  {
     return baseSalary;
  } // end method getBaseSalary

   // calculate earnings; implement interface Payable method that was
  // abstract in superclass Employee
  public double getPaymentAmount()
  {
     return getBaseSalary() + super. getPaymentAmount();
  } // end method getPaymentAmount

  // return String representation of BasePlusCommissionEmployee object
  public String toString()
  {
     return String.format( "%s %s; %s: $%,.2f",
        "base-salaried", super.toString(),
        "base salary", getBaseSalary() );
  } // end method toString
} // end class BasePlusCommissionEmployee

Test Data
______________________

   // Tests Payable Interface

  public class PayableInterfaceTest
  {
      public static void main( String args[] )
  {
     // create subclass objects
     SalariedEmployee salariedEmployee =
        new SalariedEmployee( "John", "Smith", "111-11-1111", 800.00
);
     HourlyEmployee hourlyEmployee =
        new HourlyEmployee( "Karen", "Price", "222-22-2222", 16.75, 40
);
     CommissionEmployee commissionEmployee =
        new CommissionEmployee(
        "Sue", "Jones", "333-33-3333", 10000, .06 );
     BasePlusCommissionEmployee basePlusCommissionEmployee =
        new BasePlusCommissionEmployee(
        "Bob", "Lewis", "444-44-4444", 5000, .04, 300 );

     System.out.println( "Employees processed individually:\n" );

     System.out.printf( "%s\n%s: $%,.2f\n\n",
        salariedEmployee, "earned",
salariedEmployee.getPaymentAmount() );
     System.out.printf( "%s\n%s: $%,.2f\n\n",
        hourlyEmployee, "earned", hourlyEmployee.getPaymentAmount() );
     System.out.printf( "%s\n%s: $%,.2f\n\n",
        commissionEmployee, "earned",
commissionEmployee.getPaymentAmount() );
     System.out.printf( "%s\n%s: $%,.2f\n\n",
        basePlusCommissionEmployee,
        "earned", basePlusCommissionEmployee.getPaymentAmount() );

     // create four-element Employee array
     Employee employees[] = new Employee[ 4 ];

     // initialize array with Employees
     employees[ 0 ] = salariedEmployee;
     employees[ 1 ] = hourlyEmployee;
     employees[ 2 ] = commissionEmployee;
     employees[ 3 ] = basePlusCommissionEmployee;

     System.out.println( "Employees processed polymorphically:\n" );

     // generically process each element in array employees
     for ( Employee currentEmployee : employees )
     {
        System.out.println( currentEmployee ); // invokes toString

        // determine whether element is a BasePlusCommissionEmployee
        if ( currentEmployee instanceof BasePlusCommissionEmployee )
        {
           // downcast Employee reference to
           // BasePlusCommissionEmployee reference
           BasePlusCommissionEmployee employee =
              ( BasePlusCommissionEmployee ) currentEmployee;

           double oldBaseSalary = employee.getBaseSalary();
           employee.setBaseSalary( 1.10 * oldBaseSalary );
           System.out.printf(
              "new base salary with 10%% increase is: $%,.2f\n",
              employee.getBaseSalary() );
        } // end if

        System.out.printf(
           "earned $%,.2f\n\n", currentEmployee.getPaymentAmount() );
     } // end for

     // get type name of each object in employees array
     for ( int j = 0; j < employees.length; j++ )
        System.out.printf( "Employee %d is a %s\n", j,
           employees[ j ].getClass().getName() );
  } // end main
} // end class PayrollSystemTest
Rhino - 30 Mar 2006 06:29 GMT
> I'm reading through the java sun tutorials but finding it pretty hard
> as i'm new to all of this.
[quoted text clipped - 6 lines]
> five classes plus the test class which just outputs the predefined
> data.

Okay, I'm starting to develop a mental picture of what you'll need to do to
solve this problem. I need to think about it a bit more to get a good solid
idea of exactly how the GUI will flow.

In the meantime, keep working your way through the GUI tutorial. Don't worry
too much if you don't understand everything but make a point of writing down
your questions whether they are big conceptual questions or smaller detail
questions. When you've gone through the tutorial material and have a list of
questions, post them here and we can try to answer them in a way that is
clear for you.

Then, you should be in a good position to work out a lot of the solution to
your current problem. Again, we can help you with specific questions that
you might have about solving the problem.

As you think about this problem, ask yourself what the user should see when
they do the work envisioned in the assignment, i.e. when they add employees
and calculate payment amounts for the next payroll. It would be very useful
for you to sketch the screens that the user will see and exactly what
fields, labels, and buttons (or other controls) will be on each screen.
Then, we can help verify that you are asking for the right things in the
right sequence and help you build the screens and the handling of the data
and controls.

By the way, when I say "we", I'm not employing the "royal we"; I hope that
at least the two of us work on this until you feel comfortable enough to
finish on your own. Ideally, others on this newsgroup will also jump in to
suggest things.

--
Rhino
IanH - 30 Mar 2006 08:32 GMT
I do have some questions

1.  Do I need to use the following code to declare instances of the
objects?

SalariedEmployee salariedEmployee =  new SalariedEmployee

HourlyEmployee hourlyEmployee = new HourlyEmployee

CommissionEmployee commissionEmployee =   new CommissionEmployee

BasePlusCommissionEmployee basePlusCommissionEmployee =  new
BasePlusCommissionEmployee

2.  the combobox on the interface currently doesn't have any action
attached to it. Can i use it to specify the type of employee to create.

Ian
Bjorn Abelli - 30 Mar 2006 13:44 GMT
"IanH" wrote...
>I do have some questions
>
[quoted text clipped - 9 lines]
> BasePlusCommissionEmployee basePlusCommissionEmployee =  new
> BasePlusCommissionEmployee

You'll need to do it somewhere to have any instances to play with, just as
in the PayableInterfaceTest your teacher has provided.

> 2.  the combobox on the interface currently doesn't have any action
> attached to it. Can i use it to specify the type of employee to create.

Sure you can, if that's what you want.

As this seems to be a school assignment, you could take the easy way out,
and that is to

- have JTextFields for all attributes in the classes (those needed
 in the constructors in each class).

- use the JComboBox "passively" just to choose which type of instance
 you want to create,

- use a JButton (with an associated ActionListener) in order to:

 o. instantiate from the chosen class
   (get selected value from the JComboBox),

 o. store the instance in an ArrayList,

 o. and put the output in a JTextArea
   (similar to what's printed from the PayableInterfaceTest)

My guess is that you will have another assignment to follow, where you will
be able to retrieve the data from the already created employees...

BTW, have you tested the classes you already have against the
PayableInterfaceTest? It won't work unless you add the operation
getPaymentAmount in the class Emplyoee...

And how does the interface MyPanel come into the assignment? What does that
look like? Why must Employee implement that?

// Bjorn A
Rhino - 30 Mar 2006 15:45 GMT
>I do have some questions
>
[quoted text clipped - 9 lines]
> BasePlusCommissionEmployee basePlusCommissionEmployee =  new
> BasePlusCommissionEmployee

You will need to put a pair of brackets after the second occurrence of the
Class name on each line, e.g.

   SalariedEmployee salariedEmployee = new SalariedEmployee();

Those brackets are important; you will get compile errors if you omit them.
Also, if the constructors for those classes expect input parameters, you
will need to supply those values within the brackets, e.g.

   SalariedEmployee salariedEmployee = new SalariedEmployee("Tony",
"Blair", "123-45-6789", 800.00);

The PayableInterfaceTest class does exactly the same thing to create
employees as you can see.

> 2.  the combobox on the interface currently doesn't have any action
> attached to it. Can i use it to specify the type of employee to create.

By 'it' in your second sentence, I assume you mean the comboBox: if that is
the case, the answer is yes. That appears to be exactly what they want you
to do. You'll need to put the different types of employees in the comboBox
before you display the comboBox to the user. Then, the user will choose one
of the types when the GUI is presented.

You will need to wait for the user to choose one of the employee types from
the comboBox, then detect the fact that a selection has been made.

Your code will then need to display the input form that is appropriate for
that type of employee. For example, if the user specifies a
salariedEmployee, you will need to display a form that prompts for the
employee's first name, last name, social security number, and weekly salary.
The form will vary for each type of employee. In each case, you'll need to
detect that the form has been filled out. You may want to have the user
click a button to indicate that they've finished completing the form; that
would be the most common approach to this situation and is easier to code
than any other approach that comes to mind.

When you know the form has been completed, you need to compute the pay for
that employee and display the amount of that employee's pay in the text area
that the assignment suggested.

--

It's unfortunate but perhaps inevitable that several aspects of this
assignment are not very realistic. In the real world, employees would get
entered into the payroll system when they got hired. Information like their
name and social security number and annual salary or hourly salary or
commission rate would get recorded _once_ and stay in effect until the
information changed for some reason. The data would most likely be recorded
in a database.

The actual weekly payroll run would not need to capture any of that
information anew. The only new data that the payroll run would need would be
the number of hours worked that week for hourly employees and the sales for
the commissioned employees. Then the payroll program could calculate the
amount to pay each employee and print the cheques.

Clearly, your assignment envisions combining all of this work into a weekly
run which would be very tedious for the payroll department if it were
actually done that way. But your instructor probably only has limited time
to spend on a given area of programming so you are combining things somewhat
unrealistically so that you can cover more ground in the time available.
That's understandable but it would be wise for you to remember that the real
world won't work exactly the way the assignments do. That should be a
comfort in case you're thinking ahead to the real world and wondering why
anyone would do a payroll this way when much more efficient approaches would
make more sense ;-)

--
Rhino
Oliver Wong - 30 Mar 2006 16:10 GMT
> It's unfortunate but perhaps inevitable that several aspects of this
> assignment are not very realistic. In the real world, employees would get
[quoted text clipped - 9 lines]
> for the commissioned employees. Then the payroll program could calculate
> the amount to pay each employee and print the cheques.

   Back in the old days (or so I've heard; I wasn't alive at the time), we
didn't have databases, and harddrives were extremely rare. Every week, a set
of punch cards would be fed into the machine, along with the data, and the
program would calculate everyone's pay from that data. The data had to be
fed in every time the program was to run.

   - Oliver
Rhino - 30 Mar 2006 18:56 GMT
>> It's unfortunate but perhaps inevitable that several aspects of this
>> assignment are not very realistic. In the real world, employees would get
[quoted text clipped - 15 lines]
> the program would calculate everyone's pay from that data. The data had to
> be fed in every time the program was to run.

Yeah, I know that things were done that way once upon a time. Ian's
instructor may be trying to model this archaic way of doing things just for
the sake of a good challenge to his class. But I think you'll agree that it
isn't the way things would be done today, except possibly in the third world
where technology is rather scarcer than it is here.

--
Rhino
Rhino - 31 Mar 2006 22:55 GMT
>I do have some questions
>
[quoted text clipped - 12 lines]
> 2.  the combobox on the interface currently doesn't have any action
> attached to it. Can i use it to specify the type of employee to create.

Ian,

I haven't seen a new post from you on this thread in a while. Have you
finished the assignment or are you so confused that you don't know what to
do?

If the former, great! If the latter, please try to articulate the nature of
the problem as best you can and we will try to help you get moving again.
There's nothing too tricky in the final code. We can probably explain the
concepts and give some bits of the code if you need something to get you
properly started.

--
Rhino


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.