public class MyDate { protected int month, date, year; // date as 3 ints, for instance 8, 29, 2014 public MyDate() // no arg constructor, initialize all to 0 { month=date=year=0; } public MyDate(int m, int d, int y) // make the assumption that m, d and y are legal values { month=m; date=d; year=y; } public MyDate(String s) // can also construct the date using a String in the form of either MM/DD/YY or MM/DD/YYYY { month=Integer.parseInt(s.substring(0,2)); // first two chars are the month date=Integer.parseInt(s.substring(3,5)); // after /, next two chars are date if(s.length()==8) year=Integer.parseInt(s.substring(6,8))+2000; // after /, last 2 chars are 2-digit year, add 2000, otherwise else year=Integer.parseInt(s.substring(6,10)); // 4-digit year } public int getMonth(){return month;} // accessors public int getDate(){return date;} public int getYear(){return year;} public void setMonth(int x){if(x>0&&x<13) month=x;} // mutators with minor error detection public void setDate(int x){if(x>0&&x<32) date=x;} public void setYear(int x) {if(x>0&&x<9999) year=x;} public String toString() { return "" + month + "/" + date + "/" + year;} // toString }