Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29
  1. #21
    PaulM is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default

    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?

  2. #22
    PaulM is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default

    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());

  3. #23
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Java Code:
    emps.add(new Salaried());

  4. #24
    PaulM is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default

    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)

  5. #25
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Java Code:
    emps.add(new Salaried()) = scan.next();
    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.

  6. #26
    PaulM is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default

    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.

  7. #27
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    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.

  8. #28
    PaulM is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default

    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

  9. #29
    PaulM is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default

    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.?

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Verifying of Month
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 2
    Last Post: 11-02-2010, 05:34 PM
  2. Replies: 0
    Last Post: 05-19-2010, 06:38 PM
  3. Replies: 15
    Last Post: 11-06-2009, 11:31 AM
  4. While loop comparing strings from user
    By N3VRMND in forum New To Java
    Replies: 5
    Last Post: 10-30-2009, 09:18 AM
  5. Verifying existence of a table in a db
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 10:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •