diff --git a/ch11/.checkstyle b/ch11/.checkstyle deleted file mode 100644 index 744b9f9..0000000 --- a/ch11/.checkstyle +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/ch11/.classpath b/ch11/.classpath deleted file mode 100644 index 3f3893a..0000000 --- a/ch11/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/ch11/.project b/ch11/.project deleted file mode 100644 index dd4d0e0..0000000 --- a/ch11/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - ch11 - - - - - - org.eclipse.jdt.core.javabuilder - - - - - net.sf.eclipsecs.core.CheckstyleBuilder - - - - - - org.eclipse.jdt.core.javanature - net.sf.eclipsecs.core.CheckstyleNature - - diff --git a/ch11/Time.java b/ch11/Time.java deleted file mode 100644 index fe5bfd6..0000000 --- a/ch11/Time.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Represents a time of day. - */ -public class Time { - - private int hour; - private int minute; - private double second; - - /** - * Construct a Time object with default values. - */ - public Time() { - this.hour = 0; - this.minute = 0; - this.second = 0.0; - } - - /** - * Construct a Time object with given values. - */ - public Time(int hour, int minute, double second) { - this.hour = hour; - this.minute = minute; - this.second = second; - } - - public int getHour() { - return this.hour; - } - - public int getMinute() { - return this.minute; - } - - public double getSecond() { - return this.second; - } - - public void setHour(int hour) { - this.hour = hour; - } - - public void setMinute(int minute) { - this.minute = minute; - } - - public void setSecond(double second) { - this.second = second; - } - - /** - * Prints the time in a simple format. - */ - public static void printTime(Time t) { - System.out.print(t.hour); - System.out.print(":"); - System.out.println(t.minute); - System.out.print(":"); - System.out.println(t.second); - } - - /** - * Returns a String representation of the time. - */ - public String toString() { - return String.format("%02d:%02d:%04.1f\n", - this.hour, this.minute, this.second); - } - - /** - * Tests whether two times are equivalent. - */ - public boolean equals(Time that) { - final double DELTA = 0.001; - return this.hour == that.hour - && this.minute == that.minute - && Math.abs(this.second - that.second) < DELTA; - } - - /** - * Adds two Times and returns a new Time object (static method). - */ - public static Time add(Time t1, Time t2) { - Time sum = new Time(); - sum.hour = t1.hour + t2.hour; - sum.minute = t1.minute + t2.minute; - sum.second = t1.second + t2.second; - return sum; - } - - /** - * Adds two Times and returns a new Time object (instance method). - */ - public Time add(Time t2) { - Time sum = new Time(); - sum.hour = this.hour + t2.hour; - sum.minute = this.minute + t2.minute; - sum.second = this.second + t2.second; - - if (sum.second >= 60.0) { - sum.second -= 60.0; - sum.minute += 1; - } - if (sum.minute >= 60) { - sum.minute -= 60; - sum.hour += 1; - } - if (sum.hour >= 24) { - sum.hour -= 24; - } - return sum; - } - -} diff --git a/ch11/TimeClient.java b/ch11/TimeClient.java deleted file mode 100644 index aa90401..0000000 --- a/ch11/TimeClient.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Class that uses Time objects. - */ -public class TimeClient { - - public static void main(String[] args) { - Time time = new Time(11, 59, 59.9); - System.out.println(time); - - // cannot access private variables from another class - // System.out.println(time.hour); - - String s = time.toString(); - System.out.println(s); - - Time time1 = new Time(9, 30, 0.0); - Time time2 = time1; - Time time3 = new Time(9, 30, 0.0); - - System.out.println(time1 == time2); - System.out.println(time1 == time3); - System.out.println(time1.equals(time2)); - System.out.println(time1.equals(time3)); - - Time startTime = new Time(18, 50, 0.0); - Time runningTime = new Time(2, 16, 0.0); - Time endTime = Time.add(startTime, runningTime); - - // using the instance method - endTime = startTime.add(runningTime); - } - -}