Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Assingment help

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Assingment help

    Hi All

    I am currently working om an assignment that I could use some help on. The purpose of the assignment is to write a program that takes two types of employees one salaried on commissioned. the base employee must be abstract and contain an abstract method for earnings. The problem that I am have is that I can get one employee name to show up and the yearly and base salary for that employee to show up but I am having a problem getting a second employee name to show up and on how to get the abstract earnings method for the commission employee to return the correct information

    if this post is in the wrong spot I am sorry was not sure where it should go

    thx
    bjcdude

    here is my code
    abstract class Employee
    {
     
    	private String EmpFirstName;
    	private String EmpLastName;
     
     
    	public Employee(String EmpFirstName, String EmpLastName)
    	{
    		this.EmpFirstName = EmpFirstName;
    		this.EmpLastName = EmpLastName;
    	}
     
    	abstract public int Earnings();
     
    	public String getEmpFirstName()
    	{
    		return EmpFirstName;
    	}
     
    	public void setEmpFirstName(String FName)
    	{
    		EmpFirstName = FName;
    	}
     
    	public String getEmpLastName()
    	{
    		return EmpLastName;
    	}
     
    	public void setEmpLastName(String LName)
    	{
    		EmpLastName = LName;
    	}
     
    	public String toString()
    	{
    		return ("Employee:" + EmpFirstName + " " + EmpLastName);
    	}
    }

    class SalaryEmployee extends Employee
    {
    	private int EmpSalary;
     
    	public SalaryEmployee()
    	{
    		EmpSalary = 2000000;
    	}
     
    	public int Earnings()
    	{
    		return EmpSalary;
    	}
     
    	public void setSalary(int Salary)
    	{
    		this.EmpSalary  = EmpSalary;
    	}
     
    	public int getSalary()
    	{
    		return EmpSalary;
    	}
     
    	public String toString()
    	{
    		return super.toString() + " " +"Salaried:" + Earnings();
     
    	}
     
    }


    class CommissionEmployee extends Employee
    {
    	private int BaseSalary;
    	private int NumProductsSold;
    	private int CommissionPercent;
     
    	public CommissionEmployee()
    	{
    		BaseSalary = 80000;
    		NumProductsSold = 20;
    		CommissionPercent = 10;
    	}
     
    	public int Earnings()
    	{
    		return BaseSalary;
    	}
     
    	public void setBaseSalary(int BSalary)
    	{
    		this.BaseSalary = BaseSalary;
    	}
     
    	public double setBaseSalary()
    	{
    		return BaseSalary;
    	}
     
    	public void setNumProductsSold(int NumProducts)
    	{
    		this.NumProductsSold = NumProductsSold;
    	}
     
    	public double getNumProductsSold()
    	{
    		return NumProductsSold;
    	}
     
    	public void setCommissionPercent(int ComPercent)
    	{
    		this.CommissionPercent = CommissionPercent;
    	}
     
    	public double getCommissionPercent()
    	{
    		return CommissionPercent;
    	}
     
    	public String toString()
    	{
    		return super.toString() + " " + "Commissioned:" + BaseSalary;
    	}
     
    }


    public class MainEmployee
    {
    	public static void main(String[] args)
    	{
    		SalaryEmployee Emp = new SalaryEmployee();
    		CommissionEmployee ComEmployee = new CommissionEmployee();
     
    		System.out.println(Emp.toString());
    		System.out.println(ComEmployee.toString());
     
    	}
    }

    if any other information or clarity is needed let me know.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Assingment help

    What specifically are you having problems with? Are you getting an error message? If so, please post the message.

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Assingment help

    I think it's

    public abstract int...

    not

    abstract public int...

    could be wrong.

    The way I learned it was public abstract int...

    Also, your main method never sets BaseSalary...so it's going to print null.

    Also, for your two sub classes, you're going to at least need to have the same two parameters in your Employee class in each of your two subclasses.

    You just call them..first statement inside constructor...super(params);
    Last edited by javapenguin; February 8th, 2011 at 04:42 PM.

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Assingment help

    I think this should work. (Haven't had a chance to test it...my compiler is broken...remember...

    public abstract class Employee
    {
     
    	private String EmpFirstName;
    	private String EmpLastName;
     
     
    	public Employee(String EmpFirstName, String EmpLastName)
    	{
    		setEmpFirstName(EmpFirstName);
    		setEmpLastName(EmpLastName);
    	}
     
    	public abstract  int Earnings();
     
    	public String getEmpFirstName()
    	{
    		return EmpFirstName;
    	}
     
    	public void setEmpFirstName(String FName)
    	{
    		EmpFirstName = FName;
    	}
     
    	public String getEmpLastName()
    	{
    		return EmpLastName;
    	}
     
    	public void setEmpLastName(String LName)
    	{
    		EmpLastName = LName;
    	}
     
    	public String toString()
    	{
    		return ("Employee:" +getEmpFirstName() + " " + getEmpLastName());
    	}
    }

    class SalaryEmployee extends Employee
    {
    	private int EmpSalary;
     
    	public SalaryEmployee(String EmpFirstName, String EmpLastName, int EmpSalary)
    	{
                     super(EmpFirstName, EmpLastName);
     
    // what is line below for?
    		// EmpSalary = 2000000;
    setSalary(EmpSalary);
    	}
     
    	public int Earnings()
    	{
    		return EmpSalary;
    	}
     
    	public void setSalary(int Salary)
    	{
    		this.EmpSalary  = EmpSalary;
    	}
     
    	public int getSalary()
    	{
    		return EmpSalary;
    	}
     
    	public String toString()
    	{
    		return (super.toString() + " " +"Salaried:" + this.Earnings());
     
    	}
     
    }


    class CommissionEmployee extends Employee
    {
    	private int BaseSalary;
    	private int NumProductsSold;
    	private int CommissionPercent;
     
    	public CommissionEmployee(String EmpFirstName, String EmpLastName, int BaseSalary, int NumProductsSold, int CommissionPercent )
    	{
                   super(EmpFirstName, EmpLastName);
    	//	BaseSalary = 80000;
      setBaseSalary(BaseSalary);
      setNumProductsSold(NumProductsSold);
    setCommissionPercent(CommissionPercent);
    		// NumProductsSold = 20;
    	// 	CommissionPercent = 10;
    	}
     
    	public int Earnings()
    	{
    		return BaseSalary;
    	}
     
    	public void setBaseSalary(int BSalary)
    	{
    		this.BaseSalary = BaseSalary;
    	}
     
    	public double setBaseSalary()
    	{
    		return BaseSalary;
    	}
     
    	public void setNumProductsSold(int NumProducts)
    	{
    		this.NumProductsSold = NumProductsSold;
    	}
     
    	public int getNumProductsSold()
    	{
    		return NumProductsSold;
    	}
     
    	public void setCommissionPercent(int ComPercent)
    	{
    		this.CommissionPercent = CommissionPercent;
    	}
     
    	public int getCommissionPercent()
    	{
    		return CommissionPercent;
    	}
     
    	public String toString()
    	{
    		return (super.toString() + " " + "Commissioned:" + BaseSalary);
    	}
     
    }


    public class MainEmployee
    {
    	public static void main(String[] args)
    	{
                     Scanner console = new Scanner(System.in);
                   System.out.println("Enter first name of Salary Employee");
                String firstName = console.nextLine();
                System.out.println("Enter last name");
                String lastName = console.nextLine();
    System.out.println("Enter salary");
    int salary = console.nextInt();
     
    		SalaryEmployee Emp = new SalaryEmployee(firstName, lastName, salary);
     
        System.out.println("Enter first name of Commission  Employee");
                String firstName2 = console.nextLine();
                System.out.println("Enter last name");
                String lastName2 = console.nextLine();
    System.out.println("Enter base salary");
    int baseSalary = console.nextInt();
    System.out.println("Enter number of products sold");
    int prodSold = console.nextInt();
    System.out.println("Enter commission %");
    int comPer = console.nextInt();
     
     
     
    		CommissionEmployee ComEmployee = new CommissionEmployee(firstName2, lastName2, baseSalary, prodSold, comPer);
     
    		System.out.println(Emp.toString());
    		System.out.println(ComEmployee.toString());
     
    	}
    }
    Last edited by javapenguin; February 8th, 2011 at 05:17 PM. Reason: Might need that there

  5. The Following User Says Thank You to javapenguin For This Useful Post:

    bjcdude (February 10th, 2011)