horsemanship世界

星期一, 4月 24, 2006

Lab8

package lab8;
public class EqualsAndToStringDemo {
public static void main(String[] args)
{
DateFourthTry() date1 = new DateFourthTry(),
date2 = new DateFourthTry();

date1.setDate(6,17,1882);
date2.setDate(6,17,1882);

if(date.equals(date2))
System.out.println(date1 + "equals"+date2);
else
Syetem.out.println(date1 + "does not equal"+date2);

date1.setDate(7,28,1750);

if(date1.precedes(date2))
Syetem.out.println(date1 + " comes befpre "+date2);
else
Syetem.out.println(date2 + "comes befpre or is equal to "+date1);
}
}

=========================================
package lab8;
import java.io.*;
public class DateFourthTry
{
private String month;
private int day, year;

public String toString()
{
return (month+" "+ day +", " + year);
}

public void writeOutput()
{
System.out.println(month+" "+ day +", " + year);
}

public boolean equals( DateFourthTry otherDate)
{
return((month.equals(otherDate)) && (day == otherDate.day) &&
(year == otherDate.year));
}
public boolean precedes(DateFourthTry otherDate)
{
return ((year < otherDate.year) (year == otherDate.year && getMonth() <
otherDate.getMonth())
(year < otherDate.year && month.equals(otherDate.month) &&day <
otherDate.day));
}}

0 Comments:

張貼留言

<< Home