Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 393433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:15:25+00:00 2026-05-12T16:15:25+00:00

Heres the code I’ve made up so far. Its fully functional and the only

  • 0

Heres the code I’ve made up so far. Its fully functional and the only gripe I have with it is that my output for Weekly and Annual pay is always weekly…I’m at a loss as to how to get this from within either toString method.

public class PolyEmployees {
    public static void main(String[] args) {

        Employee [] myEmployees = {
            new Hourly("Joan Rivers", "Human Resources", 12.45, 34.3),
            new Hourly("Jason Nezbit", "Accounting", 15.25, 46.0),
            new Hourly("Ingrid Homes", "Secretary", 10.11, 38.7),
            new Salaried("Amy Liberman", "Human Resources Executive", 32.50),
            new Salaried("Xander Xavar", "Resource Processing", 29.20),
            new Salaried("Milly Rockhome", "PR Executive", 65.28)
        };

        // Output all employee types
        for (int i = 0; i < myEmployees.length; i++)    {
            System.out.println("\n" + myEmployees[i].toString());
        }                 
    }

}

/*
 * Employee abstract class
 */

abstract public class Employee {
    private String mName;
    private String mDepartment;
    protected Double mRate;

    // Constructor
    public Employee(String mName, String mDepartment, Double mRate) {
        this.mName = mName;
        this.mDepartment = mDepartment;
        this.mRate = mRate;
    }

    // Annual Pay
    public Double pay() {   // 40 Hours a Week, 52 weeks in a year
        return ((this.mRate * 40) * 52);
    }

    @Override
    public String toString() {
        return "Employee: " + this.mName + "\nDepartment: " + this.mDepartment + "\nAnnual Pay: " + this.pay();
    }
}

/*
 * Hourly employee class
 */

public class Hourly extends Employee {
    private Double mHours;

    public Hourly(String mName, String mDepartment, Double mRate, Double mHours) {
        super(mName, mDepartment, mRate);
        this.mHours = mHours;
    }

    @Override
    public Double pay() {   // Weekly Pay, deals with overtime for hourly employee

        if (this.mHours > 40.0) {
            return ((40 * this.mRate) + ((this.mHours-40) * (this.mRate * 1.5)));
        }
        else    {
            return (this.mHours * this.mRate);
        }       
    }

    public String toString() {
        return super.toString() + "\tWeekly Pay: " + pay();
    }

}

/*
 * Salaried Employee Class
 */

public class Salaried extends Employee{

    public Salaried(String mName, String mDepartment, Double mRate) {
        super(mName, mDepartment, mRate);
    }

    @Override
    public Double pay() {   // Weekly Pay
        return (this.mRate * 40);
    }

    @Override
    public String toString() {
        return super.toString() + "\tWeekly Pay: " + this.pay();
    }
}

I get all the output I want except for annual pay. Stepping through the debugger it returns to the childs pay method even when calling from within the parent. Since it’s overridden I am not really surprised by this, but part of my deliverable is to get weekly from the subclass and annual from the super.

So that begs my question, how can I get Annual pay from the parent? Do I have no choice but to cast it as an employee as part of my system output or is there something I am missing?

And on a side note, I love how fluid this site is. Not many places I’ve been to show your post live as you type it.

NOTE ON COMMENT: According to my deliverables, both the salaried and hourly employees toString must return weekly pay. The employee abstract class itself contains the method to return the annual pay.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:15:25+00:00Added an answer on May 12, 2026 at 4:15 pm

    You have the option of calling the super from the subclass. Your toString in Salaried, for example, could look like this:

    return super.toString() + "\tWeekly Pay: " + this.pay()+ "\tAnnual Pay: " + super.pay());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 197k
  • Answers 197k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Python, simplest: def a(n): if n == 0: return 1… May 12, 2026 at 7:28 pm
  • Editorial Team
    Editorial Team added an answer The problem is cause by some strange vista behaviour around… May 12, 2026 at 7:28 pm
  • Editorial Team
    Editorial Team added an answer It's because the MFC support for language selection has a… May 12, 2026 at 7:28 pm

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Here's the code I use to load a texture. image is a CGImageRef. After
Here's the code I'm trying to make work: <?php class database { var $connection;
Here's the code I'm using $(document).ready(function(){ $('#slickbox').hide(); // toggles the slickbox on clicking the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.