import structure5.Assert; import java.util.Random; import java.util.Scanner; /** Simple Date representation for lab 4. */ public class Date2 { /** Used for generating random dates. */ private static final Random r = new Random(312); /** Returns the number of days in month m of year y, where 1 = January and 2000 = year 2000 */ static public int numDays(int m, int y) { return 30; } /** Constructs a new Date. @pre 0 < m <= 12; y >= 1900; 0 < d <= num days in that month */ public Date2(int d, int m, int y) { Assert.pre(d > 0 && d <= numDays(m, y), "Day out of range. (d = " + d + ")"); Assert.pre(m > 0 && m <= 12, "Month out of range. (m = " + m + ")"); Assert.pre(y >= 1900, "Year out of range. (y = " + y + ")"); Assert.pre(y <= 2099, "Year out of range. (y = " + y + ")"); } /** Returns the day of the month, where 1 = the first day */ public int getDay() { return 0; } /** Returns the month, where 1 = January */ public int getMonth() { return 0; } /** Returns the year, where 2000 = the year 2000 */ public int getYear() { return 0; } /** Returns the day of the week corresponding to this date, where 0 = Saturday */ public int getDayOfWeek() { return 0; } /** Converts a day of the week, where 0 = Sat, to the equivalent string. */ static public String dayOfWeekToString(int day) { Assert.pre((day >= 0) && (day < 7), "Illegal day"); return ""; } /** Produces a random date between 1900 and 2099 (no guarantees * about the distribution of dates, however). For a given run of the program, * the random number generator is always initialized with the same seed, so * generating a sequence of random dates always produces the same sequence. */ static public Date2 random() { int y = 1899 + randomInt(200); int m = randomInt(12); int d = randomInt(numDays(m, y)); return new Date2(d, m, y); } /** Generates a random number between 1 and high. */ static private int randomInt(int high) { return r.nextInt(high) + 1; } /** Generates a string representation with the month spelled out. */ public String toString() { return ""; } }