Results 1 to 4 of 4
  1. #1
    fezman1337 is offline Member
    Join Date
    Oct 2010
    Posts
    7
    Rep Power
    0

    Default 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.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    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.

  3. #3
    fezman1337 is offline Member
    Join Date
    Oct 2010
    Posts
    7
    Rep Power
    0

    Default

    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.

  4. #4
    fezman1337 is offline Member
    Join Date
    Oct 2010
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Gregorian calendar multiple dates
    By tirwit in forum New To Java
    Replies: 4
    Last Post: 09-17-2010, 04:10 PM
  2. Gregorian Calendar
    By bindhuuk4 in forum New To Java
    Replies: 1
    Last Post: 08-07-2009, 01:00 PM
  3. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 09:32 PM
  4. Help with gregorian calendar
    By osval in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 12:21 AM
  5. Gregorian calendar issue
    By orchid in forum New To Java
    Replies: 1
    Last Post: 05-16-2007, 07:51 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
  •