Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New to Java. need help with hw...pls

    Below instruction are part of my HW. and i'm stuck on this. I need to have new class created as mentioned below and out printed on console.
    Output needs to look like in attached file. Attachment 10100

    Create a Test class (in different file)to test the following functionality in its main method.
    a. Declare a variable named currentEmployee of type Employee.
    b. Create an Employee object with name Alice and the weekly wage rate 1000 and assign it to the above variable.
    c. Print to the console the string representation of this object.
    d. Using any of the loop constructs, iterate over the computePayStub of this object with the hours 10, 20, 30, 40, 50, and 60. Display the wages as shown in the sample below.
    e. Create a Consultant object with name Bob and the hourly wage rate 100. Reassign the currentEmployee to this object.
    f. Repeat the steps shown in c) and d) for this object.






    In below file where i have created classes and implement the specified functionality.


    package hw3.part2;
    import javax.swing.JOptionPane;
    import java.text.NumberFormat;


    public class Employee {

    //instance variables
    private String name;
    private int wageRate;
    NumberFormat moneyFormatter=NumberFormat.getCurrencyInstance();

    public Employee(){}

    //single constructor
    public Employee(String theName, int theWageRate){


    name=theName;
    wageRate=theWageRate;
    }

    public String getName() {
    return name;
    }

    public void setName(String newName) {
    this.name = newName;
    }


    public int getWageRate() {
    return wageRate;
    }

    public void setWageRate(int newWageRate) {
    this.wageRate = newWageRate;
    }

    //compute computePayStub
    public double computePayStub(double hours)
    {

    double perHourRate=wageRate/40;
    double weekleyWadge=0.0;


    if (hours>=40){
    weekleyWadge=(perHourRate*40);

    }
    else if (hours<40){
    weekleyWadge=(perHourRate*hours);
    }

    return weekleyWadge;

    }
    public String toString (){
    return "Employee: Alice";
    }
    }

    //Create a derived class from the Employee class named Consultant

    class consultant extends Employee{
    public consultant()
    {
    }
    public consultant(String theName,int theWageRate){
    super (theName, theWageRate);

    }

    //Override computePayStub method
    public double computePayStub(double hours){
    double hourlyRate=getWageRate()/40;
    double weekleyWadge=0.0;


    if (hours>=40){
    if (hours <=50){
    weekleyWadge=((hourlyRate*hours)*1.5);
    } else {
    weekleyWadge=((hourlyRate*50)*1.5); }
    }

    else {
    weekleyWadge=(hourlyRate*hours);}

    return weekleyWadge; }

    public String toString (){
    return "Consultant: Bob";
    }
    }
    Last edited by navya4u2004; 08-10-2011 at 04:47 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Okay, and where's the code that you have written to show what you have currently tried?


  •  

    Posting Permissions

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