Results 1 to 6 of 6
- 09-14-2013, 02:57 AM #1
Senior Member
- Join Date
- Jul 2013
- Location
- Wisconsin, USA
- Posts
- 106
- Rep Power
- 0
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? } }
- 09-14-2013, 03:28 AM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 09-15-2013, 09:37 PM #3
Senior Member
- Join Date
- Jul 2013
- Location
- Wisconsin, USA
- Posts
- 106
- Rep Power
- 0
- 09-15-2013, 11:40 PM #4
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: What's required for declaring a date field?
The JDK API comes with your installation of Java.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 09-17-2013, 09:59 PM #5
Senior Member
- Join Date
- Jul 2013
- Location
- Wisconsin, USA
- Posts
- 106
- Rep Power
- 0
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 02:40 AM.
- 09-18-2013, 04:24 AM #6
Re: What's required for declaring a date field?
Continued here:
http://www.java-forums.org/new-java/...nstructor.html
Similar Threads
-
Java Date in Text Field
By Richard5324 in forum New To JavaReplies: 1Last Post: 11-17-2011, 07:57 AM -
How to insert/update Date field in Oracle with java code
By sasi.tati in forum AWT / SwingReplies: 2Last Post: 07-28-2010, 05:14 PM -
Is there a way to have mySQL auto fill in the current date into my dateCreated field?
By Md Saim in forum JDBCReplies: 12Last Post: 04-18-2009, 01:58 AM -
Doubt with hibernate and date field
By Ed in forum JDBCReplies: 2Last Post: 07-02-2007, 05:25 PM -
problem with date field
By Ed in forum JDBCReplies: 2Last Post: 06-12-2007, 05:27 PM
Bookmarks