Results 1 to 9 of 9
  1. #1
    pxsalmers is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default need help with final project for Obj-Oriented Java Class

    Hey everyone, new to the forums here. Also somewhat new to Java. My final project that I was assigned seems somewhat overwhelming to me.

    Essentially I need to make a program with a GUI that allows input for data entry for Employees.

    Different kinds of Employees:
    Full Time, Unionized (5% higher raises than Full Time employees )
    Full Time, Regular (3% annual raises)
    Part Time, Regular (2% annual raises)
    Part Time, Seasonal ($1 annual raises)

    Hierarchy would be as follows:

    Worker interface -> Full Time and Part Time
    Part Time -> RegularPartTime and Seasonal Part Time

    I also need to calculate FT employee salary based on their hire date and union membership (implementing Calendar and setting union status to a boolean)

    Now I have a few questions:

    1) How would I implement an equals() method to allow for string comparison to prevent duplicate data entries?
    2) I have several methods within my Employee classes which are subclasses of the Worker class, which when brought to the Worker method getCurrentSalary() should calculate the current salary of any employee based on union status, starting salary, and the hire date. So something like:
    Current FT Regular Salary = starting salary * 1.03% (for each year employed)
    or
    Current FT Unionized Salary = [starting salary * 1.03% (for each year employed)] * 1.05% (unionized)
    or
    Current PT Regular Salary = starting salary * 1.02% (for each year employed)
    or
    Current PT Seasonal Salary = starting salary + $1 (for each year employed)
    How do I get getCurrentSalary() to calculate the current salary for each circumstance?

    Here is some of my code that I have so far....

    Java Code:
    class PersonalData
    
    {
    private String Name;
    private String Residence;
    
    public PersonalData() throws EmployeeException
    {
    	Name = "name";
    	Residence = "residence";
    }
    
    public void setName(String N) throws EmployeeException
    {
    	if(N != null && N.length() == 0)
    		throw new EmployeeException();
    	else
    		Name = N;
    }
    
    public String getName()
    {
    	return Name;
    }
    
    public void setResidence(String R) throws EmployeeException
    {
    	if(R != null && R.length() == 0)
    		throw new EmployeeException();
    	else
    		Residence = R;
    }
    
    public String getResidence()
    {
    	return Residence;
    }
    
    public void finalize()
    {
    String data = "The employee "+ Name +" lives at "+ Residence + ".";
    
    System.out.println(data);
    }
    
    }
    the code below is where i need the calculations for the current salary...the "Hours" double is merely a placeholder...

    Java Code:
    public class Worker
    {
    
    	private double Salary;
    	private double Hours;
    	private double HourlySalary;
    
    	public Worker()
    	{
    		Salary = 0.00;
    		Hours = 0.00;
    	}
    
    
    	public double getSalary()
    	{
    		return Salary;
    	}
    	public double getHourlySalary()
    	{
    		return HourlySalary;
    	}
    
    	public void getCurrentAnnualSalary() throws EmployeeException
    	{
    		if(Hours>=32.00)
    		System.out.println("The employee's current annual salary is: $" + getSalary());
    
    		else if(Hours>=0.00 && Hours<32.00)
    		System.out.println("The employee's current hourly salary is: $" + getHourlySalary() + " per hour.");
    
    		else
    		throw new EmployeeException();
    	}
    
    
    
    }
    the code below is an example of one of the employee subclasses...

    Java Code:
    public class FullTime extends Worker implements Cloneable{
    
    private PersonalData FullTimeData;
    private HireDate HD;
    private boolean Unionized;
    private double StartingSalary;
    
    public FullTime() throws Exception
    {
    	setFullTimeData("Name", "Residence");
    	HD.c.set(2002, 9, 9);
    	Unionized = true;
    	StartingSalary = 25000.00;
    }
    public void setFullTimeData(String N, String R) throws EmployeeException
    {
    	if(N != null && N.length() == 0)
    		throw new EmployeeException();
    	else if(R != null && R.length() == 0)
    		throw new EmployeeException();
    	else
    	FullTimeData.setName(N);
    	FullTimeData.setResidence(R);
    
    }
    public PersonalData getFullTimeData()
    {
    	return FullTimeData;
    }
    public void setHireDate(int Y, int M, int D) throws EmployeeException
    {
    	if (Y<=2002 && M<=9 && D<9)
    		throw new EmployeeException();
    	else
    	HD.c.set(Y, M, D);
    
    }
    public HireDate getHireDate()
    {
    	return HD;
    }
    
    public void setUnionized(boolean U)
    {
    	if (U = true)
    		Unionized = true;
    	else
    		Unionized = false;
    }
    
    public boolean getUnionized()
    {
    	return Unionized;
    }
    
    public void setStartingSalary(double S) throws EmployeeException
    {
    	if (S<0)
    		throw new EmployeeException();
    	else
    		StartingSalary = S;
    		
    	if (Unionized = true)
    	
    }
    public double getStartingSalary()
    {
    	return StartingSalary;
    }
    
    
    public Object clone() throws CloneNotSupportedException
    {
    	return super.clone();
    }
    
    
    
    }
    Any help is very appreciated. If I have more questions to ask I'll ask them as I get responses. Thanks in advance.
    Last edited by pxsalmers; 12-05-2011 at 05:01 AM.

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

    Default Re: need help with final project for Obj-Oriented Java Class

    Quote Originally Posted by pxsalmers View Post
    1) How would I implement an equals() method to allow for string comparison to prevent duplicate data entries?
    How do you determine if 2 employees are the same? By the colour of the car they drive, their name or maybe an ID number.
    2) How do I get getCurrentSalary() to calculate the current salary for each circumstance?
    Each subclass should override the getCurrentSalary method of the parent class.

  3. #3
    pxsalmers is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: need help with final project for Obj-Oriented Java Class

    Quote Originally Posted by Junky View Post
    How do you determine if 2 employees are the same? By the colour of the car they drive, their name or maybe an ID number.

    Each subclass should override the getCurrentSalary method of the parent class.
    I typed this code for the equals() method part...

    Java Code:
    public boolean equals(PersonalData o) throws EmployeeException
    {
    	if (this.Name.equals(o.Name))
    		{
    			return true;
    		}
    	else if (this.Residence.equals(o.Residence))
    		{
    			return true;
    		}
    	else
    			return false;
    }
    I don't have a client code to test that on yet, so I am not sure if that is the correct code for my intended purpose. I also don't know if the boolean returns will throw the exception, adding a "throw new EmployeeException" line gives an "unreachable statement" error.

    and as for your reply to my other question, I do realize that is what I'm supposed to do but my question is more....how do I implement the Calendar into it to measure time of employment from a certain date? i know theres a getTimeInMillis() method but my question is how I would convert an input date to that to get it to recognize a certain amount of years, or would I have to calculate specifically years in milliseconds?

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: need help with final project for Obj-Oriented Java Class

    If you are hell bent on throwing the exception then add it to the else statement at the end without the return false. It is unreachable due to all paths currently returning.

    Also please read this : Naming Conventions

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,935
    Rep Power
    19

    Default Re: need help with final project for Obj-Oriented Java Class

    Why does PersonalData override finalize()?

  6. #6
    pxsalmers is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: need help with final project for Obj-Oriented Java Class

    Quote Originally Posted by Tolls View Post
    Why does PersonalData override finalize()?
    -.-

    I'm just typing what my professor is specifying for the project.....I've been confused all semester with this stuff I'm trying to go for networking and I'm learning Java.

    And I have to implement an ArrayList into the GUI too. I have a working example that works in DOS but not with a GUI >< he said that all employee classes should be "cloneable and serializable".
    Last edited by pxsalmers; 12-05-2011 at 06:59 PM.

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

    Default Re: need help with final project for Obj-Oriented Java Class

    Java Code:
    public boolean equals(PersonalData o) throws EmployeeException {
        if (this.Name.equals(o.Name)) {
            return true;
        } else if (this.Residence.equals(o.Residence)) {
            return true;
        } else {
            return false;
        }
    }
    So John Smith living in London is the same as John Smith living in New York?

  8. #8
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: need help with final project for Obj-Oriented Java Class

    Quote Originally Posted by pxsalmers View Post
    I'm just typing what my professor is specifying for the project.....I've been confused all semester with this stuff I'm trying to go for networking and I'm learning Java . . . he said that all employee classes should be "cloneable and serializable".
    Sheesh. What's the title of this course?
    Get in the habit of using standard Java naming conventions!

  9. #9
    pxsalmers is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: need help with final project for Obj-Oriented Java Class

    Quote Originally Posted by Junky View Post
    Java Code:
    public boolean equals(PersonalData o) throws EmployeeException {
        if (this.Name.equals(o.Name)) {
            return true;
        } else if (this.Residence.equals(o.Residence)) {
            return true;
        } else {
            return false;
        }
    }
    So John Smith living in London is the same as John Smith living in New York?
    hmm...didnt think of that....

    guess i should have an && operator to narrow down exact matches.

    Sheesh. What's the title of this course?
    Object Oriented Java.

Similar Threads

  1. Help me? Class final project.
    By Blue Energy in forum Advanced Java
    Replies: 2
    Last Post: 05-14-2011, 06:39 AM
  2. Java's Class Final Project - Tower Defense
    By lastpirate89 in forum New To Java
    Replies: 6
    Last Post: 05-11-2011, 03:04 PM
  3. Replies: 0
    Last Post: 07-09-2009, 12:23 AM
  4. GUI Final Project help
    By Unknown in forum New To Java
    Replies: 21
    Last Post: 12-30-2008, 07:58 PM
  5. [SOLVED] is final class members are also final ?
    By haoberoi in forum New To Java
    Replies: 4
    Last Post: 11-10-2008, 03:01 PM

Posting Permissions

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