I'm trying to write a Date class with doomsday rule, in which when the user inputs a year, month and day in a test class, it would output the day of the week.
With the codes below I can find out the dooms day of the year from 1100 to 2900, but then where do I go from here?
(I'm new to Java, so if my code can be cleaner please let me know.
private int year;
private int month;
private int day;
public Set <Integer> tue = new HashSet <Integer> (Arrays.asList(20,16,24,28,12));
public Set <Integer> fri = new HashSet <Integer> (Arrays.asList(18,14,22,26));
public Set <Integer> sun = new HashSet <Integer> (Arrays.asList(21,17,13,25,29));
public Set <Integer> wed = new HashSet <Integer> (Arrays.asList(19,15,23,27,11));
public int getDoomsDay() {
int y = Integer.parseInt(Integer.toString(this.year).substring(0,2));
int c;
if(tue.contains(y)){
c = 2;
}
else if(fri.contains(y)){
c = 5;
}
else if(sun.contains(y)) {
c = 0;
}
else {
c = 3;
}
int d = Integer.parseInt(Integer.toString(this.year).substring(2,4));
int s = d/12;
int t = d%12;
int f = t/s;
int b;
if((c+s+t+f) > 6) {
b = (c+s+t+f)%7;
}
else {
b = (c+s+t+f);
}
if(this.year % 4 == 0 && this.year % 100 != 0) {
return b +1;
}
else {
return b;
}
}