Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 11.11 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /* Title: Gregorian Calendar
  2.  * Authour: Robert B.
  3.  * Assignemnt: Final ISU (Culnamating)
  4.  * Date: June 18 2012
  5.  */
  6.  
  7. public class finalISU
  8. {
  9.     public static void main (String[] args)
  10.     {
  11.  
  12.         //variable declarations
  13.         int mon = 1, date = 1900, y = 1900, y2 = 0, mon2 = 0, date2 = 0, n, i = 0, q = 0;
  14.         int fday, start = 1900, dtotal = 0, dnum = 365, after;
  15.         char option, loop1 = '$', loop2 = '$';
  16.         boolean isleap, check = true;
  17.  
  18.         isleap = leapyear (y);
  19.  
  20.         while (loop1 == '$')
  21.         {
  22.             //prompts user for options
  23.             System.out.println ("Please choose one of the following options: ");
  24.             System.out.println ("(A) full calender/ (B) month / (C) day from date / (D) date from days / (E) Book Appointment");
  25.             System.out.print ("Option: ");
  26.             option = In.getChar ();
  27.  
  28.             //space
  29.             System.out.println ();
  30.             System.out.println ();
  31.             System.out.println ();
  32.  
  33.  
  34.             switch (option)
  35.             {
  36.                 case 'A':
  37.  
  38.                     System.out.print ("Enter Year: ");
  39.                     y = In.getInt ();
  40.                     while (y < 1900)
  41.                     {
  42.                         System.out.println ("Error: must be a year after 1900");
  43.                         System.out.print ("Enter Year: ");
  44.                         y = In.getInt ();
  45.                     }
  46.                     //go to completecal method for info
  47.                     completecal (y);
  48.                     break;
  49.  
  50.                 case 'B':
  51.  
  52.                     System.out.print ("Enter Year: ");
  53.                     y = In.getInt ();
  54.  
  55.  
  56.                     while (y < 1900)
  57.                     {
  58.                         System.out.println ("Error: must be a year after 1900");
  59.                         System.out.print ("Enter Year: ");
  60.                         y = In.getInt ();
  61.                     }
  62.  
  63.                     System.out.print ("Enter Month (1-12): ");
  64.                     mon = In.getInt ();
  65.  
  66.  
  67.                     while (mon < 1 || mon > 12)
  68.                     {
  69.                         System.out.println ("Error: Invalid month");
  70.                         System.out.println ("Enter Month (1-12): ");
  71.                         mon = In.getInt ();
  72.                     }
  73.  
  74.                     //
  75.                     monthcal (y, mon);
  76.                     break;
  77.  
  78.                 case 'C':
  79.  
  80.                     System.out.print ("Enter Year: ");
  81.                     y = In.getInt ();
  82.  
  83.                     while (y < 1900)
  84.                     {
  85.                         System.out.println ("Error: must be a year after 1900");
  86.                         System.out.print ("Enter Year: ");
  87.                         y = In.getInt ();
  88.                     }
  89.  
  90.                     //
  91.  
  92.  
  93.                     //
  94.                     System.out.print ("Enter Month (1-12): ");
  95.                     mon = In.getInt ();
  96.  
  97.                     while (mon < 1 || mon > 12)
  98.                     {
  99.                         System.out.println ("Error: Invalid month");
  100.                         System.out.print ("Enter Month (1-12): ");
  101.                         mon = In.getInt ();
  102.                     }
  103.  
  104.                     //
  105.                     System.out.print ("Enter Date (1-31): ");
  106.                     date = In.getInt ();
  107.  
  108.                     //
  109.                     while ((date < 1 || date > 31) || ((mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12) && date > 31))
  110.                     {
  111.                         System.out.println ("Error: Date must correspond to month");
  112.                         System.out.print ("Enter Date (1-31): ");
  113.                         date = In.getInt ();
  114.                     }
  115.  
  116.                     while ((mon == 4 || mon == 6 || mon == 9 || mon == 11) && date > 30)
  117.                     {
  118.                         System.out.println ("Error: Date must correspond to month");
  119.                         System.out.print ("Enter Date (1-31): ");
  120.                         date = In.getInt ();
  121.                     }
  122.  
  123.                     while ((mon == 2 && isleap == true) && date > 29)
  124.                     {
  125.                         System.out.println ("Error: Date must correspond to month");
  126.                         System.out.print ("Enter Date (1-31): ");
  127.                         date = In.getInt ();
  128.                     }
  129.  
  130.                     //
  131.                     WeekDay (y, mon, date);
  132.                     break;
  133.  
  134.                 case 'D':
  135.  
  136.                     //
  137.                     System.out.print ("Enter Today's Year: ");
  138.                     y = In.getInt ();
  139.  
  140.                     //
  141.                     while (y < 1900)
  142.                     {
  143.                         System.out.println ("Error: Must be a year after 1900");
  144.                         System.out.print ("Enter Today's Year: ");
  145.                         y = In.getInt ();
  146.                     }
  147.  
  148.                     System.out.print ("Enter Month (1-12): ");
  149.                     mon = In.getInt ();
  150.  
  151.                     while (mon < 1 || mon > 12)
  152.                     {
  153.                         System.out.println ("Error: Invalid Month");
  154.                         System.out.print ("Enter Month (1-12): ");
  155.                         mon = In.getInt ();
  156.                     }
  157.  
  158.                     System.out.print ("Enter Date (1-31): ");
  159.                     date = In.getInt ();
  160.  
  161.                     //
  162.                     while ((date < 1 || date > 31) || ((mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12) && date > 31))
  163.                     {
  164.                         System.out.println ("Error: Date must correspond to month");
  165.                         System.out.print ("Enter Date (1-31): ");
  166.                         date = In.getInt ();
  167.                     }
  168.  
  169.                     while ((mon == 4 || mon == 6 || mon == 9 || mon == 11) && date > 30)
  170.                     {
  171.                         System.out.println ("Error: Date must correspond to month");
  172.                         System.out.print ("Enter Date (1-31): ");
  173.                         date = In.getInt ();
  174.                     }
  175.  
  176.                     while ((mon == 2 && isleap == true) && date > 29)
  177.                     {
  178.                         System.out.println ("Error: Date must correspond to month");
  179.                         System.out.print ("Enter Date (1-31): ");
  180.                         date = In.getInt ();
  181.                     }
  182.  
  183.                     System.out.println ("Enter number of days after today: ");
  184.                     after = In.getInt ();
  185.  
  186.                     addDay (year, month, date, after);
  187.  
  188.                     System.out.println ();
  189.  
  190.                 case 'E':
  191.  
  192.                     System.out.print ("Enter number of timeslots: ");
  193.                     n = In.getInt ();
  194.                     int[] slots = new int [n];
  195.                     int[] slote = new int [n];
  196.                     int holds = 0, holde = 0;
  197.  
  198.  
  199.                     while (0 < n)
  200.                     {
  201.  
  202.                         while (loop2 == '$')
  203.                         {
  204.                             System.out.print ("Enter Year of reservation: ");
  205.                             y = In.getInt ();
  206.  
  207.                             while (y < 1900)
  208.                             {
  209.                                 System.out.println ("Error: Must be a year after 1900");
  210.                                 System.out.print ("Enter Year of reservations: ");
  211.                                 y = In.getInt ();
  212.                             }
  213.  
  214.                             System.out.print ("Enter Month of reservation (1-12): ");
  215.                             mon = In.getInt ();
  216.  
  217.                             while (mon < 1 || mon > 12)
  218.                             {
  219.                                 System.out.println ("Error: Invalid Month");
  220.                                 System.out.print ("Enter Month of reservation (1-12): ");
  221.                             }
  222.  
  223.                             System.out.print ("Enter date of reservation (1-31): ");
  224.                             date = In.getInt ();
  225.  
  226.                             while ((date < 1 || date > 31) || ((mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12) && date > 31))
  227.                             {
  228.                                 System.out.println ("Error: Date must correspond to month");
  229.                                 System.out.print ("Enter Date of reservation (1-31): ");
  230.                                 date = In.getInt ();
  231.                             }
  232.  
  233.                             while ((mon == 4 || mon == 6 || mon == 9 || mon == 11) && date > 30)
  234.                             {
  235.                                 System.out.println ("Error: Date must correspond to month");
  236.                                 System.out.print ("Enter Date of reservation (1-31): ");
  237.                                 date = In.getInt ();
  238.                             }
  239.  
  240.                             while ((mon == 2 && isleap == true) && date > 29)
  241.                             {
  242.                                 System.out.println ("Error: Date must correspond to month");
  243.                                 System.out.print ("Enter Date of reservation (1-31): ");
  244.                                 date = In.getInt ();
  245.                             }
  246.  
  247.                             if (mon < 3)
  248.                             {
  249.                                 mon = mon + 12;
  250.                                 y = y - 1;
  251.                             }
  252.                             fday = ((date + (2 * mon) + (6 * mon + 1) / 10) + y + (y / 4) - (y / 100) = (y / 400) + 1) % 7);
  253.  
  254.                             if (mon > 12)
  255.                             {
  256.                                 mon = mon - 12;
  257.                                 y = y + 1;
  258.                             }
  259.                             while (fday == 1 || fday == 2 || fday = 3 || fday = 4 || fday == 5)
  260.                             {
  261.                                 System.out.println ("Error: The date is not a Saturday or Sunday. Try again.");
  262.                                 System.out.print ("Enter Date of reservation (1-31): ");
  263.                                 date = In.getInt ();
  264.                             }
  265.  
  266.                             if (mon < 3)
  267.                             {
  268.                                 mon = mon + 12;
  269.                                 y = y - 1;
  270.                             }
  271.  
  272.                             fday = ((date + (2 ^ mon) + 6 * (mon + 1) / 10) + y + (y / 4) - (y / 100) + y / 400) + 1) % 7;
  273.  
  274.                             if (month > 12)
  275.                             {
  276.                                 month = month - 12;
  277.                                 year = year + 1;
  278.                             }
  279.                         }
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.                     }
  288.             }
  289.         }
  290.  
  291.  
  292.         public static boolean leapyear (int y)
  293.         {
  294.             if ((y % 4 == 0) && (y % 100 != 0 || y % 400 == 0))
  295.                 return true;
  296.             else
  297.                 return false;
  298.         }
  299.     }