Results 1 to 5 of 5
  1. #1
    infernocy is offline Member
    Join Date
    Apr 2012
    Posts
    15
    Rep Power
    0

    Default servicedate field in java

    I am creating a vehicle class and i want to create a field for a servicedate
    by the way i have a separate class called date with this code
    Java Code:
    /**
     * Simple Date Class 
     */
    public class Date {
        /** Fields of a Date - just the day, month and year*/
        private int day;
        private int month;
        private int year;
        /**
         * Constructor for objects of class Date
         * @param d - the day part of the date (1 - 31, depending on the month).
         * @param m - the month part of the date (1 - 12).
         * @param y - the year part of the date.*/
        public Date(int d, int m, int y){
            day = d;
            month = m;
            year = y;
        }
        /**
         * Default Constructor for objects of class Date set the constructed date to 1/01/1970.  This is a default setting
         * and is obviously "in the past"
         */
        public Date(){
            day = 1;
            month = 1;
            year = 1970;
        }
         /**
         * method to set the Date
         * @param d - the day part of the date (1 - 31, depending on the month).
         * @param m - the month part of the date (1 - 12).
         * @param y - the year part of the date.
         * Note: No error checking in this version ! */
        public void setDate(int d, int m, int y){
            day = d;
            month = m;
            year = y;
        }
        
        /**
         * @return the date as a String, format "09/11/2002" */
        public String toString(){
            return as2Digits(day) + "/" + as2Digits(month) + "/" + year;
        }
        
        /** Internal method to add a leading zero if necessary. */
        private String as2Digits (int i){
            if (i <10) {return "0" + i;}
            else {return "" + i;}
        }
        public boolean equals(Object o){
            if (o instanceof Date){
                Date d = (Date)o;
                return d.toString().equals(this.toString());
            }
            return false;
        }
            
    }
    and my vehicle class so far
    Java Code:
    /**
     * Write a description of class Vehicle here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class Vehicle {
        // instance variables - replace the example below with your own
        public String Code;
        public String HomeDepot;
        public String Make;
        public String  ServiceDate;
        /**
         * Constructor for objects of class Vehicle
         */
        public Vehicle(String Vcode , String VHomeDepot, String VMake , String VServiceDate){
           Code = Vcode;
           HomeDepot = VHomeDepot ;
           Make = VMake ;
           ServiceDate =  VServiceDate;
        }
    
        /**
         * An example of a method - replace this comment with your own
         * 
         * @param  y   a sample paraameter for a method
         * @return     the sum of x and y 
         */
        public int sampleMethod(int y){
           return y;
        }
    }
    what is the best way to do it ? should i create an arraylist and get the date from the date class or create a new field for it ?


    thanks for all the help
    Last edited by Fubarable; 04-07-2012 at 07:33 PM. Reason: quote tags changed to code tags

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: servicedate field in java

    what is the best way to do it?
    What would the arraylist be for?
    How would the servicedate be different from any other class members like code or make? Make it a field.

    Coding standards:
    Use lower case first letters for variable names.

    Date is a poor choice for your class. Java SE has two classes named Date. Anyone reading where you use the Date class could be confused.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    infernocy is offline Member
    Join Date
    Apr 2012
    Posts
    15
    Rep Power
    0

    Default Re: servicedate field in java

    i have to create two methods in the depot class rent vehicle and remove vehicle , rent vehicle(the method should take the code of a vehicle and a date when the vehicle must be return - if there is a vehicle with the same code , that can be return and that is not rented it should be rented )

    what is the best way to store the servicedate in the Vehicle class for this to work
    i will change the names

    thanks
    Last edited by infernocy; 04-08-2012 at 09:56 PM.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: servicedate field in java

    The contents/value of the service date should be determined by how you are going to be using it in the program.
    It could be passed to the class in any format and then converted to how you want to save it.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Java Date in Text Field
    By Richard5324 in forum New To Java
    Replies: 1
    Last Post: 11-17-2011, 07:57 AM
  2. Replies: 0
    Last Post: 07-22-2011, 01:47 PM
  3. front end display of field description when clicking the field name
    By neils in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 10-29-2010, 12:47 PM
  4. Replies: 1
    Last Post: 10-25-2010, 01:20 PM
  5. Replies: 4
    Last Post: 01-18-2010, 12:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •