09-06-2007, 20:26
|
|
|
חבר מתאריך: 06.05.07
הודעות: 4
|
|
שימוש בשיטת Isvalid ב Java
אני בונה תוכנית בעזרת שלוש מחלקות: Passport, Traveler, Data
בשלב הזה אני סיימתי את מחלקת Date ומנסה ליישם שיטה במחלקת Passport שתאמת אם הדרכון תקף בתאריך הנתון ואני מחפש דרך לממש את השיטה דרך ה Date למישהו יש רעיון איך אני ממשיך משם?
קוד:
public class Passport
{
private int _number;
private Date _expiryDate;
private String _name;
/**
* * Constructor for objects of class Passport
Constructs a passport given an passport number, name, and expiry date for a passport
*/
public Passport ( int number, String name, Date expiryDate )
{
if (name==null || expiryDate==null)
System.out.println("illegal passport # sent to set SetDate");
else
{
_expiryDate= new Date (expiryDate);
_name= new String (name);
}
}
/**
* Constructor for objects of class passport
* Copy constructor
*/
public Passport (Passport other)
{
if (other==null)
System.out.println("illegal passport sent to copy consturctor");
else
{
this._number = other._number;
this._expiryDate = new Date (other._expiryDate);
this._name = new String (other._name);
}
}
/**
* The method returns with passport #
*/
public int getNumber()
{
return this. _number;
}
/**
* The operation returns with a name
*/
public String getName()
{
return this._name;
}
/**
* The method returns with expiry date
*/
public Date getExpiryDate()
{
return this._expiryDate;
}
public void setName (String name)
{
if (name==null)
System.out.println("illegal name sent to setName");
else
name = new String (_name);
}
public void setExpiryDate (Date newExpDate) {
if (newExpDate==null)
System.out.println("illegal expiry date sent to setName");
else
newExpDate = new Date (newExpDate);
}
public boolean isValid (Date dateChecked) {
|