Page 3 of 3 FirstFirst 123
Results 41 to 49 of 49
  1. #41
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    YES! THIS is what i am picturing!

    the pseudo code is what i was thinking, but your more practical string birthday text as ""; is what i wasnt thinking about.

    so my only other question is getMonth().....is that actually a method i can call? i am not sure...

  2. #42
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default

    Ah, I got that a bit wrong.
    Employee has a getBirthDate() method, which returns a Date object (the birthDate).
    Date has a getMonth() method, so you can "chain" these together:
    Java Code:
    employee.getBirthDate().getMonth();
            ^ calling the getBirthDate() on my employee object
                           ^ which returns a Date on which we call the getMonth() method
    Hopefully that's all laid out properly.
    This is the equivalent of:
    Java Code:
    Date birthDate = employee.getBirthDate();
    birthDate.getMonth();

  3. #43
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    do i want :

    if ( currentMonth == employee.getBirthDate().getMonth() )

    or

    if ( currentMonth == employees.getBirthDate().getMonth() )

    i have tried both and get cannot find symbol errors. also tried

    if ( currentMonth == employee.getBirthDate().month )

    and various other combinations, and always get a cannot find symbol error.

  4. #44
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default

    Sorry, you called it currentEmployee, not employee.
    So currentEmployee.getBirthDate().getMonth().

  5. #45
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    im still getting cannot find symbol errors on the getMonth(). im reading through the employee.java file, and have tried 6-8 other trial and error based combinations to no avail.

    maybe i need to add a set/getMonth method within the getBirthDate if there isnt one? the public class Date is in there as well, confusing the issue to me.

    want me to post the Employee.java code?

  6. #46
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    the Employee.java code is the following:

    there is no "getMonth()" method within the getBirthDate() method, but i can't see how i would implement one, or if i actually even need one.....its obviously retrieving the the birth dates properly from payrollsysystemtest.java as is, so there must be a way i retrieve that same information in this if statement.

    Java Code:
    // Fig. 10.4: Employee.java
    // Employee abstract superclass.
    
    public abstract class Employee 
    {
       private String firstName;
       private String lastName;
       private String socialSecurityNumber;
       private Date birthDate;
    
       // six-argument constructor
       public Employee( String first, String last, String ssn,
       		int month, int day, int year )
       {
          firstName = first;
          lastName = last;
          socialSecurityNumber = ssn;
          birthDate = new Date ( month, day, year);
       } // end six-argument Employee constructor
    
       // set first name
       public void setFirstName( String first )
       {
          firstName = first; // should validate
       } // end method setFirstName
    
       // return first name
       public String getFirstName()
       {
          return firstName;
       } // end method getFirstName
    
       // set last name
       public void setLastName( String last )
       {
          lastName = last; // should validate
       } // end method setLastName
    
       // return last name
       public String getLastName()
       {
          return lastName;
       } // end method getLastName
    
       // set social security number
       public void setSocialSecurityNumber( String ssn )
       {
          socialSecurityNumber = ssn; // should validate
       } // end method setSocialSecurityNumber
    
       // return social security number
       public String getSocialSecurityNumber()
       {
          return socialSecurityNumber;
       } // end method getSocialSecurityNumber
       
       // set birth date
       public void setBirthDate( int month, int day, int year )
       {
          birthDate = new Date( month, day, year );
       } // end method setBirthDate
    
       // return birth date
       public Date getBirthDate()
       {
          return birthDate;
       } // end method getBirthDate
       
       public class Date 
    {
       private int month; // 1-12
       private int day; // 1-31 based on month
       private int year; // any year
    
       // constructor: call checkMonth to confirm proper value for month; 
       // call checkDay to confirm proper value for day
       public Date( int theMonth, int theDay, int theYear )
       {
          month = checkMonth( theMonth ); // validate month
          year = theYear; // could validate year
          day = checkDay( theDay ); // validate day
          
          System.out.printf( 
             "Date object constructor for date %s\n", this );
    
       } // end Date constructor
    
       // utility method to confirm proper month value
       private int checkMonth( int testMonth )
       {
          if ( testMonth > 0 && testMonth <= 12 ) // validate month
             return testMonth;
          else // month is invalid 
          { 
             System.out.printf( 
                "Invalid month (%d) set to 1.", testMonth );
             return 1; // maintain object in consistent state
          } // end else
       } // end method checkMonth
    
       // utility method to confirm proper day value based on month and year
       private int checkDay( int testDay )
       {
          int[] daysPerMonth = 
             { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
       
          // check if day in range for month
          if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
             return testDay;
       
          // check for leap year
          if ( month == 2 && testDay == 29 && ( year % 400 == 0 || 
               ( year % 4 == 0 && year % 100 != 0 ) ) )
             return testDay;
       
          System.out.printf( "Invalid day (%d) set to 1.", testDay );
          return 1;  // maintain object in consistent state
       } // end method checkDay
       
       // return a String of the form month/day/year
       public String toString()
       { 
          return String.format( "%d/%d/%d", month, day, year ); 
       } // end method toString
    } // end class Date
    
    
    
       // return String representation of Employee object
       @Override
          public String toString()
       {
          return String.format( "%s %s\n%s: %s\n%s: %s", 
             getFirstName(), getLastName(), 
             "social security number", getSocialSecurityNumber(), 
             "birth date", getBirthDate() );
       } // end method toString
    
    
       // abstract method overridden by concrete subclasses
       public abstract double earnings(); // no implementation here
    } // end abstract class Employee
    obviously the date class is coded in there as well instead of imported ( as my instructions requested) but that shouldnt complicate this issue any i dont believe.

  7. #47
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default

    Oh.
    For some reason I thought your Date class had a getMonth() method.

    I'd add one to it (if that's not against the rules).
    Java Code:
    public int getMonth() {
        return month;
    }

  8. #48
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    after trying and moving a couple more things....


    IT WORKS!


    Thank you so much for you help, both on this and in the past, i really appreciate it.

    Hayden

  9. #49
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

Page 3 of 3 FirstFirst 123

Similar Threads

  1. subclass calling superclass method
    By stackptr89 in forum New To Java
    Replies: 10
    Last Post: 11-22-2010, 07:40 PM
  2. Calling subclassed methods from constructors
    By arefeh in forum New To Java
    Replies: 7
    Last Post: 01-22-2010, 12:22 AM
  3. superclass and subclass
    By mr idiot in forum New To Java
    Replies: 19
    Last Post: 01-03-2009, 07:29 AM
  4. Calling methods from superclass
    By moaxjlou in forum New To Java
    Replies: 7
    Last Post: 12-11-2008, 12:07 AM
  5. SuperClass of an Object
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-06-2007, 02: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
  •