日期復活節我寫了一個名爲復活節類(見下文),並命名爲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());' –