Results 1 to 4 of 4

Thread: set system time

  1. #1
    @eddie.com is offline Member
    Join Date
    Aug 2008
    Posts
    4
    Rep Power
    0

    Question set system time

    I am learning inheritance of classes. I have a ProductionEmployee that extends
    Employee The trouble that I am having is one of the getMethods (getcalcPayRate) will not compile I have to subtract yearOfHire which is in the super class Employee from the current system time at first I got a Deprecated error when trying to do date.getYear. I then done a web search and looked in the Java class library i tried date.get(Calander.YEAR) with variations
    Although this still did not work Some times the explination in the Java library itself is not clear (to me anyway)

    Here is my code >>>>

    import java.util.Date;
    public class ProductionEmployee extends Employee
    {
    private double baseHourlyRate;
    private Date date;

    public ProductionEmployee()
    {

    super();
    Date date = new Date();
    baseHourlyRate = 0;
    }

    public void setbaseHourlyRate(double rate)
    {
    baseHourlyRate = rate;
    }

    public double getbaseHourlyRate()
    {
    return baseHourlyRate;
    }

    public double getcalcPayRate()
    {

    double rate = yearOfHire - date.get(Calander.YEAR);
    for(int i=0; i<rate;i++)
    {
    double rise = baseHourlyRate + 1;

    }

    return calcPayRate;


    }


    }

    I also have trouble tring to return the calcPayRate so in my Driver program it will not return the amount.

    Thank you in advance
    Last edited by @eddie.com; 09-02-2008 at 12:25 PM. Reason: bad English

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default

    My doc for Date says:
    int getYear()
    Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.YEAR) - 1900.
    Have you looked at using the Calendar class?
    have trouble tring to return the calcPayRate
    Can you describe the problem?
    If you get errors, copy and paste them here.

  3. #3
    @eddie.com is offline Member
    Join Date
    Aug 2008
    Posts
    4
    Rep Power
    0

    Default

    Hi Again and thank you for the Calendar advice I think that has worked!!!

    I have now changed it to
    import java.util.Calendar;
    public class ProductionEmployee extends Employee
    {
    private double baseHourlyRate;
    private Calendar date;

    public ProductionEmployee()
    {

    super();
    Calendar date = Calendar.getInstance();
    baseHourlyRate = 0;
    }

    public void setbaseHourlyRate(double rate)
    {
    baseHourlyRate = rate;
    }

    public double getbaseHourlyRate()
    {
    return baseHourlyRate;
    }

    public double getcalcPayRate()
    {

    double rate = yearOfHire - date.get(Calendar.YEAR);
    for(int i=0; i<rate;i++)
    {
    double rise = baseHourlyRate + 1;

    }

    return rise;


    }




    }

    And the error message that I get is that return rise can not be found if I place calcPayRate there instead it says calcPayRate can not be found Does this have to do with where I have the curly braces positioned??

    Thanks for having a look.

    Just incase although I dont think that it matters but I am using blueJ

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default

    If you get errors, copy and paste them here.
    where I have the curly braces positioned??
    Which curly braces? If you ask questions about lines of code,
    you should add comments in the code to show where.

Similar Threads

  1. setting system clocks time
    By pks in forum New To Java
    Replies: 4
    Last Post: 05-14-2009, 03:36 AM
  2. Replies: 21
    Last Post: 08-01-2008, 11:13 AM
  3. Run Time Stats
    By JamesF in forum Advanced Java
    Replies: 1
    Last Post: 07-16-2008, 12:33 AM
  4. Hello, first time here.
    By ludragon in forum Introductions
    Replies: 2
    Last Post: 01-03-2008, 05:03 AM
  5. Urgent-Imp-Displaying message with respect to system time
    By garinapavan in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 02:17 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
  •