日期复活节我写了一个名为复活节类(见下文),并命名为EasterTester(也低于)一个测试类来执行它,并插上年份值。目标是实现高斯的算法,用于计算任意指定年份复活节周日的月份和日期。在Java和UML方法语法
我的代码工作正常,但我有我的书有点混乱,我下面。它告诉我不要在我的第一个代码链接的底部实现两个getter方法,因为我“不需要它们”。正如我的代码,我肯定需要它们。有什么我失踪涉及?
此外,它列出了我建议作为使用“复活节类公共接口”:
calculateEaster(INT aYear):字符串
“的UML方法语法指示该方法将一个整数参数并返回一个字符串。“我不明白这个评论,因此,我不明白如何编辑我的代码以遵循这些指导方针。
如果任何人都可以提供对困境/问题的任何清晰,我会非常赞赏!
代码: /** * * @author B_T * */
类复活节{
/**
* @param n is the month
* @param p is the day
*/
private int n;
private int p;
// Comments via Cay Horstmann's "Big Java" 4th ed. on page 169; p.4.19
// Let y be the year (such as 1800 or 2001).
/**
*
* @param y this will hold the year that users enter
*/
Easter(int y) {
// Divide y by 19 and call the remainder a. Ignore the quotient.
int a = y % 19;
// Divide y by 100 to get a quotient b and a remainder c.
int b = y/100;
int c = y % 100;
// Divide b by 4 to get a quotient d and a remainder e.
int d = b/4;
int e = b % 4;
// Divide 8 * b + 13 by 25 to get a quotient g. Ignore the remainder.
int g = (8 * b + 13)/25;
// Divide 19 * a + b - d - g + 15 by 30 to get a remainder h. Ignore the quotient.
int h = (19 * a + b - d - g + 15) % 30;
// Divide c by 4 to get a quotient j and a remainder k.
int j = c/4;
int k = c % 4;
// Divide a + 11 * h by 319 to get a quotient m. Ignore the remainder.
int m = (a + 11 * h)/319;
// Divide 2 * e + 2 * j - k - h + m + 32 by 7 to get a remainder r. Ignore the quotient.
int r = (2 * e + 2 * j - k - h + m + 32) % 7;
// Divide h - m + r + 90 by 25 to get a quotient n. Ignore the remainder.
n = (h - m + r + 90)/25;
// Divide h - m + r + n + 19 by 32 to get a remainder p.
p = (h - m + r + n + 19) % 32;
}
/**
*
* @return n returns the month in which a given year's Easter Sunday will take place
*/
public int getEasterSundayMonth() {
return n;
}
/**
*
* @return p returns the day in which a given year's Easter Sunday will take place
*/
public int getEasterSundayDay() {
return p;
}
}
这里是Tester类:
公共类EasterTester {
public static void main(String[] args)
{
Easter myEaster = new Easter(2002);
System.out.println("In 2002, Easter Sunday is: " + "month = " + myEaster.getEasterSundayMonth() + " and day = " + myEaster.getEasterSundayDay());
Easter myEaster2 = new Easter(2012);
System.out.println("In 2012, Easter Sunday is: " + "month = " + myEaster2.getEasterSundayMonth() + " and day = " + myEaster2.getEasterSundayDay());
}
}
测试仪类不_test_什么。 –
@TrueSoft我认为它测试了2002年和2012年?这个意见是什么意思? – dustdustdust
测试人员应该测试结果是否与预期结果相同。了解如何制作[JUnit测试](http://www.vogella.com/articles/JUnit/article.html)(另请参阅[测试驱动开发](http://www.agiledata.org/)文章/ tdd.html))。否则,你可以像这样测试:'int expectedMonth_2012 = 4; if(myEaster2.getEasterSundayMonth()== expectedMonth_2012)System.out.println(“Passed”);否则System.err.println(“失败;预计月份+ expectedMonth_2012 +”,但返回“+ myEaster2.getEasterSundayMonth());' –