Results 1 to 9 of 9
- 12-05-2011, 04:59 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 4
- Rep Power
- 0
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....
the code below is where i need the calculations for the current salary...the "Hours" double is merely a placeholder...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 an example of one of the employee subclasses...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(); } }
Any help is very appreciated. If I have more questions to ask I'll ask them as I get responses. Thanks in advance.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(); } }Last edited by pxsalmers; 12-05-2011 at 05:01 AM.
- 12-05-2011, 05:37 AM #2
Re: need help with final project for Obj-Oriented Java Class
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.2) How do I get getCurrentSalary() to calculate the current salary for each circumstance?
- 12-05-2011, 08:36 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 4
- Rep Power
- 0
Re: need help with final project for Obj-Oriented Java Class
I typed this code for the equals() method part...
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.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; }
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?
- 12-05-2011, 03:04 PM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
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
- 12-05-2011, 05:07 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: need help with final project for Obj-Oriented Java Class
Why does PersonalData override finalize()?
- 12-05-2011, 06:45 PM #6
Member
- Join Date
- Dec 2011
- Posts
- 4
- Rep Power
- 0
Re: need help with final project for Obj-Oriented Java Class
-.-
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..gif)
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.
- 12-05-2011, 10:54 PM #7
Re: need help with final project for Obj-Oriented Java Class
So John Smith living in London is the same as John Smith living in New York?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; } }
- 12-06-2011, 12:38 AM #8
Re: need help with final project for Obj-Oriented Java Class
Get in the habit of using standard Java naming conventions!
- 12-06-2011, 01:14 AM #9
Member
- Join Date
- Dec 2011
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Help me? Class final project.
By Blue Energy in forum Advanced JavaReplies: 2Last Post: 05-14-2011, 06:39 AM -
Java's Class Final Project - Tower Defense
By lastpirate89 in forum New To JavaReplies: 6Last Post: 05-11-2011, 03:04 PM -
Java Networking - Need help in doing final year project
By sujatha_nw in forum NetworkingReplies: 0Last Post: 07-09-2009, 12:23 AM -
GUI Final Project help
By Unknown in forum New To JavaReplies: 21Last Post: 12-30-2008, 07:58 PM -
[SOLVED] is final class members are also final ?
By haoberoi in forum New To JavaReplies: 4Last Post: 11-10-2008, 03:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks