Results 1 to 4 of 4
Thread: help with Gregorian Calendar
- 10-25-2010, 07:46 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 7
- Rep Power
- 0
help with Gregorian Calendar
This is what i have so far:
import java.util.*;
public class Employee extends Person {
private double annualSalary;
private GregorianCalendar yearHired;
private String socialSecurityNumber;
public int year;
public Employee () {
super();
annualSalary = 0.0;
yearHired = new GregorianCalendar(1900,0,1);
socialSecurityNumber = "999999999";
}
public Employee(String name, double salary, GregorianCalendar year, String ssn) {
super(name);
annualSalary = salary;
yearHired = new GregorianCalendar (year.get(year.YEAR));
socialSecurityNumber = ssn;
}
public Employee(Employee emp) {
setAnnualSalary(emp.getAnnualSalary());
yearHired = emp.getYearHired();
socialSecurityNumber = emp.getSocialSecurityNumber();
}
public double getAnnualSalary() {
return annualSalary;
}
public GregorianCalendar getYearHired() {
return( new GregorianCalendar (yearHired.get(yearHired.YEAR)));
}
public String getSocialSecurityNumber() {
return socialSecurityNumber;
}
public void setAnnualSalary(double salary) {
annualSalary = salary;
}
public void setYearHired(GregorianCalendar date) {
yearHired = date;
}
public void setSocialSecurityNumber(String ssn) {
socialSecurityNumber = ssn;
}
public String toString() {
GregorianCalendar temp = getYearHired();
return(super.toString() + "\nName: \nYear Hired: " + getYearHired() + "\nAnnual Salary: " + getAnnualSalary()
+ "\nSocial Security Number: " + getSocialSecurityNumber());
}
public boolean equals(Object obj) {
return (getAnnualSalary() == (obj.getAnnualSalary())
&& getYearHired() == obj.getYearHired()
&& getSocialSecurityNumber().equals(obj.getSocialSecu rityNumber()));
}
}
That is the program i have to write and complete and the next 2 codes are given.
/**
* Class that represents a person
* @author
* @version 1.0
*/
public class Person {
//instance field for the name of the Person
private String name;
/**
* Default constructor
*/
public Person() {
name= "no name";
}
/**
* Constructor that set the name to what is passed in
* @param n The name of the Person you are creating
*/
public Person(String n) {
name = n;
}
/**
* Returns the name of the person
* @return The name of the person
*/
public String getName() {
return name;
}
/**
* Set the Person's name to name that is passed in
* @param n Name that you want to set the Person's name to.
*/
public void setName(String n){
name = n;
}
/**
* Overriden method, that returns the Person in string form
* @return The Person as a string
*/
public String toString() {
return("Person's name is " + getName());
}
}
AND..
import java.util.GregorianCalendar;
/**
* Program to Test the Employee subclass
*
*
* @
* @version 1.00 2009/10/1
*/
public class TestEmployee {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Employee e1 = new Employee();
Employee e2 = new Employee("Bob Smith", 45000.50, new GregorianCalendar(2009, 00, 01), "123456789");
Employee e3 = new Employee(e2);
System.out.println(e1.toString());
System.out.println(e2.toString());
System.out.println(e3.toString());
if (e2.equals(e3)){
System.out.println(e2.getName() + " is the same as " + e3.getName());
}else{
System.out.println(e2.getName() + " is NOT the same as " + e3.getName());
}
System.out.println();
e3.setName("Test Person");
e3.setSocialSecurityNumber("134256987");
e3.setAnnualSalary(65000.63);
e3.setYearHired(new GregorianCalendar(2009,9,15));
System.out.println(e1.toString());
System.out.println(e2.toString());
System.out.println(e3.toString());
if (e2.equals(e3)){
System.out.println(e2.getName() + " is the same as " + e3.getName());
}else{
System.out.println(e2.getName() + " is NOT the same as " + e3.getName());
}
}
}
The errors i get are "Cannot find symbol constructor GregorianCalendar(int)" and the equals class is not working. any help will be appreciated thanx.
- 10-25-2010, 08:10 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
And what is your question ?
see: GregorianCalendar (Java Platform SE 6) --> Constructor Summary
In the equals methods, the passed objects typ is Object. If you want to invoke methods from your Employee class, you have to cast to it.
- 10-26-2010, 03:13 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 7
- Rep Power
- 0
ok i got the Employee to compile but when i run the TestEmployee i get a really long answer for the year hired. the error i get is this
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,le nient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,trans itions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,start Year=0,startMode=3,startMonth=2,startDay=8,startDa yOfWeek=1,startTime=7200000,startTimeMode=0,endMod e=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=72 00000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,Y EAR=2009,MONTH=9,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DA Y_OF_MONTH=15,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_W EEK_IN_MONTH=?,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE =0,SECOND=0,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET =?]
I think the error is from the toString class i have which looks like this
public String toString() {
GregorianCalendar temp = getYearHired();
return ("\nName: " + super.toString() + "\nYear Hired: " + getYearHired() + "\nAnnual Salary: " + getAnnualSalary()
+ "\nSocial Security Number: " + getSocialSecurityNumber());
BTW thank you for ur help eRaaaa.
- 10-26-2010, 04:01 AM #4
Member
- Join Date
- Oct 2010
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Gregorian calendar multiple dates
By tirwit in forum New To JavaReplies: 4Last Post: 09-17-2010, 03:10 PM -
Gregorian Calendar
By bindhuuk4 in forum New To JavaReplies: 1Last Post: 08-07-2009, 12:00 PM -
Creating a Gregorian Calendar using a Date object gives date - 1
By prachi_goliwadekar in forum New To JavaReplies: 1Last Post: 05-08-2008, 08:32 PM -
Help with gregorian calendar
By osval in forum New To JavaReplies: 2Last Post: 08-06-2007, 11:21 PM -
Gregorian calendar issue
By orchid in forum New To JavaReplies: 1Last Post: 05-16-2007, 06:51 PM


LinkBack URL
About LinkBacks

Bookmarks