Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default What's required for declaring a date field?

    I need to declare 3 fields: employee name, employee number, and the date they were hired. I came up with this so far:

    Java Code:
    package employment;
    //Do I need an import here in order to declare a Date field in my main method?
    
    /**
     *
     * @author speterson86
     */
    public class Employee {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            String Name;
            int employeeNum;
            //How should I declare a Date field here?        
        }
    }
    But I'm not sure how I should declare a date field. Also, if I do, Do I need some sort of import statement in the .java file that this code is in?

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,413
    Rep Power
    5

    Default Re: What's required for declaring a date field?

    Check the JDK API for the Date class and import that. However, some methods of that class are deprecated so only use the ones that aren't. Also, check out the Calendar class.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default Re: What's required for declaring a date field?

    Quote Originally Posted by jim829 View Post
    Check the JDK API for the Date class and import that.
    Yeah, I was wondering about that sort of thing. Netbeans may be an IDE, but does that mean it also has JDK API stuff built into it?

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,413
    Rep Power
    5

    Default Re: What's required for declaring a date field?

    The JDK API comes with your installation of Java.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default Re: What's required for declaring a date field?

    I'm having lots of problems setting up my constructor. The error for line 36 says, "illegal start of expression"; the error for lines 38 thru 40 say "cannot find symbol" (which I don't understand, because they're being declared in the super class, a super class is the main class, so why is it yelling at me?); and see my comment right after the class's final closing curly brace for the other error. Here's the code:

    Java Code:
    /*
     * The workday is divided into two shifts: Day and Night. The shift field will 
     * be an integer value representing the shift that the employee works (Day is 
     * shift1, and Night is shift2). This java project will be a modification of 
     * Programming Challenge 1 of Chapter 9 (Employee and ProductionWorker Classes).
     */
    package employment;
    //import java.util.Calendar;
    import java.text.DateFormat;
    
    public class Employee {
    
        public static void main(String[] args) {
            String Name;
            String hireDate;
            int employeeNum;
            //declare a variable here with current date and time to calculate how
            //long an employee has been with the company
            
            //Write one or more constructors and the appropriate accessor and 
            //mutator methods for the class. (Note that "accessor methods" are 
            //getters, and "mutator methods" are setters):
    
            
             //The following constructor accepts arguments for the employee's name,
             //hire date, and id number:
                   
            
            public Employee(String aName, String aHireDate, int aEmployeeNum)
            {
                Name = aName;
                hireDate = aHireDate;
                employeeNum = aEmployeeNum;
            }
            
            DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
        }
    }//end of public class Employee; error: "class, interface, or enum expected"
    Last edited by SamJava_the_Hut; 09-18-2013 at 01:40 AM.

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

Similar Threads

  1. Java Date in Text Field
    By Richard5324 in forum New To Java
    Replies: 1
    Last Post: 11-17-2011, 06:57 AM
  2. Replies: 2
    Last Post: 07-28-2010, 04:14 PM
  3. Replies: 12
    Last Post: 04-18-2009, 12:58 AM
  4. Replies: 2
    Last Post: 07-02-2007, 04:25 PM
  5. problem with date field
    By Ed in forum JDBC
    Replies: 2
    Last Post: 06-12-2007, 04:27 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
  •