Results 1 to 5 of 5
Thread: servicedate field in java
- 04-07-2012, 06:20 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 15
- Rep Power
- 0
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
and my vehicle class so farJava 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; } }
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 ?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; } }
thanks for all the helpLast edited by Fubarable; 04-07-2012 at 06:33 PM. Reason: quote tags changed to code tags
-
Re: servicedate field in java
moderation: quote tags changed to code tags.
- 04-07-2012, 06:40 PM #3
Re: servicedate field in java
What would the arraylist be for?what is the best way to do it?
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.
- 04-08-2012, 08:49 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 15
- Rep Power
- 0
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
thanksLast edited by infernocy; 04-08-2012 at 08:56 PM.
- 04-08-2012, 08:53 PM #5
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
-
Java Date in Text Field
By Richard5324 in forum New To JavaReplies: 1Last Post: 11-17-2011, 06:57 AM -
adding field with tokenStream Field(name, tokenStream, termVector) constructor
By gadek.a in forum LuceneReplies: 0Last Post: 07-22-2011, 12:47 PM -
front end display of field description when clicking the field name
By neils in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 10-29-2010, 11:47 AM -
Help with bcc field and cc field in java code
By eel in forum NetworkingReplies: 1Last Post: 10-25-2010, 12:20 PM -
how from an Access Currency field I populate a hidden field
By lse123 in forum Java ServletReplies: 4Last Post: 01-17-2010, 11:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks