Created
September 8, 2013 02:12
-
-
Save iamedu/6481285 to your computer and use it in GitHub Desktop.
Very simple dumb implementation of MyCalendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyCalendar { | |
public static DAY = 1; | |
public static MONTH = 2; | |
public static YEAR = 3; | |
private int day; | |
private int month; | |
private int year; | |
public MyCalendar() { | |
day = 1; | |
month = 0; | |
year = 1980; | |
} | |
public void add(int field, int amount) { | |
if(field == DAY) day += amount; | |
else if(field == MONTH) month += amount; | |
else if(field == YEAR) year += amount; | |
} | |
public void set(int field, int amount) { | |
if(field == DAY) day = amount; | |
else if(field == MONTH) month = amount; | |
else if(field == YEAR) year = amount; | |
} | |
public int get(int field) { | |
if(field == DAY) return day; | |
else if(field == MONTH) return month; | |
else if(field == YEAR) return year; | |
throw new RuntimeException("What are you talking about?"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Test { | |
public static void main(String args[]) { | |
MyCalendar dumbCalendar = new MyCalendar(); | |
dumbCalendar.set(MyCalendar.DAY, 1); | |
dumbCalendar.set(MyCalendar.MONTH, 1); | |
dumbCalendar.set(MyCalendar.YEAR, 2015); | |
System.out.println("Some random date " + dumbCalendar.get(MyCalendar.DAY) + dumbCalendar.get(MyCalendar.MONTH) + dumbCalendar.get(MyCalendar.YEAR)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment