Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. using System;
  2. // if you want to use the instructor's version of "MyDate":
  3. //using Date_SOLUTION; // leave this line UNcommented
  4. using A3_Date_StudentWork; // and comment this line out.
  5. //If you want to use your version of "MyDate" then comment out "using TEACHER_SOLUTION;"
  6. // and UNcomment "using A3_Date_StudentWork";
  7.  
  8.  
  9. // Roberto Ramirez Bit 142 2017 spring A2.0
  10. namespace A3_Date
  11. {
  12. class Birthday
  13. {
  14.  
  15. static void Main(string[] args)
  16. {
  17. bool useProgram = true;
  18. bool firstTime = true;
  19. while (useProgram)
  20. {
  21.  
  22. /* i wrote this because it was easier to test all 4 values plus a few new ones, rather than running the program
  23. over and over*/
  24.  
  25. Console.Write(firstTime ? "would you like to use the program?: " : "would you like to use the program again?: ");
  26. string input = Console.ReadLine();
  27. useProgram = false;
  28. if (input.Equals("y", StringComparison.InvariantCultureIgnoreCase))
  29. useProgram = true;
  30.  
  31. //MyDate today;
  32. int todayYear;
  33. int todayMonth;
  34. int todayDay;
  35.  
  36. // MyDate bday;
  37. int bdayYear;
  38. int bdayMonth;
  39. int bdayDay;
  40.  
  41. Console.WriteLine("What is today's year?");
  42. Int32.TryParse(Console.ReadLine(), out todayYear);
  43. Console.WriteLine("What is today's month?");
  44. Int32.TryParse(Console.ReadLine(), out todayMonth);
  45. Console.WriteLine("What is today's day?");
  46. Int32.TryParse(Console.ReadLine(), out todayDay);
  47. Console.WriteLine("What is your birthday year?");
  48. Int32.TryParse(Console.ReadLine(), out bdayYear);
  49. Console.WriteLine("What is your birthday month?");
  50. Int32.TryParse(Console.ReadLine(), out bdayMonth);
  51. Console.WriteLine("What is your birthday day?");
  52. Int32.TryParse(Console.ReadLine(), out bdayDay);
  53. // creating new objects
  54.  
  55. MyDate tday = new MyDate(todayYear, todayMonth, todayDay);
  56. MyDate birthday = new MyDate(bdayYear, bdayMonth, bdayDay);
  57.  
  58. Console.WriteLine("there are {0} days in month #{1}", birthday.daysInMonth(), bdayMonth);
  59.  
  60. Console.WriteLine("{0} {1} a leap year", todayYear, tday.isLeapYear() ? "Is" : "is Not");
  61.  
  62. // using a conditional "?" operator for boolean values to run effective on one line.
  63. MyDate tempDate = new MyDate(tday);
  64. int daysUntilBirthday = 0;
  65.  
  66. while (!tempDate.equalsIgnoreYear(birthday))
  67. {
  68. tempDate.nextDay();
  69.  
  70. daysUntilBirthday++;
  71. }
  72.  
  73.  
  74. //create the boolean operator to determine if happy birthday is needed or not.
  75.  
  76.  
  77. Console.WriteLine(tday.equalsIgnoreYear(birthday) ? "Happy Birthday!" : " Number of days till birthday {0} : {1}", birthday.toString(birthday) , daysUntilBirthday);
  78.  
  79. Console.WriteLine("you are {0} years old right now", tday.earlierThan(tempDate) ? todayYear - bdayYear - 1 : todayYear - bdayYear);
  80.  
  81. // REMEMBER TO TEST OUT YOUR CODE WITH _BOTH_ THE INSTRUCTOR'S
  82. // VERSION _AND_ YOUR VERSION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  83. // (there are more details at the top of this file)
  84. firstTime = false;
  85. }
  86. }
  87.  
  88.  
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement