In a 30-day month planner, the day reading goes this way: 1,2,3,...28,29,30,1,2,3..
Implement a class, ModMonth, to perform the following:
Q1.succ(dy), returning the value of the next day.
succ(29) => 30,
succ(30)=> 1
Q2. pred(dy), returning the value of the previous day
pred(2) => 1,
pred(1) ==> 30.
Question is, how to make a short solution to it that also works for a trillion-day month by simply modifying some constants instead of enumerating a trillion values? As for instance:
public int succ(int dy) {
int[] nextDay = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1
};
return nextDay [dy - 1];
}
Both of these methods are not acceptable.. which i can only think this way. Same goes to the public int succ int dy.. dy ==1
Is there any other way to make a short method? I'm using Drjava apps btw.