Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

can any of you huys help me with this java homework ?:)

Options
  • 09-04-2010 5:25pm
    #1
    Closed Accounts Posts: 73 ✭✭


    (a) Write the following for the Employee class:


    1. A constructor that requires the employee name, the number of hours worked and the hourly wages rate. The number of hours must be between 5 and 40, if they are outside these hours they are set to 0. The hourly wages should be between €9.50 and €19.00, if they are outside these values the hourly wages should be set to 0.
    2. A method getHoursWorked that returns the amount of hours worked
    3. A method getWagesRate that returns the hourly pay rate
    4. A method calculateSalary that calculates, sets and returns the weekly pay. The weekly pay is the rate by the number of hours less 10% for PRSI.
    5. A method getName that returns the name








    public class Employee
    {
    private String name;
    private int employeeNumber;
    private double wagesPerHour;
    private double numHoursPerWeek;
    private double weeklyPay;
    public int getHoursWorked;

    public Employee()
    {
    name = "kevin";
    }

    public void setEmployeeName(String name)
    {
    this.name = name;

    }
    public void setHoursWorked(Double numHoursPerWeek)
    {
    numHoursPerWeek = ((numHoursPerWeek>5&&numHoursPerWeek<40)?numHoursPerWeek:0);

    }


    //====================================================

    public String getEmployeeName(){
    return name;
    }
    public double getHoursWorked(){
    return numHoursPerWeek;
    }


    }


Comments

  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,646 Mod ✭✭✭✭TrueDub


    So what's your question?


  • Closed Accounts Posts: 5,482 ✭✭✭Kidchameleon


    Something like this OP:

    //instance variables

    private String employeeName;
    private int hoursWorked;
    private float wagesRate;

    private float weeklyPay;

    public Employee(String name, int hours, float rate)
    {

    this.employeeName = name;

    if(hours >= 5 && hours <= 40)
    {
    this.hoursWorked = hours;
    }
    else
    {
    this.hoursWorked = 0;
    }

    if(rate >= 9.50f && rate <= 19.00f)
    {
    this.wagesRate = rate;
    }
    else
    {
    this.wagesRate = 0.0f;
    }

    }

    //instance methods

    public int getHoursWorked()
    {
    return this.hoursWorked;
    }

    public float getWagesRate()
    {
    return this.wagesRate;
    }

    public float calculateSalary()
    {

    this.weeklyPay = this.wagesRate * (float)this.hoursWorked;

    return this.weeklyPay - (this.weeklyPay * 0.1f);

    }

    public String getName()
    {
    return this.employeeName;
    }


    Regards,

    Kid.


  • Registered Users Posts: 6,433 ✭✭✭run_Forrest_run


    OP seriously, if you need help doing this then you should scrap development for yourself. We can help you do it but there's no point in doing it all for you.
    Anyway, if you read the basics of constructors and methods this will be enough to do this simple task.


  • Closed Accounts Posts: 324 ✭✭radioactiveman


    Yeah you need to do the calculation in the constructor, or call another method from the constructor that does it..
    remember doing this exact exercise myself and being confused by it :D if you're not familiar with java and constructors it can be a bit confusing at first


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Yeah you need to do the calculation in the constructor, or call another method from the constructor that does it..
    remember doing this exact exercise myself and being confused by it :D if you're not familiar with java and constructors it can be a bit confusing at first

    This is true, but if you don't make some kind of effort to work it out before posting wholesale on a forum somewhere you'll never moved beyond that.


  • Advertisement
Advertisement