I have been given a task for college and it is to create a program where the user will input the date and the program will return a numerical value which corresponds with the day of that specific date.
3 things must be taken into consideration:
-
Before the 3rd of September 1752 there is an equation that is used to generate a numerical value. However....
-
After the 13th of September 1752 the calendar was changed to more accurately represent the days in the year and therefore a different equation is used to represent these dates.
-
Lastly, between the 3rd and the 13th of September 1752 the program should return that these dates did not exist at all since the change in calendar skipped the days in between.
I have an if statement that I want to be one big condition instead of separate ones:
if (yyyy <= 1752 && mm <= 9 && dd < 3)
But the problem is if I choose a date that is on the year 1752, that is on or before the 9th month, and has a day that is higher than 3, an answer will not be returned. Therefore (dd/mm/yyyy) >3/January-August/1752 will not return an answer.
The rest of the code if anyone wants to mess around with it/test something:
public static void main(String[] args) {
System.out.print("Please enter your desired date(dd/mm/yyyy): ");
String date = new Scanner(System.in).nextLine();
int d1 = (date.charAt(0)-48)*10;
int d2 = date.charAt(1)-48;
int dd = d1+d2;
int m1 = (date.charAt(3)-48)*10;
int m2 = date.charAt(4)-48;
int mm = m1+m2;
int y1 = (date.charAt(6)-48)*1000;
int y2 = (date.charAt(7)-48)*100;
int y3 = (date.charAt(8)-48)*10;
int y4 = date.charAt(9)-48;
int yyyy = y1+y2+y3+y4;
if (dd <= 13 && dd >= 3 && mm == 9 && yyyy == 1752){
System.out.println("This date never occured.");
} if (dd > 13 && mm >= 9 && yyyy >= 1752 || yyyy>1752){
{
while(true){
if (dd > 31){
System.out.println("This is not a valid day.");
dd = new Scanner(System.in).nextInt();
}
if (mm > 12){
System.out.println("This is not a valid month.");
mm = new Scanner(System.in).nextInt();
}
if (mm == 1){
mm = 13;
}
if (mm== 2){
mm = 14;
}
else{
int answer;
answer = (dd +((26*(mm+1))/10)+yyyy+(yyyy/4)+6*(yyyy/100)+(yyyy/400))%7;
System.out.println("\n");
System.out.println("The day was/is: "+answer);
System.out.println("Sa: 0, Su: 1, M: 2, Tu: 3, W: 4, Th: 5, F: 6");
break;
}
}
} }
if ((yyyy <= 1752 && mm <= 9 && dd < 3) || yyyy < 1752){
{
while(true){
if (dd > 31){
System.out.println("This is not a valid day.");
dd = new Scanner(System.in).nextInt();
}
if (mm > 12){
System.out.println("This is not a valid month.");
mm = new Scanner(System.in).nextInt();
}
if (mm == 1){
mm = 13;
}
if (mm== 2){
mm = 14;
}
else{
int answer;
answer = (dd+(26*(mm+1)/10)+yyyy+(yyyy/4)+5)%7;
System.out.println("\n");
System.out.println("The day was/is: "+answer);
System.out.println("Sa: 0, Su: 1, M: 2, Tu: 3, W: 4, Th: 5, F: 6");
break;
}
}
}
}
}
}
Any help is appreciated :3 thank you!
Aucun commentaire:
Enregistrer un commentaire