My code asks for the user to enter the day with an integer value ie Sunday = 0, Monday = 1, etc., then asks the user to input a number representing an offset day. From there the program finds the day corresponding to the offset number ie
Enter today's day: 0 //Sunday
Enter the number of days elapsed since today: 6
6 days from Sunday is Sunday
The problem with the above output is that since I'm using, "%6" to find the offset day, it skips one day for values 6.
Also, I can't figure a way to find the day for an entered negative offset value. ie
Enter today's day: 0 //Sunday
Enter the number of days elapsed since today: -2
-2 days from Sunday is Friday
Here's my code
import java.util.Scanner ;
public class test {
public static void main (String[] args) {
Scanner Input = new Scanner(System.in);
System.out.print("Enter today's day: ");
int today = Input.nextInt();
System.out.print("Enter the number of days elapsed since today: ");
int offset = Input.nextInt ();
int offsetDay = 0;
if (offset >= 0)
offsetDay = (today + offset)% 6 ; //to get remainder and make it vary from 0 - 6
else if (offset < 0)
offsetDay = (today - offset)% 6 ;
String todayText = null ;
String offsetText = null;
//Converting input integers into days in text for variable today
switch (today) {
case 0 : todayText = "Sunday" ; break;
case 1 : todayText = "Monday"; break;
case 2 : todayText = "Tuesday"; break;
case 3 : todayText = "Wednesday";break;
case 4 : todayText = "Thrusday"; break;
case 5 : todayText = "Friday"; break;
case 6 : todayText = "Saturday"; break;
}
//Converting input integers into days in text for variable offset
switch (offsetDay) {
case 0 : offsetText = "Sunday" ; break;
case 1 : offsetText = "Monday"; break;
case 2 : offsetText = "Tuesday"; break;
case 3 : offsetText = "Wednesday";break;
case 4 : offsetText = "Thrusday"; break;
case 5 : offsetText = "Friday"; break;
case 6 : offsetText = "Saturday"; break;
}
System.out.println(offset + " days from " + todayText + " is " + offsetText);
}
}
My last question is, how would I implement this using enumeration? Any thoughts?