title: Design and implement the class Day that implements the day of the week in a program
body: <p>I have a program to write with the following requirements: </p>
  
  <p>Design and implement the class Day that implements the day of the week in a program.  The class Day should store the day, such as Sun for Sunday.  The program should be able to perform the following operations on an object of type Day:</p>
  
  <p>A. Set the day.</p>
  
  <p>B. Print the day.</p>
  
  <p>C. Return the day.</p>
  
  <p>D. Return the next day.</p>
  
  <p>E. Return the previous day.</p>
  
  <p>F. Calculate and return the day by adding certain days to the current day.  For example, if the current day is Monday and we add four days, the day to be returned is Friday.  Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.</p>
  
  <p>G. Add the appropriate constructors.</p>
  
  <p>H. Write the definitions of the methods to implement the operations for the class Day, as defined in A through G.</p>
  
  <p>I. Write a program to test various operations on the class Day.</p>
  
  <p>Now, I've looked at the various thread on this and other sites, read my materials, and have gotten my program just about there.  I'm just having one nagging issue: Sunday.  The code below does everything I expect for every day of the week, except Sunday.  </p>
  
  <p>When I set ourDay to SUN, I do get the nextDay, 10 days out etc, but I keep getting a blank return for previousDay.  I've tried various ways to go about this, but I keep coming back to the way it's written below as being the way it should work, but it's not.  I know that I can't handle SUN the same as other days, since I can't subtract 1 from that and expect a value the program can return properly, which is why I've told it to set ourDay as SAT if the value is SUN.</p>
  
  <p>Any and all assistance would be much appreciated, as I believe I'm missing something simple here, and am just beating my head against the wall at this point.</p>
  
  <p><strong>EDIT</strong>  Thanks everyone for your input.  Using your feedback I've changed the code, updated source is provided below.  For some reason, I'm still getting a blank output for previousDay, although all other functions are working.  I cleaned up a lot, as some of you pointed out I was doing some things that did not need to be done and were redundant.  </p>
  
  <p>At this point I'm almost ready to scrap the approach I've taken and move to using an enum or array.  Any thoughts to that, or should I stick with what I have so far?</p>
  
  <p>FYI my output looks like this when I run:
  The current day: Sunday
  The previous day: 
  The next day: Monday
  10 days later: Thursday</p>
  
  <pre><code>    public class Day
  
  {
          final static int SUN = 0;
          final static int MON = 1;
          final static int TUE = 2;
          final static int WED = 3;
          final static int THU = 4;
          final static int FRI = 5;
          final static int SAT = 6;                 
  
          public static int ourDay;         
  
          public void setDay()
          {this.ourDay = ourDay;} 
  
          public void DayType()
          {this.ourDay = ourDay;}
  
          public int nextDay()
          {
              if (ourDay == SAT)
              {return SUN;}
  
              else
              {ourDay = (ourDay + 1) % 7;}            
              return ourDay;           
          }                  
  
          public int previousDay() 
          {
              if (ourDay == SUN)
              {return SAT;}
  
              else
              {ourDay = (ourDay - 1) % 7;}        
              return ourDay;           
          }       
  
          public int futureDay(int ourDays) 
          {return (ourDay + ourDays) % 7;}
  
          public String toString()        
          {
              switch (this.ourDay) 
                 {
                    case SUN:
                          return "Sunday";
                    case MON:
                          return "Monday";
                    case TUE:
                          return "Tuesday";
                    case WED:
                          return "Wednesday";
                    case THU:
                          return "Thursday";
                    case FRI:
                          return "Friday";
                    case SAT:
                          return "Saturday";
                  }
                    return "";
          }    
  
          public static void main(String[] args) 
          {
                  DayType outDay = new DayType(SUN);                
                  System.out.print("The current day: " + outDay);                
                  System.out.println();
                  outDay.setDay(outDay.previousDay());
                  System.out.print("The previous day: " + outDay);                               
                  System.out.println();
                  outDay.setDay(outDay.nextDay());                
                  outDay.setDay(outDay.nextDay());
                  System.out.print("The next day: " + outDay);              
                  System.out.println();                               
                  outDay.setDay(outDay.futureDays(10));
                  System.out.print("10 days later: " + outDay);               
                  System.out.println();               
          }       
  }
  </code></pre>