Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Class;
- public class Clock {
- /* properties */
- public static final int MAX_HOUR = 24;
- public static final int MAX_MINUTE = 60;
- protected static boolean format = false;
- protected int hour;
- protected int minute;
- /* get, set methods */
- public static void setFormat(boolean bool_format) {
- format = bool_format;
- }
- public static void setFormat(int format) {
- if (format == 12) { setFormat(false); }
- else if (format == 24) { setFormat(true); }
- }
- public static boolean getFormat() {
- return format;
- }
- public void setHour(int hour) {
- if (hour < 0) { hour = 0; }
- this.hour = hour%MAX_HOUR;
- }
- public int getHour() {
- return hour;
- }
- public void setMinute(int minute) {
- if (minute < 0) { minute = 0; }
- this.minute = minute%MAX_MINUTE;
- }
- public int getMinute() {
- return minute;
- }
- /* constructors */
- public Clock(int hour, int minute) {
- setHour(hour);
- setMinute(minute);
- }
- public Clock() {
- this(0, 0);
- }
- /* copy constructor */
- public Clock(Clock clockObj) {
- hour = clockObj.hour;
- minute = clockObj.minute;
- }
- /* methods */
- public String toString() { //setting AM/PM styling
- String flag = " (" + ((hour < (MAX_HOUR/2))?"AM":"PM") + ')';
- //returning the styled string
- return String.format("(%s@%h) %02d:%02d%s",
- this.getClass().getName(),
- this,
- (format) ? hour : ( hour % (MAX_HOUR/2) ),
- minute,
- (format)?"":flag);
- }
- }
Add Comment
Please, Sign In to add comment