Results 21 to 29 of 29
- 03-24-2011, 01:25 AM #21
Member
- Join Date
- Mar 2011
- Posts
- 15
- Rep Power
- 0
put this at top of payroll class:
ArrayList<Employee> emps = new ArrayList<Employee>();
so in the separate areas below after they choose empType would I do this:?
emps.add(new Salaried());
or emps.add(new Employee(salaried());
and then the same for the hourly section but replacing salaried obvioulsy?
I'm sure both of those are incorrect, but how do I format the passing of the above mentioned constructors from the other classes to add in arraylist?
- 03-24-2011, 01:30 AM #22
Member
- Join Date
- Mar 2011
- Posts
- 15
- Rep Power
- 0
or do I have to do separate ArrayLists Like this at top:
ArrayList<Salaried> sal = new ArrayList<Salaried>();
ArrayList<hourly> hour = new ArrayList<hourly>();
and then later using it something like:
sal.add(new Salaried());
hour.add(new Hourly());
- 03-24-2011, 01:32 AM #23
Java Code:emps.add(new Salaried());
- 03-24-2011, 01:47 AM #24
Member
- Join Date
- Mar 2011
- Posts
- 15
- Rep Power
- 0
so if they, let's say choose salaried. I would do something like
while (scan.HasNext())
{
emps.add(new Salaried()) = scan.next();
}
? or something of this fashion? They should be entering data that constructor below in the Salaried class uses and trying to store it in the new ArrayList emps:
public Salaried (String _name, String _socSecNum, double _pay)
- 03-24-2011, 01:50 AM #25
This is not legal syntax. You would get user input first and then create the object and add it to the list. The 2nd and 3rd steps can be done in one line.Java Code:emps.add(new Salaried()) = scan.next();
- 03-24-2011, 01:55 AM #26
Member
- Join Date
- Mar 2011
- Posts
- 15
- Rep Power
- 0
oh, wait, now I am really confused. I have to use that mentioned constructor to store that data in the arraylist for that employee, but I am looking at the output and it shows the prompt saying enter name, storing name, then asking for SSN, storing SSN, asking payrate, storing payrate. Now I really have no idea how to go about this.
- 03-24-2011, 02:00 AM #27
What output? Do you mean sample output of what your assignment should look like? You may have to get clarification from your teacher. What you can do is create a default object and then each time you get user input use a setter method to set the objects values. Then at the end add it to the list.
- 03-24-2011, 02:07 AM #28
Member
- Join Date
- Mar 2011
- Posts
- 15
- Rep Power
- 0
here is my Hourly class. I need to prompt them one at a time for name, SSN, hourlyRateOfPay, and average hours worked:
public class Hourly implements Company
{
private double OVERTIME_HOURS = 40;
private double OVERTIME_RATE = 1.5;
private String name;
private String socSecNum;
private double avgHoursWorked;
private double pay;
// constructor to build hourly employee
public Hourly ( String _name, String _socSecNum, double _pay)
{
name = _name;
socSecNum = _socSecNum;
pay = _pay;
}
public void setPay(double payRate)
{
pay = payRate;
}
public double calcAnnualPay()
{
double annPay = this.calcWeeklyPay() * WEEKS_PAID;
return annPay;
}
public double calcWeeklyPay()
{
double weeklyPay = 0;
if (avgHoursWorked > OVERTIME_HOURS)
{
weeklyPay = (OVERTIME_HOURS * pay) + ((avgHoursWorked - OVERTIME_HOURS)*
pay * OVERTIME_RATE);
}
else
{
weeklyPay = avgHoursWorked * pay;
}
return weeklyPay;
}
public String toString()
{
String s = "Name: "+ "\tname\n" + "SSN: \n" + "\t\tAverage Hours Worked:\t" + "$\t" + avgHoursWorked +
"Hourly Rate: $ " + pay + "\n\t\t" +
"Average Weekly Pay: $ " + calcWeeklyPay() + "\n" + "Average Annual Pay: $ " +
calcAnnualPay();
return s;
}
} // end class
- 03-24-2011, 02:18 AM #29
Member
- Join Date
- Mar 2011
- Posts
- 15
- Rep Power
- 0
but the main functional class is the payroll class that has the arraylist in it. do I have to make separate local variables within payroll employee creation section for each thing needed then prompt for each value, then once all are entered and validated then create the "new Salaried" and THEN call the constructor to create the new employee and then set pay and averageHoursWorked(which I just noticed I have no setAvgHoursWkd() method for.?
Similar Threads
-
Verifying of Month
By ŖàΫ ỏƒ Ңόρę in forum New To JavaReplies: 2Last Post: 11-02-2010, 04:34 PM -
Client cannot retrieve all strings from the InputStreamReader through a loop
By yadav in forum NetworkingReplies: 0Last Post: 05-19-2010, 05:38 PM -
Need help writing program to compare 2 strings using a loop
By kornwheat in forum New To JavaReplies: 15Last Post: 11-06-2009, 10:31 AM -
While loop comparing strings from user
By N3VRMND in forum New To JavaReplies: 5Last Post: 10-30-2009, 08:18 AM -
Verifying existence of a table in a db
By Java Tip in forum Java TipReplies: 0Last Post: 02-14-2008, 09:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks