public class Nextday { //第一个
public static Date nextDay(Date d) {
Date dd = new Date(d.getMonth().getCurrentPos(), d.getDay().getCurrentPos(), d.getYear().getCurrentPos());
dd.increment();
return dd;
}
}
public class Date { // 第二个
private Day d;
private Month m;
private Year y;
public Date(int pMonth, int pDay, int pYear) {
y = new Year(pYear);
m = new Month(pMonth, y);
d = new Day(pDay, m);
}
public void increment() {
if (!d.increment()) {
if (!m.increment()) {
y.increment();
m.setMonth(1, y);
}
d.setDay(1, m);
}
}
public void printDate() {
System.out.println(m.getMonth() + "/" + d.getDay() + "/" + y.getYear());
}
public Day getDay() {
return d;
}
public Month getMonth() {
return m;
}
public Year getYear() {
return y;
}
public boolean equals(Object o) {
if (o instanceof Date) {
if (this.y.equals(((Date) o).y) && this.m.equals(((Date) o).m)
&& this.d.equals(((Date) o).d))
return true;
}
return false;
}
public String toString() {
return (m.getMonth() + "/" + d.getDay() + "/" + y.getYear());
}
}
2 回答

慕桂英9052184
TA贡献1条经验 获得超0个赞
package net.mooctest;
import static org.junit.Assert.*;
import org.junit.Test;
public class NextdayTest {
@Test
public void test() {
Nextday n = new Nextday();
Date d = new Date(2,28,2008);
Date expectedDate = new Date(2,29,2008);
assertEquals(expectedDate,n.nextDay(d));
}
}
这是我写的。
添加回答
举报
0/150
提交
取消