Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- // if you want to use the instructor's version of "MyDate":
- //using Date_SOLUTION; // leave this line UNcommented
- using A3_Date_StudentWork; // and comment this line out.
- //If you want to use your version of "MyDate" then comment out "using TEACHER_SOLUTION;"
- // and UNcomment "using A3_Date_StudentWork";
- // Roberto Ramirez Bit 142 2017 spring A2.0
- namespace A3_Date
- {
- class Birthday
- {
- static void Main(string[] args)
- {
- bool useProgram = true;
- bool firstTime = true;
- while (useProgram)
- {
- /* i wrote this because it was easier to test all 4 values plus a few new ones, rather than running the program
- over and over*/
- Console.Write(firstTime ? "would you like to use the program?: " : "would you like to use the program again?: ");
- string input = Console.ReadLine();
- useProgram = false;
- if (input.Equals("y", StringComparison.InvariantCultureIgnoreCase))
- useProgram = true;
- //MyDate today;
- int todayYear;
- int todayMonth;
- int todayDay;
- // MyDate bday;
- int bdayYear;
- int bdayMonth;
- int bdayDay;
- Console.WriteLine("What is today's year?");
- Int32.TryParse(Console.ReadLine(), out todayYear);
- Console.WriteLine("What is today's month?");
- Int32.TryParse(Console.ReadLine(), out todayMonth);
- Console.WriteLine("What is today's day?");
- Int32.TryParse(Console.ReadLine(), out todayDay);
- Console.WriteLine("What is your birthday year?");
- Int32.TryParse(Console.ReadLine(), out bdayYear);
- Console.WriteLine("What is your birthday month?");
- Int32.TryParse(Console.ReadLine(), out bdayMonth);
- Console.WriteLine("What is your birthday day?");
- Int32.TryParse(Console.ReadLine(), out bdayDay);
- // creating new objects
- MyDate tday = new MyDate(todayYear, todayMonth, todayDay);
- MyDate birthday = new MyDate(bdayYear, bdayMonth, bdayDay);
- Console.WriteLine("there are {0} days in month #{1}", birthday.daysInMonth(), bdayMonth);
- Console.WriteLine("{0} {1} a leap year", todayYear, tday.isLeapYear() ? "Is" : "is Not");
- // using a conditional "?" operator for boolean values to run effective on one line.
- MyDate tempDate = new MyDate(tday);
- int daysUntilBirthday = 0;
- while (!tempDate.equalsIgnoreYear(birthday))
- {
- tempDate.nextDay();
- daysUntilBirthday++;
- }
- //create the boolean operator to determine if happy birthday is needed or not.
- Console.WriteLine(tday.equalsIgnoreYear(birthday) ? "Happy Birthday!" : " Number of days till birthday {0} : {1}", birthday.toString(birthday) , daysUntilBirthday);
- Console.WriteLine("you are {0} years old right now", tday.earlierThan(tempDate) ? todayYear - bdayYear - 1 : todayYear - bdayYear);
- // REMEMBER TO TEST OUT YOUR CODE WITH _BOTH_ THE INSTRUCTOR'S
- // VERSION _AND_ YOUR VERSION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- // (there are more details at the top of this file)
- firstTime = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement