Results 1 to 6 of 6
- 04-23-2011, 06:17 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
Confusion with Payroll Application
Ok gals and guys,
I need some help figuring this project out. I want to create a payroll application that reads data from an input file. I have created an Employee Superclass that holds the employee name, ID#, and address. I also have two subclasses that will calculate gross pay for hourly (one class), and gross pay for commissioned employees(the other class). My issue is how the heck can I read the input values from my input file and create objects from that.
At first I thought about making an arraylist but is it possible to make an arraylist from multiple classes? If I can, then I figred I'll do a for each loop and return the grosspay() depending on wheather the employee is commissioned or hourly.
My other option is to create the objects within the main by reading the paramaters for HrlyEmployee and CommissionedEmployee by line number. I am having an issue figuring this out. I am new to this and sometimes just need someone to turn me in the right direction. Heres what I have...
Java Code:public class Employee { private String name; private int employeeID; private String address; private double grossPay; /** * Constructs an employee with given name, ID number, and address. * @param aName the name of the employee * @param anEmployeeNumber the ID number of the employee * @param anAddress the employee address */ public Employee(String aName, int anEmployeeNumber, String anAddress) { name = aName; employeeID = anEmployeeNumber; address = anAddress; } /** * Sets the name of the employee * @param the new employee name */ public void setName(String newName) { name = newName; } /** * Gets the name of the employee * @return the employee name */ public String getName() { return name; } /** * Sets the ID number of the employee * @param the new employee ID */ public void setEmployeeID(int newEmployeeID) { employeeID = newEmployeeID; } /** * Gets the employee ID Number. * @return employee ID number */ public int getEmployeeID() { return employeeID; } /** * Sets the address of the employee * @param the new employee address */ public void setAddress(String newAddress) { address = newAddress; } /** * Gets the address of the employee * @return the employee address */ public String getAddress() { return address; } /** * Calculates the gross pay of the employee based on hours worked * pay rate. * @param amount which is the hours worked in a week * @param rate which is the pay rate for that employee */ public void calculateGrossPay(double amount, double rate) { grossPay = amount * rate; } /** * Calculates the grossPay from the hours worked and pay rate * @return the grossPay */ public double getGrossPay() { return grossPay; } }Java Code:public class HrlyEmployee extends Employee { private double hours; private double rate; /** * Constructs an hourly employee with number of hours worked and hourly pay rate. * @param number of hours worked. * @param the hourly pay rate. */ public HrlyEmployee(double someHours, double aRate, String aName, int anEmployeeNumber, String anAddress) { super(aName, anEmployeeNumber, anAddress); hours = someHours; rate = aRate; } /** * Sets the hours worked in the week * @param newHours which is the new number of hours worked */ public void setHours(double newHours) { hours = newHours; } /** * Gets the number of hours worked * @return hours which is the number of hours worked. */ public double getHours() { return hours; } /** * Sets the pay rate for the employee * @param newRate for the employee. */ public void setRate(double newRate) { rate = newRate; } /** * Gets the employee pay rate * @return rate per hour */ public double getRate() { return rate; } /** * Calculates the gross pay of the employee based on hours worked * pay rate. * @param amount which is the hours worked in a week * @param rate which is the pay rate for that employee */ public void calculateGrossPay(double amount, double rate) { super.calculateGrossPay(amount, rate); } }Excerpt of input fileJava Code:public class CommissionEmployee extends Employee { private double sales; private double commission; /** * Constructs an commissioned employee with amount of sales * commission rate. * @param amount of sales. * @param the commission rate. */ public CommissionEmployee(double someSales, double aCommission, String aName, int anEmployeeNumber, String anAddress) { super(aName, anEmployeeNumber, anAddress); sales = someSales; commission = aCommission; } /** * Sets the number of sales made a week. * @param newSales which is the new number of sales made */ public void setSales(double newSales) { sales = newSales; } /** * Gets the number of sales made * @return sales the number of sales made. */ public double getSales() { return sales; } /** * Sets the commission rate for the employee * @param newCommission for the employee. */ public void setCommission(double newCommission) { commission = newCommission; } /** * Gets the commission rate * @return commission percentage */ public double getCommission() { return commission; } /** * Calculates the gross pay of the employee based on WeeklySales * CommissionRate. * @param amount which is weekly sales * @param rate which is the commission rate for the employee */ public void calculateGrossPay(double hours, double rate) { super.calculateGrossPay(hours, rate); } }
Good Employee
1
1234 Main Street, Somewhere, NA 99921
40
50.00
-
How can you tell by the file data which type of Employee each record refers to?
- 04-23-2011, 06:42 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
I realize that you can't tell from the data file. I figured that I would need to do something like this:
FileReader reader = new FileReader("InputFile.txt");
HlryEmployee anHrlyEmployee = new HrlyEmployee();
anHrlyEmployee.setName(Line1) //This is wrong, but this is kind of what I'm thinking
anHrlyEmployee.setAddress(...) etc.
Doing the same as i add employees to the data file for commissioned. I know this is flawed, but with my limited knowledge, this is the only way I can think of.
-
can you show us a good portion of the data file? Maybe you can tell which Employee type is desired by each record's data.
- 04-23-2011, 06:56 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
The data file is my creation, so if I need to add a field that stated Hourly/Commissioned I can do so. There really isn't any more to it. So for commissioned:
Good HrlyEmployee <== name
1 <== employee number
1234 Main Street, Somewhere, NA 99921 <== address
40 <== number of hours worked
50.00 <== pay rate per hour
Good CommEmployee <== Employee Name
2 <== Employee Number
1234 Google Street, Somewhere, NA 99921 <== address
1254 <== sales number
0.25 <== commission percentage
-
You'll probably need to give the data file an additional line that indicates what type of Employee it refers to.
Better to use XML or database to hold the information for you.
Similar Threads
-
backup -- payroll system
By princess000 in forum Forum LobbyReplies: 10Last Post: 02-27-2011, 11:41 AM -
Payroll program
By bigley04 in forum EclipseReplies: 7Last Post: 12-06-2010, 04:57 PM -
payroll generation
By kriti in forum New To JavaReplies: 5Last Post: 06-02-2010, 03:21 PM -
Payroll Project 1 Troubles
By KiskaBaker in forum New To JavaReplies: 3Last Post: 08-16-2009, 12:41 PM -
help for payroll project in java
By mageshwari in forum New To JavaReplies: 2Last Post: 04-09-2008, 02:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks