From c9b1805fd8758a6d256b9f1fc8571ac2d88c91cd Mon Sep 17 00:00:00 2001 From: Allen Downey Date: Thu, 3 Mar 2016 16:17:03 -0500 Subject: [PATCH 01/29] Adding code for chapters 1-12 --- ch01/Goodbye.java | 13 +++ ch01/Hello.java | 7 ++ ch02/Variables.java | 84 +++++++++++++ ch03/Convert.java | 25 ++++ ch03/Echo.java | 17 +++ ch03/GuessStarter.java | 14 +++ ch03/Input.java | 15 +++ ch03/ScannerBug.java | 25 ++++ ch04/Methods.java | 20 ++++ ch04/NewLine.java | 18 +++ ch04/PrintTime.java | 14 +++ ch04/PrintTwice.java | 11 ++ ch05/Conditional.java | 157 +++++++++++++++++++++++++ ch06/Series.java | 143 +++++++++++++++++++++++ ch06/SeriesTest.java | 10 ++ ch06/ValueMethods.java | 113 ++++++++++++++++++ ch07/Tables.java | 181 +++++++++++++++++++++++++++++ ch08/ArrayExamples.java | 156 +++++++++++++++++++++++++ ch09/StringsThings.java | 55 +++++++++ ch10/Max.java | 23 ++++ ch10/PointRect.java | 61 ++++++++++ ch11/Time.java | 118 +++++++++++++++++++ ch11/TimeClient.java | 14 +++ ch12/Card.java | 82 +++++++++++++ ch12/CardTable.java | 94 +++++++++++++++ ch12/Search.java | 102 ++++++++++++++++ ch12/cardset-oxymoron/01c.gif | Bin 0 -> 670 bytes ch12/cardset-oxymoron/01d.gif | Bin 0 -> 590 bytes ch12/cardset-oxymoron/01h.gif | Bin 0 -> 630 bytes ch12/cardset-oxymoron/01s.gif | Bin 0 -> 956 bytes ch12/cardset-oxymoron/02c.gif | Bin 0 -> 737 bytes ch12/cardset-oxymoron/02d.gif | Bin 0 -> 630 bytes ch12/cardset-oxymoron/02h.gif | Bin 0 -> 698 bytes ch12/cardset-oxymoron/02s.gif | Bin 0 -> 720 bytes ch12/cardset-oxymoron/03c.gif | Bin 0 -> 801 bytes ch12/cardset-oxymoron/03d.gif | Bin 0 -> 660 bytes ch12/cardset-oxymoron/03h.gif | Bin 0 -> 753 bytes ch12/cardset-oxymoron/03s.gif | Bin 0 -> 791 bytes ch12/cardset-oxymoron/04c.gif | Bin 0 -> 871 bytes ch12/cardset-oxymoron/04d.gif | Bin 0 -> 711 bytes ch12/cardset-oxymoron/04h.gif | Bin 0 -> 833 bytes ch12/cardset-oxymoron/04s.gif | Bin 0 -> 868 bytes ch12/cardset-oxymoron/05c.gif | Bin 0 -> 939 bytes ch12/cardset-oxymoron/05d.gif | Bin 0 -> 745 bytes ch12/cardset-oxymoron/05h.gif | Bin 0 -> 894 bytes ch12/cardset-oxymoron/05s.gif | Bin 0 -> 946 bytes ch12/cardset-oxymoron/06c.gif | Bin 0 -> 1034 bytes ch12/cardset-oxymoron/06d.gif | Bin 0 -> 803 bytes ch12/cardset-oxymoron/06h.gif | Bin 0 -> 982 bytes ch12/cardset-oxymoron/06s.gif | Bin 0 -> 1048 bytes ch12/cardset-oxymoron/07c.gif | Bin 0 -> 1083 bytes ch12/cardset-oxymoron/07d.gif | Bin 0 -> 826 bytes ch12/cardset-oxymoron/07h.gif | Bin 0 -> 1029 bytes ch12/cardset-oxymoron/07s.gif | Bin 0 -> 1103 bytes ch12/cardset-oxymoron/08c.gif | Bin 0 -> 1213 bytes ch12/cardset-oxymoron/08d.gif | Bin 0 -> 899 bytes ch12/cardset-oxymoron/08h.gif | Bin 0 -> 1124 bytes ch12/cardset-oxymoron/08s.gif | Bin 0 -> 1240 bytes ch12/cardset-oxymoron/09c.gif | Bin 0 -> 1240 bytes ch12/cardset-oxymoron/09d.gif | Bin 0 -> 936 bytes ch12/cardset-oxymoron/09h.gif | Bin 0 -> 1190 bytes ch12/cardset-oxymoron/09s.gif | Bin 0 -> 1280 bytes ch12/cardset-oxymoron/10c.gif | Bin 0 -> 1391 bytes ch12/cardset-oxymoron/10d.gif | Bin 0 -> 1056 bytes ch12/cardset-oxymoron/10h.gif | Bin 0 -> 1349 bytes ch12/cardset-oxymoron/10s.gif | Bin 0 -> 1437 bytes ch12/cardset-oxymoron/11c.gif | Bin 0 -> 2991 bytes ch12/cardset-oxymoron/11d.gif | Bin 0 -> 3050 bytes ch12/cardset-oxymoron/11h.gif | Bin 0 -> 2842 bytes ch12/cardset-oxymoron/11s.gif | Bin 0 -> 2857 bytes ch12/cardset-oxymoron/12c.gif | Bin 0 -> 3045 bytes ch12/cardset-oxymoron/12d.gif | Bin 0 -> 2969 bytes ch12/cardset-oxymoron/12h.gif | Bin 0 -> 2864 bytes ch12/cardset-oxymoron/12s.gif | Bin 0 -> 2899 bytes ch12/cardset-oxymoron/13c.gif | Bin 0 -> 3098 bytes ch12/cardset-oxymoron/13d.gif | Bin 0 -> 2961 bytes ch12/cardset-oxymoron/13h.gif | Bin 0 -> 2743 bytes ch12/cardset-oxymoron/13s.gif | Bin 0 -> 3092 bytes ch12/cardset-oxymoron/COPYRIGHT | 10 ++ ch12/cardset-oxymoron/back001.gif | Bin 0 -> 8291 bytes ch12/cardset-oxymoron/back101.gif | Bin 0 -> 5148 bytes ch12/cardset-oxymoron/back102.gif | Bin 0 -> 5513 bytes ch12/cardset-oxymoron/back111.gif | Bin 0 -> 5233 bytes ch12/cardset-oxymoron/back191.gif | Bin 0 -> 2598 bytes ch12/cardset-oxymoron/back192.gif | Bin 0 -> 2598 bytes ch12/cardset-oxymoron/bottom01.gif | Bin 0 -> 333 bytes ch12/cardset-oxymoron/bottom02.gif | Bin 0 -> 1881 bytes ch12/cardset-oxymoron/bottom03.gif | Bin 0 -> 864 bytes ch12/cardset-oxymoron/bottom04.gif | Bin 0 -> 1817 bytes ch12/cardset-oxymoron/bottom05.gif | Bin 0 -> 1806 bytes ch12/cardset-oxymoron/bottom06.gif | Bin 0 -> 1808 bytes ch12/cardset-oxymoron/bottom07.gif | Bin 0 -> 1858 bytes ch12/cardset-oxymoron/config.txt | 6 + ch12/cardset-oxymoron/l01.gif | Bin 0 -> 1772 bytes ch12/cardset-oxymoron/l02.gif | Bin 0 -> 1805 bytes ch12/cardset-oxymoron/l03.gif | Bin 0 -> 1832 bytes ch12/cardset-oxymoron/l04.gif | Bin 0 -> 1832 bytes ch12/cardset-oxymoron/shade.gif | Bin 0 -> 9715 bytes ch12/cardset-oxymoron/shadow00.gif | Bin 0 -> 722 bytes ch12/cardset-oxymoron/shadow01.gif | Bin 0 -> 673 bytes ch12/cardset-oxymoron/shadow02.gif | Bin 0 -> 831 bytes ch12/cardset-oxymoron/shadow03.gif | Bin 0 -> 989 bytes ch12/cardset-oxymoron/shadow04.gif | Bin 0 -> 1148 bytes ch12/cardset-oxymoron/shadow05.gif | Bin 0 -> 1313 bytes ch12/cardset-oxymoron/shadow06.gif | Bin 0 -> 1488 bytes ch12/cardset-oxymoron/shadow07.gif | Bin 0 -> 1662 bytes ch12/cardset-oxymoron/shadow08.gif | Bin 0 -> 1835 bytes ch12/cardset-oxymoron/shadow09.gif | Bin 0 -> 2009 bytes ch12/cardset-oxymoron/shadow10.gif | Bin 0 -> 2184 bytes ch12/cardset-oxymoron/shadow11.gif | Bin 0 -> 2357 bytes ch12/cardset-oxymoron/shadow12.gif | Bin 0 -> 2531 bytes ch12/cardset-oxymoron/shadow13.gif | Bin 0 -> 2711 bytes 112 files changed, 1588 insertions(+) create mode 100644 ch01/Goodbye.java create mode 100644 ch01/Hello.java create mode 100644 ch02/Variables.java create mode 100644 ch03/Convert.java create mode 100644 ch03/Echo.java create mode 100644 ch03/GuessStarter.java create mode 100644 ch03/Input.java create mode 100644 ch03/ScannerBug.java create mode 100644 ch04/Methods.java create mode 100644 ch04/NewLine.java create mode 100644 ch04/PrintTime.java create mode 100644 ch04/PrintTwice.java create mode 100644 ch05/Conditional.java create mode 100644 ch06/Series.java create mode 100644 ch06/SeriesTest.java create mode 100644 ch06/ValueMethods.java create mode 100644 ch07/Tables.java create mode 100644 ch08/ArrayExamples.java create mode 100644 ch09/StringsThings.java create mode 100644 ch10/Max.java create mode 100644 ch10/PointRect.java create mode 100644 ch11/Time.java create mode 100644 ch11/TimeClient.java create mode 100644 ch12/Card.java create mode 100644 ch12/CardTable.java create mode 100644 ch12/Search.java create mode 100644 ch12/cardset-oxymoron/01c.gif create mode 100644 ch12/cardset-oxymoron/01d.gif create mode 100644 ch12/cardset-oxymoron/01h.gif create mode 100644 ch12/cardset-oxymoron/01s.gif create mode 100644 ch12/cardset-oxymoron/02c.gif create mode 100644 ch12/cardset-oxymoron/02d.gif create mode 100644 ch12/cardset-oxymoron/02h.gif create mode 100644 ch12/cardset-oxymoron/02s.gif create mode 100644 ch12/cardset-oxymoron/03c.gif create mode 100644 ch12/cardset-oxymoron/03d.gif create mode 100644 ch12/cardset-oxymoron/03h.gif create mode 100644 ch12/cardset-oxymoron/03s.gif create mode 100644 ch12/cardset-oxymoron/04c.gif create mode 100644 ch12/cardset-oxymoron/04d.gif create mode 100644 ch12/cardset-oxymoron/04h.gif create mode 100644 ch12/cardset-oxymoron/04s.gif create mode 100644 ch12/cardset-oxymoron/05c.gif create mode 100644 ch12/cardset-oxymoron/05d.gif create mode 100644 ch12/cardset-oxymoron/05h.gif create mode 100644 ch12/cardset-oxymoron/05s.gif create mode 100644 ch12/cardset-oxymoron/06c.gif create mode 100644 ch12/cardset-oxymoron/06d.gif create mode 100644 ch12/cardset-oxymoron/06h.gif create mode 100644 ch12/cardset-oxymoron/06s.gif create mode 100644 ch12/cardset-oxymoron/07c.gif create mode 100644 ch12/cardset-oxymoron/07d.gif create mode 100644 ch12/cardset-oxymoron/07h.gif create mode 100644 ch12/cardset-oxymoron/07s.gif create mode 100644 ch12/cardset-oxymoron/08c.gif create mode 100644 ch12/cardset-oxymoron/08d.gif create mode 100644 ch12/cardset-oxymoron/08h.gif create mode 100644 ch12/cardset-oxymoron/08s.gif create mode 100644 ch12/cardset-oxymoron/09c.gif create mode 100644 ch12/cardset-oxymoron/09d.gif create mode 100644 ch12/cardset-oxymoron/09h.gif create mode 100644 ch12/cardset-oxymoron/09s.gif create mode 100644 ch12/cardset-oxymoron/10c.gif create mode 100644 ch12/cardset-oxymoron/10d.gif create mode 100644 ch12/cardset-oxymoron/10h.gif create mode 100644 ch12/cardset-oxymoron/10s.gif create mode 100644 ch12/cardset-oxymoron/11c.gif create mode 100644 ch12/cardset-oxymoron/11d.gif create mode 100644 ch12/cardset-oxymoron/11h.gif create mode 100644 ch12/cardset-oxymoron/11s.gif create mode 100644 ch12/cardset-oxymoron/12c.gif create mode 100644 ch12/cardset-oxymoron/12d.gif create mode 100644 ch12/cardset-oxymoron/12h.gif create mode 100644 ch12/cardset-oxymoron/12s.gif create mode 100644 ch12/cardset-oxymoron/13c.gif create mode 100644 ch12/cardset-oxymoron/13d.gif create mode 100644 ch12/cardset-oxymoron/13h.gif create mode 100644 ch12/cardset-oxymoron/13s.gif create mode 100644 ch12/cardset-oxymoron/COPYRIGHT create mode 100644 ch12/cardset-oxymoron/back001.gif create mode 100644 ch12/cardset-oxymoron/back101.gif create mode 100644 ch12/cardset-oxymoron/back102.gif create mode 100644 ch12/cardset-oxymoron/back111.gif create mode 100644 ch12/cardset-oxymoron/back191.gif create mode 100644 ch12/cardset-oxymoron/back192.gif create mode 100644 ch12/cardset-oxymoron/bottom01.gif create mode 100644 ch12/cardset-oxymoron/bottom02.gif create mode 100644 ch12/cardset-oxymoron/bottom03.gif create mode 100644 ch12/cardset-oxymoron/bottom04.gif create mode 100644 ch12/cardset-oxymoron/bottom05.gif create mode 100644 ch12/cardset-oxymoron/bottom06.gif create mode 100644 ch12/cardset-oxymoron/bottom07.gif create mode 100644 ch12/cardset-oxymoron/config.txt create mode 100644 ch12/cardset-oxymoron/l01.gif create mode 100644 ch12/cardset-oxymoron/l02.gif create mode 100644 ch12/cardset-oxymoron/l03.gif create mode 100644 ch12/cardset-oxymoron/l04.gif create mode 100644 ch12/cardset-oxymoron/shade.gif create mode 100644 ch12/cardset-oxymoron/shadow00.gif create mode 100644 ch12/cardset-oxymoron/shadow01.gif create mode 100644 ch12/cardset-oxymoron/shadow02.gif create mode 100644 ch12/cardset-oxymoron/shadow03.gif create mode 100644 ch12/cardset-oxymoron/shadow04.gif create mode 100644 ch12/cardset-oxymoron/shadow05.gif create mode 100644 ch12/cardset-oxymoron/shadow06.gif create mode 100644 ch12/cardset-oxymoron/shadow07.gif create mode 100644 ch12/cardset-oxymoron/shadow08.gif create mode 100644 ch12/cardset-oxymoron/shadow09.gif create mode 100644 ch12/cardset-oxymoron/shadow10.gif create mode 100644 ch12/cardset-oxymoron/shadow11.gif create mode 100644 ch12/cardset-oxymoron/shadow12.gif create mode 100644 ch12/cardset-oxymoron/shadow13.gif diff --git a/ch01/Goodbye.java b/ch01/Goodbye.java new file mode 100644 index 0000000..0b165c3 --- /dev/null +++ b/ch01/Goodbye.java @@ -0,0 +1,13 @@ +/** + * Example program that demonstrates print vs println. + */ +public class Goodbye { + + /** + * Prints a greeting. + */ + public static void main(String[] args) { + System.out.print("Goodbye, "); // note the space + System.out.println("cruel world"); + } +} diff --git a/ch01/Hello.java b/ch01/Hello.java new file mode 100644 index 0000000..13dacf5 --- /dev/null +++ b/ch01/Hello.java @@ -0,0 +1,7 @@ +public class Hello { + + public static void main(String[] args) { + // generate some simple output + System.out.println("Hello, World!"); + } +} diff --git a/ch02/Variables.java b/ch02/Variables.java new file mode 100644 index 0000000..b4a99d6 --- /dev/null +++ b/ch02/Variables.java @@ -0,0 +1,84 @@ +/** + * Examples from Chapter 2. + */ +public class Variables { + + public static void main(String[] args) { + + String message; + + int x; + + String firstName; + String lastName; + int hour, minute; + + message = "Hello!"; // give message the value "Hello!" + hour = 10; // assign the value 10 to hour + minute = 59; // set minute to 59 + + message = "123"; // legal + // message = 123; not legal + + String message2 = "Hello!"; + int hour2 = 10; + int minute2 = 59; + + int a = 5; + int b = a; // a and b are now equal + a = 3; // a and b are no longer equal + + String firstLine = "Hello, again!"; + System.out.println(firstLine); + + System.out.print("The value of firstLine is "); + System.out.println(firstLine); + + System.out.print("The current time is "); + System.out.print(hour); + System.out.print(":"); + System.out.print(minute); + System.out.println("."); + + System.out.print("Number of minutes since midnight: "); + System.out.println(hour * 60 + minute); + + + System.out.print("Fraction of the hour that has passed: "); + System.out.println(minute / 60); + + System.out.print("Percent of the hour that has passed: "); + System.out.println(minute * 100 / 60); + + double pi; + pi = 3.14159; + + double minute3 = 59.0; + System.out.print("Fraction of the hour that has passed: "); + System.out.println(minute3 / 60.0); + + double y = 1.0 / 3.0; // correct + + System.out.println(0.1 * 10); + System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + + 0.1 + 0.1 + 0.1 + 0.1 + 0.1); + + double balance = 123.45; // potential rounding error + int balance2 = 12345; // total number of cents + + System.out.println(1 + 2 + "Hello"); + // the output is 3Hello + + System.out.println("Hello" + 1 + 2); + // the output is Hello12 + + System.out.println(17 * 3); + System.out.println(hour * 60 + minute); + + int percentage; + percentage = (minute * 100) / 60; + + hour = minute + 1; // correct + // minute + 1 = hour; syntax error + } +} diff --git a/ch03/Convert.java b/ch03/Convert.java new file mode 100644 index 0000000..5c93d3d --- /dev/null +++ b/ch03/Convert.java @@ -0,0 +1,25 @@ +import java.util.Scanner; + +/** + * Converts centimeters to feet and inches. + */ +public class Convert { + + public static void main(String[] args) { + double cm; + int feet, inches, remainder; + final double centPerInch = 2.54; + Scanner in = new Scanner(System.in); + + // prompt the user and get the value + System.out.print("Exactly how many cm? "); + cm = in.nextDouble(); + + // convert and output the result + inches = (int) (cm / centPerInch); + feet = inches / 12; + remainder = inches % 12; + System.out.printf("%.2f cm = %d ft, %d in\n", + cm, feet, remainder); + } +} diff --git a/ch03/Echo.java b/ch03/Echo.java new file mode 100644 index 0000000..b82b2d4 --- /dev/null +++ b/ch03/Echo.java @@ -0,0 +1,17 @@ +import java.util.Scanner; + +public class Echo { + + public static void main(String[] args) { + String line; + Scanner in = new Scanner(System.in); + + System.out.print("Type something: "); + line = in.nextLine(); + System.out.println("You said: " + line); + + System.out.print("Type something else: "); + line = in.nextLine(); + System.out.println("You also said: " + line); + } +} diff --git a/ch03/GuessStarter.java b/ch03/GuessStarter.java new file mode 100644 index 0000000..92d7f50 --- /dev/null +++ b/ch03/GuessStarter.java @@ -0,0 +1,14 @@ +import java.util.Random; + +/** + * Starter code for the "guess my number" exercise. + */ +public class GuessStarter { + + public static void main(String[] args) { + // pick a random number + Random random = new Random(); + int number = random.nextInt(100) + 1; + System.out.println(number); + } +} diff --git a/ch03/Input.java b/ch03/Input.java new file mode 100644 index 0000000..574290d --- /dev/null +++ b/ch03/Input.java @@ -0,0 +1,15 @@ +/** + * Examples from Chapter 3. + */ +public class Input { + + public static void main(String[] args) { + System.out.println(System.out); + + System.out.print(4.0 / 3.0); + System.out.printf("Four thirds = %.3f", 4.0 / 3.0); + + double pi = 3.14159; + double x = (int) pi * 20.0; + } +} diff --git a/ch03/ScannerBug.java b/ch03/ScannerBug.java new file mode 100644 index 0000000..7a2d079 --- /dev/null +++ b/ch03/ScannerBug.java @@ -0,0 +1,25 @@ +import java.util.Scanner; + +/** + * Demonstrates a common problem using Scanner. + */ +public class ScannerBug { + + public static void main(String[] args) { + String name; + int age; + Scanner in = new Scanner(System.in); + + System.out.print("What is your name? "); + name = in.nextLine(); + System.out.print("What is your age? "); + age = in.nextInt(); + System.out.printf("Hello %s, age %d\n", name, age); + + System.out.print("What is your age? "); + age = in.nextInt(); + System.out.print("What is your name? "); + name = in.nextLine(); + System.out.printf("Hello %s, age %d\n", name, age); + } +} diff --git a/ch04/Methods.java b/ch04/Methods.java new file mode 100644 index 0000000..c6fa25e --- /dev/null +++ b/ch04/Methods.java @@ -0,0 +1,20 @@ +/** + * Examples from Chapter 4. + */ +public class Methods { + + public static void main(String[] args) { + double root = Math.sqrt(17.0); + double angle = 1.5; + double height = Math.sin(angle); + + double degrees = 90; + double angle2 = degrees / 180.0 * Math.PI; + double radians = Math.toRadians(180.0); + double degrees2 = Math.toDegrees(Math.PI); + long x = Math.round(Math.PI * 20.0); + double x2 = Math.cos(angle + Math.PI / 2); + double x3 = Math.exp(Math.log(10.0)); + double x4 = Math.pow(2.0, 10.0); + } +} diff --git a/ch04/NewLine.java b/ch04/NewLine.java new file mode 100644 index 0000000..b13ddfc --- /dev/null +++ b/ch04/NewLine.java @@ -0,0 +1,18 @@ +public class NewLine { + + public static void newLine() { + System.out.println(); + } + + public static void threeLine() { + newLine(); + newLine(); + newLine(); + } + + public static void main(String[] args) { + System.out.println("First line."); + threeLine(); + System.out.println("Second line."); + } +} diff --git a/ch04/PrintTime.java b/ch04/PrintTime.java new file mode 100644 index 0000000..fe3549c --- /dev/null +++ b/ch04/PrintTime.java @@ -0,0 +1,14 @@ +public class PrintTime { + + public static void printTime(int hour, int minute) { + System.out.print(hour); + System.out.print(":"); + System.out.println(minute); + } + + public static void main(String[] args) { + int hour = 11; + int minute = 59; + printTime(hour, minute); + } +} diff --git a/ch04/PrintTwice.java b/ch04/PrintTwice.java new file mode 100644 index 0000000..c34ed1c --- /dev/null +++ b/ch04/PrintTwice.java @@ -0,0 +1,11 @@ +public class PrintTwice { + + public static void printTwice(String s) { + System.out.println(s); + System.out.println(s); + } + + public static void main(String[] args) { + printTwice("Don't make me say this twice!"); + } +} diff --git a/ch05/Conditional.java b/ch05/Conditional.java new file mode 100644 index 0000000..61b3485 --- /dev/null +++ b/ch05/Conditional.java @@ -0,0 +1,157 @@ +import java.util.Scanner; + +/** + * Examples from Chapter 5. + */ +public class Conditional { + + public static void main(String[] args) { + String fruit1 = "Apple"; + String fruit2 = "Orange"; + System.out.println(fruit1.equals(fruit2)); + + int x = 17; + int n = 18; + + if (x > 0) { + System.out.println("x is positive"); + } + + if (x % 2 == 0) { + System.out.println("x is even"); + } else { + System.out.println("x is odd"); + } + + if (x > 0) { + System.out.println("x is positive"); + } else if (x < 0) { + System.out.println("x is negative"); + } else { + System.out.println("x is zero"); + } + + if (x == 0) { + System.out.println("x is zero"); + } else { + if (x > 0) { + System.out.println("x is positive"); + } else { + System.out.println("x is negative"); + } + } + boolean evenFlag = (n % 2 == 0); // true if n is even + boolean positiveFlag = (x > 0); // true if x is positive + + if (evenFlag) { + System.out.println("n was even when I checked it"); + } + + if (!evenFlag) { + System.out.println("n was odd when I checked it"); + } + + System.out.println("printLogarithm"); + printLogarithm(3.0); + + System.out.println("countdown"); + countdown(3); + + System.out.println("countup"); + countup(3); + + System.out.println("newLine"); + newLine(); + + System.out.println("nLines"); + nLines(3); + + System.out.println("threeLine"); + threeLine(); + + System.out.println("displayBinary"); + displayBinary(23); + System.out.println(); + + System.out.println("scandouble"); + scanDouble(); + + System.out.println("scandouble2"); + scanDouble2(); + } + + public static void printLogarithm(double x) { + if (x <= 0.0) { + System.err.println("Error: x must be positive."); + return; + } + double result = Math.log(x); + System.out.println("The log of x is " + result); + } + + public static void scanDouble() { + Scanner in = new Scanner(System.in); + System.out.print("Enter a number: "); + double x = in.nextDouble(); + printLogarithm(x); + } + + public static void scanDouble2() { + Scanner in = new Scanner(System.in); + System.out.print("Enter a number: "); + if (!in.hasNextDouble()) { + String word = in.next(); + System.err.println(word + " is not a number"); + return; + } + double x = in.nextDouble(); + printLogarithm(x); + } + + public static void countdown(int n) { + if (n == 0) { + System.out.println("Blastoff!"); + } else { + System.out.println(n); + countdown(n - 1); + } + } + + public static void newLine() { + System.out.println(); + } + + public static void threeLine() { + newLine(); + newLine(); + newLine(); + } + + public static void nLines(int n) { + if (n > 0) { + System.out.println(); + nLines(n - 1); + } + } + + public static void forever(String s) { + System.out.println(s); + forever(s); + } + + public static void countup(int n) { + if (n == 0) { + System.out.println("Blastoff!"); + } else { + countup(n - 1); + System.out.println(n); + } + } + + public static void displayBinary(int value) { + if (value > 0) { + displayBinary(value / 2); + System.out.print(value % 2); + } + } +} diff --git a/ch06/Series.java b/ch06/Series.java new file mode 100644 index 0000000..c256828 --- /dev/null +++ b/ch06/Series.java @@ -0,0 +1,143 @@ +/** + * Examples from Chapter 6. + */ +public class Series { + + public static void countup(int n) { + if (n == 0) { + System.out.println("Blastoff!"); + } else { + countup(n - 1); + System.out.println(n); + } + } + + public static double area(double radius) { + double area = Math.PI * radius * radius; + return area; + } + + public static double area2(double radius) { + return Math.PI * radius * radius; + } + + public static double absoluteValue(double x) { + if (x < 0) { + return -x; + } else { + return x; + } + } + + public static double distance + (double x1, double y1, double x2, double y2) { + double dx = x2 - x1; + double dy = y2 - y1; + System.out.println("dx is " + dx); + System.out.println("dy is " + dy); + return 0.0; + } + + public static double distance2 + (double x1, double y1, double x2, double y2) { + double dx = x2 - x1; + double dy = y2 - y1; + double dsquared = dx * dx + dy * dy; + System.out.println("dsquared is " + dsquared); + return 0.0; + } + + public static double distance3 + (double x1, double y1, double x2, double y2) { + double dx = x2 - x1; + double dy = y2 - y1; + double dsquared = dx * dx + dy * dy; + double result = Math.sqrt(dsquared); + return result; + } + + public static double circleArea + (double xc, double yc, double xp, double yp) { + double radius = distance(xc, yc, xp, yp); + double area = area(radius); + return area; + } + + public static double area + (double xc, double yc, double xp, double yp) { + return area(distance(xc, yc, xp, yp)); + } + + public static boolean isSingleDigit(int x) { + if (x >= 0 && x < 10) { + return true; + } else { + return false; + } + } + + public static boolean isSingleDigit2(int x) { + return x >= 0 && x < 10; + } + + public static int factorial(int n) { + if (n == 0) { + return 1; + } + int recurse = factorial(n - 1); + int result = n * recurse; + return result; + } + + public static int fibonacci(int n) { + if (n == 1 || n == 2) { + return 1; + } + return fibonacci(n - 1) + fibonacci(n - 2); + } + + public static void main(String[] args) { + countup(3); + System.out.println("Have a nice day."); + + System.out.println("area"); + System.out.println(area(3.0)); + + System.out.println("area2"); + System.out.println(area2(3.0)); + + System.out.println("circleArea"); + System.out.println(circleArea(1.0, 2.0, 4.0, 6.0)); + + System.out.println("area with 4 doubles"); + System.out.println(area(1.0, 2.0, 4.0, 6.0)); + + System.out.println("absolute value"); + System.out.println(absoluteValue(-2)); + + System.out.println("distance"); + System.out.println(distance(1.0, 2.0, 4.0, 6.0)); + + System.out.println("distance2"); + System.out.println(distance2(1.0, 2.0, 4.0, 6.0)); + + System.out.println("distance3"); + System.out.println(distance3(1.0, 2.0, 4.0, 6.0)); + + System.out.println(isSingleDigit(2)); + boolean bigFlag = !isSingleDigit2(17); + + int i = 9; + if (isSingleDigit(i)) { + System.out.println("i is small"); + } else { + System.out.println("i is big"); + } + + System.out.println("factorial"); + System.out.println(factorial(3)); + + System.out.println("fibonacci"); + System.out.println(fibonacci(3)); + } +} diff --git a/ch06/SeriesTest.java b/ch06/SeriesTest.java new file mode 100644 index 0000000..7517c85 --- /dev/null +++ b/ch06/SeriesTest.java @@ -0,0 +1,10 @@ +import junit.framework.TestCase; + +public class SeriesTest extends TestCase { + + public void testFibonacci() { + assertEquals(1, Series.fibonacci(1)); + assertEquals(1, Series.fibonacci(2)); + assertEquals(2, Series.fibonacci(3)); + } +} diff --git a/ch06/ValueMethods.java b/ch06/ValueMethods.java new file mode 100644 index 0000000..3a54d1b --- /dev/null +++ b/ch06/ValueMethods.java @@ -0,0 +1,113 @@ +public class ValueMethods { + + public static void countup(int n) { + if (n == 0) { + System.out.println("Blastoff!"); + } else { + countup(n - 1); + System.out.println(n); + } + } + + public static double area(double radius) { + double area = Math.PI * radius * radius; + return area; + } + + public static double area2(double radius) { + return Math.PI * radius * radius; + } + + public static double absoluteValue(double x) { + if (x < 0) { + return -x; + } else { + return x; + } + } + + public static double distance + (double x1, double y1, double x2, double y2) { + double dx = x2 - x1; + double dy = y2 - y1; + System.out.println("dx is " + dx); + System.out.println("dy is " + dy); + return 0.0; + } + + public static double distance2 + (double x1, double y1, double x2, double y2) { + double dx = x2 - x1; + double dy = y2 - y1; + double dsquared = dx * dx + dy * dy; + System.out.println("dsquared is " + dsquared); + return 0.0; + } + + public static double distance3 + (double x1, double y1, double x2, double y2) { + double dx = x2 - x1; + double dy = y2 - y1; + double dsquared = dx * dx + dy * dy; + double result = Math.sqrt(dsquared); + return result; + } + + public static double circleArea + (double xc, double yc, double xp, double yp) { + double radius = distance(xc, yc, xp, yp); + double area = area(radius); + return area; + } + + public static double area + (double xc, double yc, double xp, double yp) { + return area(distance(xc, yc, xp, yp)); + } + + public static boolean isSingleDigit(int x) { + if (x >= 0 && x < 10) { + return true; + } else { + return false; + } + } + + public static boolean isSingleDigit2(int x) { + return x >= 0 && x < 10; + } + + public static int factorial(int n) { + if (n == 0) { + return 1; + } + int recurse = factorial(n - 1); + int result = n * recurse; + return result; + } + + public static int fibonacci(int n) { + if (n == 1 || n == 2) { + return 1; + } + return fibonacci(n - 1) + fibonacci(n - 2); + } + + public static void main(String[] args) { + countup(3); + System.out.println("Have a nice day."); + + double x = area(3.0); + double y = area(1.0, 2.0, 4.0, 6.0); + + System.out.println(isSingleDigit(2)); + boolean bigFlag = !isSingleDigit(17); + + int z = 17; + if (isSingleDigit(z)) { + System.out.println("z is small"); + } else { + System.out.println("z is big"); + } + } +} diff --git a/ch07/Tables.java b/ch07/Tables.java new file mode 100644 index 0000000..692ca39 --- /dev/null +++ b/ch07/Tables.java @@ -0,0 +1,181 @@ +/** + * Examples from Chapter 7. + */ +public class Tables { + + public static void countdown(int n) { + while (n > 0) { + System.out.println(n); + n = n - 1; + } + System.out.println("Blastoff!"); + } + + public static void sequence(int n) { + while (n != 1) { + System.out.println(n); + if (n % 2 == 0) { // n is even + n = n / 2; + } else { // n is odd + n = n * 3 + 1; + } + } + } + + public static void example() { + int i = 1; + while (i < 10) { + double x = (double) i; + System.out.println(x + " " + Math.log(x)); + i = i + 1; + } + } + + public static void example2() { + int i = 1; + while (i < 10) { + double x = (double) i; + System.out.println(x + " " + Math.log(x) / Math.log(2)); + i = i + 1; + } + } + + public static void example3() { + final double log2 = Math.log(2); + int i = 1; + while (i < 100) { + double x = (double) i; + System.out.println(x + " " + Math.log(x) / log2); + i = i * 2; + } + } + + public static void example4() { + int i = 1; + while (i <= 6) { + System.out.printf("%4d", 2 * i); + i = i + 1; + } + System.out.println(); + } + + public static void printRow() { + int i = 1; + while (i <= 6) { + System.out.printf("%4d", 2 * i); + i = i + 1; + } + System.out.println(); + } + + public static void printRow2(int n) { + int i = 1; + while (i <= 6) { + System.out.printf("%4d", n * i); + i = i + 1; + } + System.out.println(); + } + + public static void example5() { + int i = 1; + while (i <= 6) { + printRow2(i); + i = i + 1; + } + } + + public static void printTable() { + int i = 1; + while (i <= 6) { + printRow2(i); + i = i + 1; + } + } + + public static void printTable2(int rows) { + int i = 1; + while (i <= rows) { + printRow2(i); + i = i + 1; + } + } + + public static void printRow3(int n, int cols) { + int i = 1; + while (i <= cols) { + System.out.printf("%4d", n * i); + i = i + 1; + } + System.out.println(); + } + + public static void printTable3(int rows) { + int i = 1; + while (i <= rows) { + printRow3(i, rows); + i = i + 1; + } + } + + public static void printTable4(int rows) { + for (int i = 1; i <= rows; i = i + 1) { + printRow3(i, rows); + } + } + + public static void printRow4(int n, int cols) { + int i; + for (i = 1; i <= cols; i = i + 1) { + System.out.printf("%4d", n * i); + } + System.out.println(i); + } + + public static void main(String[] args) { + System.out.println("countdown"); + countdown(3); + + System.out.println("sequence"); + sequence(10); + + System.out.println("example"); + example(); + + System.out.println("example2"); + example2(); + + System.out.println("example3"); + example3(); + + System.out.println("example4"); + example4(); + + System.out.println("example5"); + example5(); + + System.out.println("printRow"); + printRow(); + + System.out.println("printRow2"); + printRow2(6); + + System.out.println("printTable"); + printTable(); + + System.out.println("printTable2"); + printTable2(6); + + System.out.println("printRow3"); + printRow3(6, 6); + + System.out.println("printTable3"); + printTable3(6); + + System.out.println("printRow4"); + printRow4(6, 6); + + System.out.println("printTable4"); + printTable4(6); + } +} diff --git a/ch08/ArrayExamples.java b/ch08/ArrayExamples.java new file mode 100644 index 0000000..dfc8d1e --- /dev/null +++ b/ch08/ArrayExamples.java @@ -0,0 +1,156 @@ +import java.util.Arrays; +import java.util.Random; + +/** + * Demonstrates uses of arrays. + */ +public class ArrayExamples { + + /** + * Example code from Chapter 8. + */ + public static void main(String[] args) { + int size = 10; + int[] counts = new int[4]; + double[] values = new double[size]; + + counts[0] = 7; + counts[1] = counts[0] * 2; + counts[2]++; + counts[3] -= 60; + + // traversal with a while loop + int j = 0; + while (j < 4) { + System.out.println(counts[j]); + j++; + } + + // traversal with a for loop + for (int i = 0; i < 4; i++) { + System.out.println(counts[i]); + } + + int[] array = {1, 2, 3, 4}; + printArray(array); + + // printing an array as an object + System.out.println(array); + + // printing with Arrays class + System.out.println(Arrays.toString(array)); + + // copying an array + double[] a = {1.0, 2.0, 3.0}; + double[] b = new double[a.length]; + for (int i = 0; i < a.length; i++) { + b[i] = a[i]; + } + + // copying with Arrays class + double[] c = Arrays.copyOf(a, a.length); + + // traversal + for (int i = 0; i < a.length; i++) { + a[i] = Math.pow(a[i], 2.0); + } + + // search + int index = search(a, 2.0); + System.out.println("index = " + index); + + // reduce + double total = sum(a); + System.out.println("total = " + total); + + makeHistogram(); + } + + /** + * Example code related to histograms. + */ + public static void makeHistogram() { + int numValues = 8; + int[] array = randomArray(numValues); + printArray(array); + + int[] scores = randomArray(30); + int a = inRange(scores, 90, 100); + int b = inRange(scores, 80, 90); + int c = inRange(scores, 70, 80); + int d = inRange(scores, 60, 70); + int f = inRange(scores, 0, 60); + + // making a histogram + int[] counts = new int[100]; + for (int i = 0; i < scores.length; i++) { + int index = scores[i]; + counts[index]++; + } + + // histogram with enhanced for loop + counts = new int[100]; + for (int score : scores) { + counts[score]++; + } + } + + /** + * Prints the elements of an array. + */ + public static void printArray(int[] array) { + System.out.print("{" + array[0]); + for (int i = 1; i < array.length; i++) { + System.out.print(", " + array[i]); + } + System.out.println("}"); + } + + /** + * Returns the index of the target in the array, or -1 if not found. + */ + public static int search(double[] a, double target) { + for (int i = 0; i < a.length; i++) { + if (a[i] == target) { + return i; + } + } + return -1; + } + + /** + * Returns the total of the elements in an array. + */ + public static double sum(double[] a) { + double total = 0.0; + for (int i = 0; i < a.length; i++) { + total += a[i]; + } + return total; + } + + /** + * Returns an array of random integers. + */ + public static int[] randomArray(int size) { + Random random = new Random(); + int[] a = new int[size]; + for (int i = 0; i < a.length; i++) { + a[i] = random.nextInt(100); + } + return a; + } + + /** + * Computes the number of array elements in [low, high). + */ + public static int inRange(int[] a, int low, int high) { + int count = 0; + for (int i = 0; i < a.length; i++) { + if (a[i] >= low && a[i] < high) { + count++; + } + } + return count; + } +} diff --git a/ch09/StringsThings.java b/ch09/StringsThings.java new file mode 100644 index 0000000..bdec09c --- /dev/null +++ b/ch09/StringsThings.java @@ -0,0 +1,55 @@ +/** + * Demonstates uses of Strings. + */ +public class StringsThings { + + /** + * Reverses a string, returns a new String. + */ + public static String reverse(String s) { + String r = ""; + for (int i = s.length() - 1; i >= 0; i--) { + r = r + s.charAt(i); + } + return r; + } + + public static void main(String[] args) { + + System.out.print("Roman alphabet: "); + for (char c = 'A'; c <= 'Z'; c++) { + System.out.print(c); + } + System.out.println(); + + System.out.print("Greek alphabet: "); + for (int i = 913; i <= 937; i++) { + System.out.print((char) i); + } + System.out.println(); + + String fruit = "banana"; + + for (int i = 0; i < fruit.length(); i++) { + char letter = fruit.charAt(i); + System.out.println(letter); + } + + String name1 = "Alan Turing"; + String name2 = "Ada Lovelace"; + if (name1.equals(name2)) { + System.out.println("The names are the same."); + } + + int diff = name1.compareTo(name2); + if (diff == 0) { + System.out.println("The names are the same."); + } else if (diff < 0) { + System.out.println("name1 comes before name2."); + } else if (diff > 0) { + System.out.println("name2 comes before name1."); + } + + System.out.println(reverse(name1)); + } +} diff --git a/ch10/Max.java b/ch10/Max.java new file mode 100644 index 0000000..a7ecea5 --- /dev/null +++ b/ch10/Max.java @@ -0,0 +1,23 @@ +import java.util.Arrays; + +/** + * Demonstrates command-line arguments. + */ +public class Max { + + /** + * Converts the command line arguments to integers and prints the max. + */ + public static void main(String[] args) { + System.out.println(Arrays.toString(args)); + + int max = Integer.MIN_VALUE; + for (String arg : args) { + int value = Integer.parseInt(arg); + if (value > max) { + max = value; + } + } + System.out.println("The max is " + max); + } +} diff --git a/ch10/PointRect.java b/ch10/PointRect.java new file mode 100644 index 0000000..d0da1df --- /dev/null +++ b/ch10/PointRect.java @@ -0,0 +1,61 @@ +import java.awt.Point; +import java.awt.Rectangle; + +/** + * Demonstates use of Point and Rectangle classes. + */ +public class PointRect { + + /** + * Prints the attributes of a Point object. + */ + public static void printPoint(Point p) { + System.out.println("(" + p.x + ", " + p.y + ")"); + } + + /** + * Computes the distance between two points. + */ + public static double distance(Point p1, Point p2) { + double dx = (double) (p2.x - p1.x); + double dy = (double) (p2.y - p1.y); + return Math.sqrt(dx * dx + dy * dy); + } + + /** + * Finds the center of a Rectangle and returns a new Point. + */ + public static Point findCenter(Rectangle box) { + int x = box.x + box.width / 2; + int y = box.y + box.height / 2; + return new Point(x, y); + } + + /** + * Moves a Rectangle by modifying the x and y attributes. + */ + public static void moveRect(Rectangle box, int dx, int dy) { + box.x = box.x + dx; + box.y = box.y + dy; + } + + /** + * Tests the methods in this class. + */ + public static void main(String[] args) { + Point blank; + blank = new Point(3, 4); + System.out.println(blank); + + Rectangle box = new Rectangle(0, 0, 100, 200); + moveRect(box, 50, 100); + System.out.println(box); + + Rectangle box1 = new Rectangle(0, 0, 100, 200); + Rectangle box2 = box1; + + System.out.println(box2.width); + box1.grow(50, 50); + System.out.println(box2.width); + } +} diff --git a/ch11/Time.java b/ch11/Time.java new file mode 100644 index 0000000..99e75db --- /dev/null +++ b/ch11/Time.java @@ -0,0 +1,118 @@ +/** + * 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; + } + + /** + * 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) { + return this.hour == that.hour + && this.minute == that.minute + && this.second == that.second; + } + + /** + * 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; + } + return sum; + } + + /** + * Adds the given number of seconds to this object (modifier). + */ + public void increment(double seconds) { + this.second += seconds; + while (this.second >= 60.0) { + this.second -= 60.0; + this.minute += 1; + } + while (this.minute >= 60) { + this.minute -= 60; + this.hour += 1; + } + } + + /** + * Test the methods in this class. + */ + public static void main(String[] args) { + Time time = new Time(11, 59, 59.9); + System.out.println(time); + + 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)); + } +} diff --git a/ch11/TimeClient.java b/ch11/TimeClient.java new file mode 100644 index 0000000..59ef451 --- /dev/null +++ b/ch11/TimeClient.java @@ -0,0 +1,14 @@ +/** + * Class that uses Time objects. + */ +public class TimeClient { + + /** + * Demonstrates that we cannot access private variables from another + * class. + */ + public static void main(String[] args) { + Time time = new Time(11, 59, 59.9); + System.out.println(time.hour); // ERROR + } +} diff --git a/ch12/Card.java b/ch12/Card.java new file mode 100644 index 0000000..7bd1202 --- /dev/null +++ b/ch12/Card.java @@ -0,0 +1,82 @@ +/** + * A standard playing card. + */ +public class Card { + + public static final String[] RANKS = { + null, "Ace", "2", "3", "4", "5", "6", "7", + "8", "9", "10", "Jack", "Queen", "King"}; + + public static final String[] SUITS = { + "Clubs", "Diamonds", "Hearts", "Spades"}; + + private final int rank; + + private final int suit; + + /** + * Constructs a card of the given rank and suit. + */ + public Card(int rank, int suit) { + this.rank = rank; + this.suit = suit; + } + + /** + * Returns a negative integer if this card comes before + * the given card, zero if the two cards are equal, or + * a positive integer if this card comes after the card. + */ + public int compareTo(Card that) { + if (this.suit < that.suit) { + return -1; + } + if (this.suit > that.suit) { + return 1; + } + if (this.rank < that.rank) { + return -1; + } + if (this.rank > that.rank) { + return 1; + } + return 0; + } + + /** + * Returns true if the given card has the same + * rank AND same suit; otherwise returns false. + */ + public boolean equals(Card that) { + return this.rank == that.rank + && this.suit == that.suit; + } + + /** + * Gets the card's rank. + */ + public int getRank() { + return this.rank; + } + + /** + * Gets the card's suit. + */ + public int getSuit() { + return this.suit; + } + + /** + * Returns the card's index in a sorted deck of 52 cards. + */ + public int position() { + return this.suit * 13 + this.rank - 1; + } + + /** + * Returns a string representation of the card. + */ + public String toString() { + return RANKS[this.rank] + " of " + SUITS[this.suit]; + } +} diff --git a/ch12/CardTable.java b/ch12/CardTable.java new file mode 100644 index 0000000..5b2b8ca --- /dev/null +++ b/ch12/CardTable.java @@ -0,0 +1,94 @@ +import java.awt.Canvas; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Image; + +import javax.swing.ImageIcon; +import javax.swing.JFrame; + +public class CardTable extends Canvas { + private Image[][] images; + private int cardWidth, cardHeight; + + // this long is here to suppress a warning; you can read about it at + // http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html + static final long serialVersionUID = 1; + + /** + * Creates a CardTable. + * cardset is the name of the folder that contains the card images. + */ + public CardTable(String cardset) { + setBackground(new Color(0x088A4B)); + + // create a 2-D array of card images + images = new Image[14][4]; + String suits = "cdhs"; + + for (int suit = 0; suit <= 3; suit++) { + char c = suits.charAt(suit); + + for (int rank = 1; rank <= 13; rank++) { + String s = String.format("%s/%02d%c.gif", cardset, rank, c); + images[rank][suit] = new ImageIcon(s).getImage(); + } + } + + // get the width and height of the cards and set the size of + // the frame accordingly + cardWidth = images[1][1].getWidth(null); + cardHeight = images[1][1].getHeight(null); + + // set the size temporarily to get the insets + setTableSize(14, 4); + } + + /** + * Sets the table size. + * x and y are in units of card width/height. + */ + public void setTableSize(double x, double y) { + setSize((int) (x * cardWidth), + (int) (y * cardHeight)); + } + + /** + * Draws a card at the given coordinates. + * x and y are in units of card width/height. + */ + public void drawCard(Graphics g, int rank, int suit, double x, double y) { + Image image = images[rank][suit]; + g.drawImage(image, + (int) (x * cardWidth), + (int) (y * cardHeight), + null); + } + + /** + * Special method invoked when the Frame needs to be drawn. + */ + public void paint(Graphics g) { + for (int rank = 1; rank <= 13; rank++) { + for (int suit = 0; suit <= 3; suit++) { + double x = rank - 1 + suit / 5.0; + double y = suit / 2.0; + drawCard(g, rank, suit, x, y); + } + } + } + + public static void main(String[] args) { + // make the frame + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + // add the CardTable + String cardset = "cardset-oxymoron"; + Canvas canvas = new CardTable(cardset); + frame.getContentPane().add(canvas); + + // show the frame + frame.pack(); + frame.setVisible(true); + } +} diff --git a/ch12/Search.java b/ch12/Search.java new file mode 100644 index 0000000..520a838 --- /dev/null +++ b/ch12/Search.java @@ -0,0 +1,102 @@ +/** + * Search algorithms for arrays of cards. + */ +public class Search { + + /** + * Sequential search. + */ + public static int search(Card[] cards, Card target) { + for (int i = 0; i < cards.length; i++) { + if (cards[i].equals(target)) { + return i; + } + } + return -1; + } + + /** + * Binary search (iterative version). + */ + public static int binarySearch(Card[] cards, Card target) { + int low = 0; + int high = cards.length - 1; + while (low <= high) { + System.out.println(low + ", " + high); + + int mid = (low + high) / 2; // step 1 + int comp = cards[mid].compareTo(target); + + if (comp == 0) { // step 2 + return mid; + } else if (comp < 0) { // step 3 + low = mid + 1; + } else { // step 4 + high = mid - 1; + } + } + return -1; + } + + /** + * Binary search (recursive version). + */ + public static int binarySearchRec(Card[] cards, Card target, + int low, int high) { + System.out.println(low + ", " + high); + + if (high < low) { + return -1; + } + int mid = (low + high) / 2; // step 1 + int comp = cards[mid].compareTo(target); + + if (comp == 0) { // step 2 + return mid; + } else if (comp < 0) { // step 3 + return binarySearchRec(cards, target, mid + 1, high); + } else { // step 4 + return binarySearchRec(cards, target, low, mid - 1); + } + } + + /** + * Make an array of 52 cards. + */ + public static Card[] makeDeck() { + Card[] cards = new Card[52]; + int index = 0; + for (int suit = 0; suit <= 3; suit++) { + for (int rank = 1; rank <= 13; rank++) { + cards[index] = new Card(rank, suit); + index++; + } + } + return cards; + } + + /** + * Demonstrates how to call the search methods. + */ + public static void main(String[] args) { + Card[] cards = makeDeck(); + Card jack = new Card(11, 0); + Card fake = new Card(15, 1); + + System.out.println("Sequential search"); + System.out.println(search(cards, jack)); + System.out.println(); + + System.out.println("Binary search"); + System.out.println(binarySearch(cards, jack)); + System.out.println(); + + System.out.println("Failed binary search"); + System.out.println(binarySearch(cards, fake)); + System.out.println(); + + System.out.println("Recursive binary search"); + System.out.println(binarySearch(cards, jack)); + System.out.println(); + } +} diff --git a/ch12/cardset-oxymoron/01c.gif b/ch12/cardset-oxymoron/01c.gif new file mode 100644 index 0000000000000000000000000000000000000000..cbc57d5a7fd0213c356f03e3fd4e8c356399d9c9 GIT binary patch literal 670 zcmXAlZ%9*77{=dw?rC1fyW1?JJDYM1g_#zIoS<{Xji8c50;Mkn-kGA(NSPxv{BYdG zksuXPU=THf#De~Ow-0C52aEm~NDPWtRN#k75rZPwI-BRi!}Gq+`8^!YiMHd-Es-{e zz$O$A2hO<=BA?H1FQiuI_M9H;9EzGFL(#!_WH8oeo{z+ONBZJW{g)~L3N#ch7ivJw z8_K5~d)0QKQ@Q?TF>eR1)|61|!Q<#Db~pQWYkAyyv`)X4f-;op8LfEHJN3Q{G?<9F zd*VP6VEv34eub;v(M9a|*4`JTWy;x?85W)%n>p%b)K8FHK895H>yu%e9>Hr-oax6( zl>kw1wqhmmkUJr)+lHKH4J<{^$`-^_LwwMzYiu}78tdc#S z>t&xu{a%Ydns7acn~nJUApSXk{~9oNhG`24CA|yv89Oyho#Z~_sc*%Gy{>*&*ceXc z)3>yKK5w9Q#?meAc8c%5QS zQc`OI?g5Z6GnZ9t}!!UCkh+g3$}b1P&7sAi=$)3ku{N;<1P|n z1KW6r6`Pk(3uUtfoETcx1e3@4=kt^WZRwY)X} literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/01d.gif b/ch12/cardset-oxymoron/01d.gif new file mode 100644 index 0000000000000000000000000000000000000000..111e36dc18b67f47d559d08422b9e8af9f72d253 GIT binary patch literal 590 zcmZ?wbhEHb^khh6_{0DP4Gaek9Qe<`@c%!MfC9yT;sKSx`8f*3`8k;-iJ3*I3dxB@ zDaENJ42nNl7#SEC8FWBOLB=pJ|CeCA^UvUvXLc~-gtNQYm;OXT|nR@8P}FyhmG-g~@|S28ipNd028~ayxB!CY19`&gYqy!80?SN1l0(4UZfX zGt)vV9$BUwrWGbUGE5~*>-Bh~OLDjAfH`|~z*2{GzzR?405x6I;kjnTbJLXPjtS3w zW1dHPJWq9bUg+?=*5-Mq#q&{>=Zgx@cV(VmN<4oRC4NXgXg?@xRxYte@POL^X|@cO z3xW-82gMn8v2px3bl`{gF|#;{ke?pQxtR4;CRQYVaCLBFjF(s-=-|#E#g@;qLGVKx zSU<=hMh5|&zPf}3SD2fZ$x1jpJ&^EzLR$J{(|p(7=z-{%GsN3vCR| z6-*O29w;z$GBEMHQ2f}C0@TiA#C7AqgE%*kff5H28$jmp3OG0%09x^dQ^Fyk0m%5Z l@gvN328##G%neL-1}C@_7#dbG7(~qQ-(OeD%E`cB4FEMI$^rlY literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/01h.gif b/ch12/cardset-oxymoron/01h.gif new file mode 100644 index 0000000000000000000000000000000000000000..20810e15062b78793efb55187eaea0d96870e8cf GIT binary patch literal 630 zcmXX;T}TvB6uxusG|t%3*2o%ht?`daN1Zb9r=StZcJW0}LZNK76q0sX&?T)Fn_3ID zRD_@q0!^Z{C_>5yTjFLtY>Bq?AVLu<6-k)o7NH=!-L<~MIeeV&=diuHtlVKo4irJ_ zFcGCRhEOcV&VOV^x7D7lb32uGx3ksbXl-jzPCD9}+gm&+bCu^1;*c7*#%mCX$=rvi z_Qrm?j_aR(7BhDB=p$#1HW;4y9rRW`{K0>c2v18ZKXHy1u;&C0s9>FVsX_*mgDPxi_O~kRAhRmG zuYivwFuxBz7sJ;=_*MYlRrr|?zw+QuF0AIjS~f)eM)(lg%vpIQC49Lum2>eHOQ>2; z73%p=mR=J>jCuTbCe5q1WA$=vx&2xq$-@m}DLQix*zRj1S^8Zw4+3J@Zo1J|ggw&A zBouyi^qm2CRucynv6)YZkUYlW6M+@GC2iz eQq)Mi>|ig|n-GuaQDhh|y0;u@xQ!)*_WuRrywKzT literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/01s.gif b/ch12/cardset-oxymoron/01s.gif new file mode 100644 index 0000000000000000000000000000000000000000..548ee0ae3e0dc40d7ad10626920d9be1981490ad GIT binary patch literal 956 zcmX9*UuYaf82@Hw?{=EbUG_|xTg+YED-nxE9rT2n+`|Mz?b#rQ30f7)ZQ7(37bCf& zUPB*dFHJ>KYAt>0i_xc=q6YOLBro5Bij^u?C{iI0hgR?pVig}MNYB~JJbd$;@B95> zW}YtZ-}j_n1|R;0?$V&OM#N61v)wSYa5q~yIXM@2wYlJU-9J7*;~nwmkJe`DQ25s( z00f3(a%=;vKkWcAcXPUN z?-xhkzMcUN;e5|@9cUBOAM8MFy=@rM+IGYN?7S! zdZ{GN*2Fu3xNuC|2a~WMc2l5b2COFXG)2eFsU~u?mzG$H1!9n8*r@3nL^E`>cY7Z( z^J9huMhA4na1M8UN``Y-UcS0DHc)7=9U{Xx1Hla7BTw3+agV#}AevpHP-BPdiz$wHl zMX7!lV(T}`Hcqs`PCKYR$#L`a-7;%QHEfFp8n4o32pPUc*!QnH#1{2~8sH7%m6P5h v1h_KCI^qTe1z?hJ!z#83`>&@PhmVptE~0VqzyWaH1W2}Kw%(;X07m}@;hqE` literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/02c.gif b/ch12/cardset-oxymoron/02c.gif new file mode 100644 index 0000000000000000000000000000000000000000..121edd0cc64bfe9b7cbbc807da5708c2ef81fc03 GIT binary patch literal 737 zcmX|9Uq}=|9RAJDIk(BIcT(zRo~)H6A;&0kS{}Cda(bM>ff|YyyVM!hrH5MBQ){dA zPfCIwDw2JPP7U#;hC<3X6ptm53upac9Rd61D-|x@&eZPU3=2*1hxETWz ze!=#!z_KjPc`ldRX^2>{Rg$>YHjvVW22y>)X5U~^J7*4_A4(2G#Xk=MKv3>@U9y~* zQqv@0CMq@S7@bjHEIKQe7Xuw(PCgFeQtAgi$1Q?iv&@=PfJ0KLY%J;fN=R^) z-HMH))g!dO)^vW$_Ec1b%>^UlBhdlYa?wU>rF80zp}owrXR1}>%z`nSPtL}f9KV4+ z7t;543@7BVUui1e#F=&UAIw?$e_PjFZS5J?_f&$u1A z-qY&eNd%cW3jh-F8;M@AD_TBm@Lu6_w>g|e_`;s71p$`+2oh*qWc(AMtu26yYxUEf zGPV7-j)f=9>PAQWzoW1$t4I#i|FVfRJa?-ybVglK_qX0g)ZX6951J literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/02d.gif b/ch12/cardset-oxymoron/02d.gif new file mode 100644 index 0000000000000000000000000000000000000000..a014c918980edcb4125ea3ad64cf7cde819b3714 GIT binary patch literal 630 zcmYL?Ur1AN6vxl~-8nZoP7BeA%YIV{`|Hg~EoE}oA9F}545fO|-%PhexrR=xp03_y zDr1TuM4_!W^Pye`z5JFzA|_IAB6LNP(L)bC*^BG$5_BHUIegCd`#rYeJPVM`8tq@XkIOor1V@JH*vRl;G&DFmKp%ug`^N^N;QnI~00g*@ljdST%sPd= zV`(!m6ciS|e8{reL`}X$e*12?OjcvHV=;Ql0 z;`5BAp8C)jM=!6&6O4Lam%Gw3FHgP41mh?0S2wzRF|`9-G2e7M#wT!I!NmwJh4Hlb zq7^HNNS0+hMSP?~RMAD|NWeFN6>~AaffN(?4Hz*cev%SN*fjZfV!cL$e|N42d-pxP z7$!T$DPn3B(>q}VsUlpaDd2}>~k~?;7I^dLVeq?>c*3wC7V@AsgpDVC=m(j0z z+TulLvOmp!6j(2HNi+ARggYluNw8$lqOG`{ke6ned~1tOYTca_f(~3!7+nHw4WSS| z>Fx7PxM$0_d7u08M`ZH)hDD literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/02h.gif b/ch12/cardset-oxymoron/02h.gif new file mode 100644 index 0000000000000000000000000000000000000000..f7b84de5f0f1013f581bc7c59fbfbb9cc94b1e88 GIT binary patch literal 698 zcmXX^QAkr!7(VCR>z#{ZY(Cf>yXsx~5R`gr;g&U-t;}JVAa-Mko|VqTsY8WQBCc+k zsZ0@!h@_EEzSv7JA&E2HgM^l(52Z!}dkIn`BI?C;uJj-N|NP&7zVCw{&J}N^^PJxc z{NN`z3=L39(*UH?to#q#!Li!Dx~`zy(-my%^|y7m$hZC7%{?u>!1kAi06=g`r|LF< zON(&(KzZkFuY(h-Z_?yMw9vr2XXk>|%CxdF*#6bFWb7$PxuvjuXJv3Xr{HXLSv8&@ z@;#qtY@EpR{VvR|KhGRvQ6f8ESfqrTTIOHjD4}M&cO6Tvh;|K25!X-+9=nUjJMm;I zo(ft5`~wt|wKT ztE)ESD$Zj*PPF499VP-+e?0X2kCvi==KlafWe&QABr9~1j38e$d^5Zc4V8stMiM){!epw{SEeZ1d zh)`3n4EqLQeKwwpl2|<-p0kNsMuPk>2mzN;wKV{59>pLFBvVlhqCF*45PJk1_)y;b&)$EHCEUf8gjnyEoh`CyLbp#bKI4WBRU3~70&OqpNo*RpO& zV#Dn2MYfMsY%qsLX%Q@b-9b{9ferG!DVun<1fhvvG0_T&p@Xfu=AnY1W?+-s%?u@R z;R_|@Q21^6)Eb%+4MMYOUV@yOB?AMON%f8nfWwX$6%FJnYf}uSAm`Izz7or_Mgc=7*{xnS8fAAawjb`*vjPnG zQ8n{nCvJp(mXBSyUP!$xk9bJ6P@^mldvJibh_%D~LT?p)K*Yv=l0}+#OajD9BFsme z#J>+BEKD{?n1%5M-o6UHs~ocWZCm5ti&!~ZP63Rr^IqXrtLyNuNi9=A3}Z#3K+sCUm4GF zo7{;!G-`y}cmf4zt$TL&&@DxjB&nBzJ66kyXx>6=wK@@oBVN#LS-N4NO+?}yTpysC zt&+$wj{XBuxkNw(nZ+_d#-IsyzX$-wxqTLkN0eD#I_=|dMx@|iu{U}e(i3T|Dm~j* Zq!Td#gFpeA!B~IyFmmPG0Nw*o`41+L!BzkO literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/03c.gif b/ch12/cardset-oxymoron/03c.gif new file mode 100644 index 0000000000000000000000000000000000000000..fdc44b26a46f738aa9e133297b185f2ffc64ee98 GIT binary patch literal 801 zcmXw%Uq}>D6voe;JI-!;$JI7%(%o$=$*_#OwUXu%gOp}zEVyqgF;huOOD^sf=F`;` z>Ln9<=^wGAgc1~lFXhXu7H*j`j}kpBQ9h`Y1QETs-C1j3&i$P^-**q3Gp%hc4UI+{ z81NJF4+F-SX_~oQZuJnn=pF&yVXlZ|K)gh0;>Lq2mrxhTWntg zIH#b`Tl7QQ)lM|FG@H{8j#fKFZTdy@9PRqL9LU7RLO<%~(eNEG54}iR z?8SsAqwDKN!Z-XS<`uKt77n70cM%7n5%JRiXq-W5gr41pD*~vTz!^aEwH- z%vr_}62|3#!z4UG!o-UO5O81`IP!8}hM%qgHvoTauE%m-VjD$HJmrR<9IGUv;1-&= zX_bg&s~!3DS9@OMR6u6{g0y*T&P;MBKW|uumP9)r&`i&04z)IrlMfAbyeK&yQBsq0 z`nO%ukw^6Q`w`T!pIj?9QuiDuS<2j~7&nyu2kawkUSDLAP~q&MdJ(S0 zEplp(71q^~DeLJ!AOjRkZl9tnM^kCO1d-U{;F~dgvv(iv-|JZLz3C_gMB^76oFNP#?4qAMvIMV240HwVIP4JMDti zJP!h>CU~h5dG3Jc&Op^=Ylh%V{Fa31eJB0edL4ia~0n zfs-w^3(RDVI6$>h!EQObgWtz{cn~<{`O z2;U$Z25`>P0O_<@{zcLHHtj-Pdz;$T-qsQdwsbbDjls^QuI3OF{gMO#0ZKDy#shT&#FnQ%zEom5h`%jkn# zd>5JLrlFghx28BtqT77z3pWN#CT3MsE{4m^lTl{M|NaAbl;U)1X!Vkyj51}!*5QXd z!6Sv(tPeH|UTGzdcMFB)#ubeplr3^XcSmhK!XrUz>Sg>ST+2OxQzaZphuo$Q+o|4uu`z#gA%XHLHYX<2hCF~AOXJ&jK%v)pCoUS9Du4nCA`mR literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/03h.gif b/ch12/cardset-oxymoron/03h.gif new file mode 100644 index 0000000000000000000000000000000000000000..5a9daa2630fd5b4dbb1ed37517960decb670296f GIT binary patch literal 753 zcmXYsT}V_x6vxlZyDxw^{4J{Q3Xq{LX<>;VCaXWO=}X zAFy2vIOkD-XjI7mO4-^~)mhuxqIa~mH2ST^_6EJqYOn8T@I%UP837>3iJ`GIAVoE_ zvSmE?G}ofR7Z0N}Yal&dHplO_oG@1OSHb3w`rPYD7A;iH= z44%rzA%{#C{+V6tXEk`*fHXb?1{tu?^fgUt!T~k>G(5s~;|F<0CS}k;J|qO@`Fesf zaL%~=tp}|qk=!X7?u-k*%+^@$49&MGV--f_{vPzzPEH4D(6k&xrKa`V7_!r)(@v^3wA`aH~s5xP~AUsr;WK&V`s$K}AfZL6RcIAYV0^khWNa zK5(hLTL=?ler`75Mcs@ij|vzh8~i=sF7YR+6Wt)San^`o7D;1yLMAVQ32^@z0?kXm M+zfmgH!&Rk3sWEF&Hw-a literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/03s.gif b/ch12/cardset-oxymoron/03s.gif new file mode 100644 index 0000000000000000000000000000000000000000..db0a44eb7468c4c5fe9d622e83df7cb10afde6aa GIT binary patch literal 791 zcmX|;Ur19?9LIm>oa^->XUG0^Z&vT*dW5%;D-=9;1l6neP1 ztVoMJSWxsZ@+DuSmx}b|EMJyTEa^eW2ccWQbaGSRR-j7>j6=W08@VIWjS<4Vn`}lfyBn`70p+1P%Fc z9s?w&qOC)Hy?b;3B|fg^jQU4)#S&Xuj`Zr`?5F1Rcp~t-Wev?d1b%u&twuZ@ZuDa| z*>g1}+0e~BGv>iQYtOV~x(J#!sXp(xcj-j46vgp1wM?ddVkc2riS4+ZILHvK!Zx9f zlQ0btCkfGz3qmwV7DH}B z_Qq0htDde+-Ubi$Dw{kRj(drhZgOJ|WUMHlS(Xsjlqt<3NhkU4-c|XKF_GusvvrM;L}y5X@zglK;?qFc92s zOL~w9I;dXcp2Q*y!bAvUE+a$|4Wy1Tx~B+&2n)d%uUYScW|`mb^PBnozVmO-w6-*z zjI}}xwqd_nU|AODJeSMm2ZXKKJJ^1+W2oO49qR9k$NENkjPBUTwb7n9RPD+L06~qD z?8pGl>1b<@uD0IjK=;>P<=D}ChgI2pGS}Zmv#=Ns)P3cd$oiPwGW7jwTmfXSTnIN| zv1sq*=BYI>GIWl4yN~aZL-Ba>qC|43@BxUAj*< z#N8qgWd?)jF%l7wy{;<(rCw)$-1ba+nK`h^o}O1aC+b$*575UXS(=O)rNn;GrKeuL zW&6pm zZl+owf%<&p+yqN~!uE%N&cAWCqbLh5y0T`Ru(wFW+e=f}-Vi7J#Z%kjRb>Ly6wiw_ zI$OgMAd%`WgY!FW736Xh7wurOmZt&l}$yBEX4j631jTdqhz uxkG>ifhtIxjcg!1-9RlTVi4*Ed`-Vcnvo8RpGY)LMFQ-1+eD(1`p literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/04d.gif b/ch12/cardset-oxymoron/04d.gif new file mode 100644 index 0000000000000000000000000000000000000000..f2b9a2acf34c1540bec1b6998be00307847e6570 GIT binary patch literal 711 zcmX|)Z%7ky7{`CV-<`KBf61mrr_swGIt%BSQoIA-O-;&2`Gbu95B#DF01D03dK=N3&-D zkzwGMP5!O>Y%3gpKcA8Ija3*(*HmKQ1Rv*LhRP01^7z8H8cT98ZJ%SxlCGJW!) z;<%spy{67R3|%)ry^>nNALiHY%^sZ;iH-Ox@T*Z=8`q0~MC8@88ndV#v8WGu^sK^c zuLTVfs0mFV2ewc2Har&X*f!PcOo%pYpKX}6V~6hj^I5{WwP-;EvThwM)5$9O#9Cac zPgn^*;l$=Czc1Hr_^|Git3@eIRUo2b@~W%|`?1B=#SL?6><=SNFG`t*C6r~6rz>y3 zHxBIa$?^4V>KzZG)ho0~dQ!{@pahmOON_NAN<)zhNohedLNAF;oS*?{VV)b6W~E5q ziZZKVm=7n&ohHo<@+rG-Bl;o|j(O|-3LB3kW8MbeGf5M`Uf4ti3e(@;8K^2UZb~=m zUktPKj0#vj9RVV(T-U|8P{8r7l+lOFv(%CTeryzMWI*MKG0Ue;V41Pu@|3XK2+p%TtJ)!zT;_Vx+@>i+`$uGbd; literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/04h.gif b/ch12/cardset-oxymoron/04h.gif new file mode 100644 index 0000000000000000000000000000000000000000..3dddc1d9e66f2fe990aace688c13be84fd23f4b4 GIT binary patch literal 833 zcmX|9Uq}=|7@wJ4Z^s-(gRa#(&ow)eJGoX((+*`*^G^{RS)dTH*J&z=nwk}Ouy-pa z1&0z8Na;OXVPbKKh9n$&+CvGN5QGnbM;HWZL{IwSHEZPz-|zd)_xwp{l2K!3^nx@48h{q}XTiJU@UH9rc+l8La_O@PkTX(bIad$WMH1~q+T^0fWL7pzv zZ2%MJ;nzKJsqSVy9A2J}%ejH$94ozi-F`s~igUf01>+*=TQ9UkJ7V^Cd}dS%7oNF7 z0~@^Zcvj^ zZ6eN>i4PX>T|#p=QB%+$ZY>@3agbqG&5N-`<(Y>EnM-o6%TRr%p!WPD`1vsz8*LJ9 z6Ls=BFE201cBA3ixQI6gU}FwhF}j0aIQ4BAugyl~j$}h$oA_bV57&)kZ(0`aCa4QG zUT{R^{6s^bMjXoX!|$oYp~}HsMqRP+%1=!`#Tj0l7Hcmm@TOrZJ$yqOrQ`|MFH4OY zfEK>WC{{_FAy9Wqc6pSKFq<7d9QMIvI`dGPC;@!g#LuOQRlo=<*?wu(cQy&OvL$Is zwZhQ~Nu%NBB;+WnLG>%jiD?kvn4EodM R48S+Yo3G}+O-cwj{{RX5`N;qP literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/04s.gif b/ch12/cardset-oxymoron/04s.gif new file mode 100644 index 0000000000000000000000000000000000000000..acddfc8ca6baa33d70c019c67c1257f0431e56e4 GIT binary patch literal 868 zcmYjPTS!zv82)GGboRK-x?5sx;p!+!;$@j^6(fs77gOvZ$UsBnY^G=~DYeN;Jxm>p zh;9!OR1oJO!Xmm6i%<`vzKEb%`EZCrAA1Qbdg;YW=`_4DR|9}5{=ggs&riNX~ z7D&Q(SbGErA*7VKT<-UV;?mX4M@Ehgrr6oRRDU|zf2N0ZC(oQb+mnXUp9TUzP_2u# z4Uk+EeOl$SEdxigE9p(U8&VzPnk zSE!~X`7u&J8WpN&B`G9z3YD~S6VzoZX*tP~xI#HCfnuD+afNbPi~+~~tztNYin7EVsj9r3+ z6CH|x0|J2|jcMru;Ni>3g{1AGeb0FF>=^p+fZh-Guyfnp$9#)(aM~G&nq8CJIzNg! zs_1-u(z~7KW)DPVY|1$uHit*}%z%rQw$j!24)fQ!Q#Dc6JL!B2nm3N|E1j26&qf-* z>3AK6J6{?V=A`o@U_RW#n?GMf1NpRT&|&w${YX#k9G~;*l}Lp9xJTT14AzQVeyM&X zP?eC7SzKoMQjV%PPgJgD9k8Bz@8B?rkTU8^d-T80k;97&2#zonQ4zsIOe&Ig9%17$9&$(?7xDp}5C#TOO;$ll+9B|e zt(EAdDRm&SrgS1Qr1vb45aV74AsM}-D~Q}h+Ii8mAs^nDU}g_geSK9}aSLGgFL%}E AYXATM literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/05c.gif b/ch12/cardset-oxymoron/05c.gif new file mode 100644 index 0000000000000000000000000000000000000000..884857874cf54f63de748bdf52fc24de93e3dc31 GIT binary patch literal 939 zcmYLHT}V_x6h3$6GIw2P^KM~XWtXmy8P+b7ZImT(dnl7c4XG$1?q-6L<&s8*Qj^<5 z4`D?<^inSLLxo60gpkx+mq4S$Cxw!@50Y;sR-`X(bKR{5=9}-F^PO*)!&KMo-&q;2 zfjBI{%HqH|7eZt*nQTI0$@02}OO5SqW=DHlYiGRme6!gUKYzNTxf4p3R0TkREuPr3 z0h}?EnPv9A=1ik<>*MQ;y{T`5rdm&j+77Z4vlFqg#I1(!+tXV|+&(AnyBQ^OCDyKe zw9hT+I=-7ua-}#%CiXVDr>+?TPE#UOMIuBqUAE_T)5CWzBPyorgVn(Z4WR;*WnmOR zCN99$az|)64#+rwW4W`Omg2R5qxcmrrKPWER6r>WV+06?($Tc!Ql4W4A!z|}M{}pF z7KCwNMZIDvna`NCxu2-S2Q1|PAkx!fKXNEh)mq)%o3XG`r^a-*SGnpxI>=1Z?&baU zhHjX0whG8L(}vnIS|y1)S4hGnX4pUTl8+mTth4X!XNSmW$QeQ9H7loV&>uD^m_1p!TXR1{?9+pk2X>lpLva9k@#eX^WY<$_XB1T@_-Am(lyQ zd(<6&{+DnK1MOmN9^Q7>YYJYg2jy2KdBv1hGhu5;efXg?EJ+DjPz#}e7Xjr?@N zv@q%vR$h9TQ7!9|3v2UaFOSGJ3H^fmam*8E@5nOlr!PIz&{hdNXO$le1sx4lnV`{^ zx)Tic2mvY;|3lCa2t|Irc>#y3JzURpgrnY*>O3$R10S6&6Bs3gby@Yz%jVQ)1&5d$ g)u@+4mULL!C*emgSODsb0tS6BKT3C`ECjp%0GB-j&j0`b literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/05d.gif b/ch12/cardset-oxymoron/05d.gif new file mode 100644 index 0000000000000000000000000000000000000000..4f21e46120b3e03732cce1a489fc765fed0cfa61 GIT binary patch literal 745 zcmX|rn@ZkAS(8zWy>P-F!SiM!O5Xn1}3ut4zY z6b7Lt3MP#*$;!}>Fe& ztAHQ;0*O!oAw&Z}(;bQ#J1+9hIW5LYrR?*qZwEQQSqK0GwzxIE z1~8fc*LS7ms>W(~`@?HZKGJ`fXI+!en!M7w_$k!5AufD*u4*M*1!vn8GDllBuPQm z?-SI>y!OyC#dPdqVRC zf*6R(+k3hGi&D6z8`dAd_5pe9G8_7sBdFP1UG8g;VT1I9V3;M;n1~1P+_3kCtki-# z(86vRNmo~2x-SqmN*))_+1VANc$%6mEH=iv+$mrl$zdBgNuMrXW085nVi<6@dZSawt0DnL<=OZK$afK<7|I zhR3T?$mHyynL{CDAEOqkI!6y7^$DOY5%BnW9x!A|V2z7ghS?cVl{@r;sOiOQN3WQrg&D@6u}Pmd*Q6|J33i<`_d^+;j>nt(et5 zqz{&pT0d#Q$?*hs}F(?!h#RA9ixmg(Y`c0*Xn`q=bYc~ zdw$<@_P6b8*&S`XU5d#1ayH`dv6ihmR9IeGR} zF9cRx1b{$;bJd9frJ|DOtNQ)6u45$g=N}cb?&lAyT*hdzyIp_I=d7;3_^l`7qSE5t z?`~LC{TIJm?1(3DTx+Fs5$$qL78pfeA+24D2H7TTM1QeKn`{iSAWqAHX?Z;~-8>y)AuM9E zRETZI0`8I8E@u^VNo~d)?v-j_KAF%c>nOHM9oL`nzb#RNS7tt+SRws@PF7qaOGCZuZ9J zpAw?D5@zOWn~_aw_Vw*#=_gXzTJ23ij*by!7u5wEcfbe7iK0>6g3ldnamp~YEogVJ z+37Vp6AiTd1MGDmdjebz{Q6i53iMw~VhoiKE&mA34nlf9r8O@UPzlof5NHm9`cdrA z_?@K8drXudpT`cL^M-%Tm`F1JJzE;orX)?vDM)+mLGazPr6Kd6i5fy8ZoNNABjEfX zLhYo4{KmV}W5+Oa5T!D2(PJxBZ0c^3)ybHD+>y8~`cR)C%6y;1Tt659y$=YeUztlc L7Yf%5girnlWYiTZ literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/05s.gif b/ch12/cardset-oxymoron/05s.gif new file mode 100644 index 0000000000000000000000000000000000000000..bd55b4f1d88d5926dd33755c73bd5a952edf82bf GIT binary patch literal 946 zcmY+DQD_uL7{|Yv+3fC}bIqMc>Z)g)OAV3er4zVd+u)(0PKt)d`@P$_fK2eE1o3X%trJO~N}8+@p=qUX0-Y`gIP?f1>j z{J;6wnf`%y*S#GMKnRcE#bdx2W36p88ZQTs*=I`zzZlv(D)#Rk-7^;M*;f)Dh5L5z zFO5O=FNXjSSQ|}_Y=AWaa_5=6KJe)fnZEf`L$97%VV4IwiViuB#AM+<_x=}Gc z-Qa&B>|x{5qMQ@rka=@^P)>pdL%^{YXKe+5em)%5LscQY-^ur`&ye3v@o(cL@mWXZ z2f0)~oz=g$xWi|q|Kv-uvxDDi3s3&(SE{|is;23ggM;Yfm(C97HMBY7!Nn8Jbpgfn$wLK7naeoRf||b+EfIOb7g^-|I-%uMPA1K zGg9I|_VpwpNm*7Z1|uLSV|cqJUN-We!?KJ_3J)FZ<>k^6_BaN_<9C)I=ARI}SXz3Z P^)FYF{l$Yc2GH{ycJuSH literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/06c.gif b/ch12/cardset-oxymoron/06c.gif new file mode 100644 index 0000000000000000000000000000000000000000..d34bac88406638a6ac94d6a65f5b430a9595f594 GIT binary patch literal 1034 zcmYjQU1%It6h1R&oZar;aepM6vB}m6xDdA6^={Z|#H~z0t(yc{h=CA-?iveQ40KG_ zQXvnwohm|u3YOXjl|d;)MTuc40ioPcQ))N0`=V5=Fb}@?Rzx3s>3Sx+RR`{OzjMxa zzB6-Y=1BFK$;TU2Xuuz^dkGLiNGW^0UOz!Nc6Ye;`t0##>%{TpW39%qm7~^DW98)& zM_VxVx26CnPzc4L4PehyZr|nCtFO!|@80;jS08`-;fQ8``sMO8|ERmw%1(S3+^XDk zP|3)a7@?0a+9sQSLJrVC)aKUrTP2!xf%D{fIpd< zP90#QDvTg|sLwH>_E}anR0|V0P3r*5qd~EO2M2qe6#t|?)gBa)#k>fo?_^lHj@kv z+o(LRm6O34<#cTEGPkVy8F6vWOqv!QvI5j*)#153s}KpshxII32kn^q+5Cg`FRs@= zpVeP@XCiv;J>}<%?1z*%HGGlb5h^u7_h6qHQ z{WhmzI_=wU9O7au!Iqnd`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A7b4sk2=BoSvMVIJ!}Rw#s_fDAbWyMp+HDB`d1-(v2y_#2uTWwP6J{C>Aw=iw;~?$TTrGiMIW7j$Asuc@Y)=esS1AjE zJF_eh?KN<0c^%QFY^7&cZaypEXg7cR5@S#PsO8N-=#P^8>lS4bceT7dD%8ha{Fif- zoqA8pErT~T3K5AJ*63+&BZH2NZZfx;;LNhitj#$+i zj)0G2|J9{5rX{Qko1hONq#dUg-v`wPH?%gH(1cBQ0kODy9LtQ;{1PbW7jA&Pi}!FJ es<@RG8P=fh4}lACZW+LAte^P3l^WRsc;-)J`2)%T literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/07c.gif b/ch12/cardset-oxymoron/07c.gif new file mode 100644 index 0000000000000000000000000000000000000000..248e0b2a057828cede1800bc83e8099d71f37f68 GIT binary patch literal 1083 zcmYjPU1%d!6h3$EIGMJ0%mjApM4B?mZg7caxRp`-0lBfI+BFM-ls?pbnDj@xZlPrp z5FrmYsg~WXXra5Z;7bt&74#{TmPNQVBC;S12%_x5=A~~d77>3Q+;}F*iZjf2zkBZa zzH{%H`_jzxGtX9LpaQ=^?~x#-R7!Qb-F^TuegBctTjjM?x4O1^p;ozYY1v(@Tw1Cw z*C743P5=lz5hX`9K)VjPbD!UuxmYIK-{0&8XWly<)5T|BuD-(0`}?(jCeAPY`gEJn zhlP54&vA+RZgxUIp_*H$>+ty>?Y}_(sIbUWzTs`Y4))u|`=om8w48Ag*jM?fJWElQ zNfZD$2dA}jM#}J=Qbhby;gYDT4dN$PlA%CD%UG$1 zW%&h}bxO(UcgXe1147~kL_Q~td6c{O`})b%$&FjOGdqg%W#h)=TF_Y#8>Eamon~PR zRXlkdh!G>7;a5V8n8i#h2s7G_na5_M;ST1sg58Cvx{e!L9FW~+;R@L^_MPCO7&5Y( z2hJQuD&FSxptNvftJ2N#($^4Ypb$F$v64n}EL5O@tH5HVHiC;?h+;V|Ch5E{DD})x zLOBADyYnmT-sL2HVeVV8?N5lMvuy0(A$s^+_VJJtfdL)Z> z6=@0kl;gH~254_#jh-pSYR6dZ8dsD;1p5!z5nb=EygSlfcLmjIN({C4Ig9me2GimY zie(;k2-lRv?MKP|B7G)@Su1ko69|`;gcJ{7)QeNDhSilAN$^C&WGo~!Kc%MhG{a+# z^Dt_;`Ub(qPB83*7oDaYLB<3XW9&J+{Bz2U-2XnZ2$lO literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/07d.gif b/ch12/cardset-oxymoron/07d.gif new file mode 100644 index 0000000000000000000000000000000000000000..920d5f5f544c4e99d9d34317ad9080d1980e24a4 GIT binary patch literal 826 zcmY+9ZAep57{|{&XWm`)lvb#BsN30ED$dr`E7{AinP{3H5+s!%xnml>p~Hl-M6OOv zYM2l~3E99e$~0E=LCENsutco1A{4}g`cOeB7G@BxGwJn#=g0HsdCvdOIaZi|;Gm-r zIKUd%Diu&lg8&4B48O{_8CTp=(pXQWz>V&qbSY#H>w^R9Q zqMpk0Tvc43+C;<6bK{Oy9==d)W9haIuIBZv1yR3HAnhs-lc5#sGfdD1Pq5z0W+Sv^ zzyf$3!8B~?&&>A97MwbmnKdM*Vv8@^XTfQ(pB?nGy#f965+Z1VGAw0n#fgk2`Lw(r zCoo?Va-u98KUi6|C0EL}_UmO>4|&0#;WfCU(8!Gc$?`2#2ba>xZuJt#zyV>_tOPOI z=Np&a-#eZk$5)iLIHY_viF1m5J7_M@@hh5{=+)l#hq`s~Yy9lhoJWJWciriIrFX}p z03Ms50gqL#mt01r8(82O!8PIS0(v+gEE~OHC>Cah+fDXsAQqR7tlg~*Los`_i^539 z#O0IOrK1Wx%CZVH)jMfNP9$g3*jT7NlDD!@C68jxD$d`StLomyXYn4L%boM`9B#Pg z@Lt63r3w+OJXSVh_`s-Cu)T}>l8gtE9V9W_{qcyXe49`XZ|9ea@CGG61P*D=D@t}J z`}`rPI+z2ZxCC)_MXE*a_;<*Yt_pCK04<)Ea^vJ4LNRQnY9yQ?YD@?M#6;EN`vgQm zn~|YMqFU@HY7!(y20x_{z779$1Rjc>-_}0-NB%wOB<}wVLUJq=RBmMOgydFupQHl4 zi)P6^g#$1=!=TVRS@b+<1b--^IU$P z^F4>}@6WmM#K`k6Boio!{zk3Ekr1MRP@@5Ovi59x$IgzQnr1VnrjMtS$4?(+N0O)C zojICDd;XOrge274v^L8i($J*ZrhYGRVqCiX@SBF&{c%8%jjwJ_AJl8?QU1iw?9Sup zpX>B{L+nz|tv*EpTA&!R9b^2>;Y$TG^~X7F_fK)QBPB<&hg#dp#lLo`G5k4abM}+C zAIlIS>c_;7V?-|CFfIUt)F1H|ijnYKu_a4|a5>ge3;p4xXpjbR6|7Y-hN=VA5Dno4 zJOB}*J-CGTL-bG|CQzPWKQ7`?h+f)(qwql|dJtIGG*M~TjeDbQhKATm*z2P>7kR7W1#Z^+a%oEhxu2tx@i5jWL!x zaG@M7UpL2Yls_s5wX5^L-FVLqo|>mV2=fHB`Q!dPHVrkkr&@zF$xnp`l6judm9 y;ey{|&1X{aJEWzUKtA1^QHm)c9{Do2CGzqo$UrF2hmrOM`{##O#}^EYUiuGwLM~DO literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/07s.gif b/ch12/cardset-oxymoron/07s.gif new file mode 100644 index 0000000000000000000000000000000000000000..5a7842f5dce75f7b2ca6c9b412533fdd7a8b2671 GIT binary patch literal 1103 zcmY+CUuYav6vofJXPljE?zp?8sgsh8voQ;0n=ChBBWjD>Vzv?zbRp|Y%)@M&mW@Ul zk_8p=a7`M)Hb|r)iVtNUw?(B7%MwxHCaEHV5J7Mi!GM3BiWVuQeX#49SSlU(esj*u zneUu?nCC}NJ@s^H6iVC(c? z;+YDh?ph3hL4Q~r+5omZ_VYdY&FHHWZ2jBMTEWqG`y!UQ^2ywooXTxg{u!K_`RmDD zhL0+9tl|00d|ez=aB?v-y=1}F+q-wb>NA^A8$5wJ=mV$Dwf^d+1NdGw^+EIq&x$09 zUX0;5X&_8en7}-#UnIHku>+5jj)@F*;xH*AGKXQfkr8QZV3w2?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Z7k*AoLH+9wViCnD+v9OPOv#C@|XEj3D-RkgbS+d?3uwa!Ex**z-k@F`8EFOWVNe28eWt4*wt7Wk7vDiUH?esE(Efb zeC1?8TmrnqdcDf6>NgL3K1b8*A1G%|7VL(@)V)xz?sbRLhh!n`ytrU z0kGn*Y;;WjM|=;PywPDRGyzcAq6~h96c3)n*Y~!BzCkDrhs??R#(Z?vSsmq6hRaq zD!Y?xLa1a!Zz<*}HZ9w27qFz-WJKE|(umI%@7rw;FM|3iaJHx46Nc!eXj-MuCJ_WA z8Ay}ht>}uqS;>lG8-Q-hdyCiXBBe1Bnut1KubGpLVo%iMi!FN3T+vxP3W!n3?UKYD?3dvUGOqqIOqJZL~xtrW(~Ev59D^BzCD{ZCKmhXk1Kp z`{x2Bksy@}Zbn4Y6{L%cvnf)PjBw$n3E@UUM5H$e>r7YbB;Pyp&G*jxoNq&O zW)K12!OYPCr8EaXF305G@%(Xxj&401lRFQ`4s=BhB=*XCB8m3Sy-NT1FPJZ>$TVCUga(0P&lu5O)al<865;~#D$tC(m;N<-Y z_~=%$r{DrUq_t$j>#OBVixT!Q))EwQgtJDU9z=%7pmVT`K`pN_09+(CExs7%Qw#A+ zGM3f-_58zMHBBS^@Bu6>4}3`v!Fqeuc54fR{+3L}(iiZ%6UQUPd_tOeF&cpnMx}o% z=QxLz0$j~#sHly6gSfQN=mS`M5Ah`QXho=tYJGKLydSs~ddZoNQCf)28eK%g9w3lc zR)eGt$}>LQiKb<}%oY(5Sr^DnnU*8X!(>pQ0vVNo56K=Tqm&k8!09Ii#00Mkhpx`H z|1HPzp_B-+TZX0KK0PkXntecfQ=XrXjHA EFGDvIIRF3v literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/08h.gif b/ch12/cardset-oxymoron/08h.gif new file mode 100644 index 0000000000000000000000000000000000000000..7379dd6b12c991b8162d9d304d8a26bcb222200c GIT binary patch literal 1124 zcmY+Ae`s4(6vxjyFF#(An=XsCeWh7>FIi$qx9*iVTPKw_1+{DcC~kjjcCut<4P%wX zH42KtU6RHhE2E56!{{*n7wZTUhO6B_H|+>2QTErUtgyfk`d2Oxi!u{MI z=bZ2N-23{_YXdJPh9Cid!^YqsglGaZn}n^QKWQKR@bK9QZSw5I=}hAExl`IZiF3)x zQyI|LZ4!V4d#qGT2IQtHtv)e+89H-Vn)&rsGv0l1x6@{RTbUR(t{V01nfv;(YjR)1 z4CG=D>e-*#tmV=je=ek^9og~=x7Qwx-@E>4b?3*#s#w6caJD`?W}p<0>TWbDFue1qm5)`=e}Yr4qs7?zZQP|2S2R$itX^8)X} z7> zwb4d*wPZWio*Xv158k!^?q`Q)-aq(*jdG@4X`TALGWAfup64_KvO5&5Zr^0G~Q;x!&Wo_nAZs_LU`qc=Y^N$YaQ~OS9Hj; zE`!5tU!w?vN<)?RyV3>N-`BVV^Gd@npHv!Oz)8bbfJMdUkQ3@N4tY$8Ps5mT-G1yT zOhM7dKL?XNl;ni+a0+Y|OoimT46Oh$MVu!kbGj@wTVPCA+%oYUdiCXqYoUFHrd`TzZNM|F|~=Tl$A-MAJMUIKTsa=h-Xm4)d- zHAMPq$aJyG=9ix2dzM~?0?8lEyAI3AxfyuZke#u#RS|y$BDkPI#1;<TC0Vo7YY5)KL literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/08s.gif b/ch12/cardset-oxymoron/08s.gif new file mode 100644 index 0000000000000000000000000000000000000000..c3ecb02c6e49db6112eb8ce15117fbe62a77b382 GIT binary patch literal 1240 zcmaJ=U1%It6h3p$WM_7BCz(W&E@r!#O`2F^U2c+1i5m14f;MyuDHY6vg$>Pu!PP9u zK13*b?b0?6rUZ$g0ddfm6;wog2vyg9accj__$%jU3c=h=VY)OqJ(~|MPR>rv zJ~!?d6SK@n*HP+zs4C6>NL`k6*qTp7~7-GnMoF1;{gfYlj274g#XUrWmjx z-hqG#LMQXs^MtfHVF?D9#AX~PJjxTSnI*9WPZLh?qZF0I2k=S4BfJmW@Fby+_qD^x zS|9Jh8m0+7yc3eF#?piyo}^+&|M5(UL}VlmIbF8W_l=%-(chEcSlsq~kae)g+VQm{ z1L#Og6^nF4M&t0l^-g3cUhw@>+Oa&l*ix0MG16g=`u;VJO$<1VsNguP%;t7ak*?=# z@WZ#D+=LJE(_P`~@G)O$nit{2&u6 zn%{8W?hPBuX-rb)-8DMda&v)F0L(Q8FMsB34^;c^W!{e6)jFbvp&%+LYGZ(bTUpar zRD`X%F9f=w+)jDa0Oe`t6MR9y*UH5SG0~q}hfeI}6KnFOiq&yP$Of!v6|3!t#TZ`} zI)kf*mbHwsY`1D8l2N`K=nPvmWM1HipxZMdRO5Y%LMj0u^8@Oa2-(iR-HMi;xAdL# z_-Y`L6;nj3S{K**Ni@$5+b};g-i}kQR$#j{l5MOhQN0Px95hk20WY{>5iW@86{xw! z<>C&x@>XVw2->)eV4jOL$P52Av~b_Sv)-PDvj;VnHo@an3-eJ*f6mmXCqTPACfsP#N@=_peRyb%MTpShj_Wx%s2AU@PPo2PFnLs*+^eh?0<`1c@9Jpk@ z%?^^h*+HYMSoCUUN%*W#o}n23NN5{>H#BebENN(@)}WP0Icy{Vhkq_KqU-vB>c~FmIT;*&xUyRgZloT&xMk~6Mq3njxB=# literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/09c.gif b/ch12/cardset-oxymoron/09c.gif new file mode 100644 index 0000000000000000000000000000000000000000..becbd263c56e414a25c5186d958af7ad40d248d3 GIT binary patch literal 1240 zcmYjOU1%It6h3qBFd3UW&8(CaAbcIQ*O0blHSlECMvxy5WuC}y! z5sOZCg;rZ?kXrOXSSm>LLHm%0K+AG>*ObyA&SMp!gMtr&u==DR8PDC_gxzJ%{m#$* z&N<(GW#Q%7=gSLFhQFcr3n2_cAw-fS{Q%nR?qmKti)X9$g|pQ&tK~E2EA~qH{2Lc4 ztC0OyRR9#o$zn+ZG_jOlcKQ8z$Z?5U9Z9AxipDkIYWuwRn;59pdlQ~vI5N}vo8mZ&LX#Jbg<6B4#HxxtL z3Zi9ESA4B#MYXvrx<9cQL=)t?p0_qHgEK#>N1fOP>CtLJJYYB>&iJw(mbK_HBh<#A}tqC zA_Cl_RPL|#=G|9kW=M&sMbo(Oo}M_-Kv~gGpb{OaaisL+7$2|kbTdkoMdk9wrr$ZX>4tqN~6<)svz%pz$|omz%L2zFmGd{X!TYiNV-5 T@873j<-SaI|9h_C5jgfg`XNo$ literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/09d.gif b/ch12/cardset-oxymoron/09d.gif new file mode 100644 index 0000000000000000000000000000000000000000..9487da34849d9001219d7b73ed1fd4162923d75f GIT binary patch literal 936 zcma)5Pe>F|9DeW3v^(mvU9D_tcWriyl-+R~5Zoe$Cbd-)O0t9AW?hvP6&E!qPt%&K zh?;aV$&fvSq1C2)=+9+lrI6TQx`+p%#V%5ZA~viDw>KJk?ZNwg@5lRo-}k+Nsj2gy zJr}400q`B{ECr~lngt-6CGc-Kw~sd5YV7Ia`g*!L`U4%kZCo(W+uGOG51hYf2ml1U zK{aFmm1W`jw(zd5vk^|df1Q;}Cr+7Z>G9L9dSOOLMLIt^mvj2gq$T@c`KMH5rN}7v z^g^S=)~rTZOdlLPx%nd*^4G}4Bc@GlykL50ApLM07Gj!1B5ESriyiHVL*1x>>@w^S zjiwycq8SSD*b{4)=0p#6&$s*Hq8odbq$LmLQH&5`OumeAqT0l6TrI89V5VHEqF^1(}#qCaMiXtO+A4lkiOhdw&PR!7P}DK6Y&rJ{rz9 zc?ny&Bw3)BO;~k5I1Ib#gsfI7rLdMBDO4lcXtUJ*M4oL~9kX3A&&lzYqRD0t8@Fnw>p{g& zEJEy^`$wX1YEIrg94CUaf$&u#xW)cFM076fkM9ZocV^e;@i{lUFm<4HHP^(G=P1?0 zG|LNm1avcCh=7hLFQX5FCIh^JTxF3nGDSYA@)r1n*$*Nf8!=I*qnb2&5r2aezrm>h z-BhKq3S+_{D8W3GZ~`;_^CIcC3E^cB!ki(mLaHJI{1(?PFC76QqYM!sw-l3xR2id3 zL4yIV9c6|a1+@n7LOjV!sYOJ&t8Y|Ycki|Q9))A{Dl<-Sk_|~t0t%-ba|rt$!0-TQ zH-R%{MY}I@C7hD^8fITsmY}ezEV)yvhV6pXol_nbC^PP=PhxwDB;S}IZFyLgUXl1w hU>CqM24y(OjMu*)@;jx!<^oyPG^XT19OVFT{x1`dB0c~B literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/09h.gif b/ch12/cardset-oxymoron/09h.gif new file mode 100644 index 0000000000000000000000000000000000000000..17150437239003993f33c7021b625a36bdc6801a GIT binary patch literal 1190 zcmY*WZ)jUp6hH6YXL7S%?OP{XO45?FeNbPrct@boY2Y;l*XjoYm7(8Wa4n1$_FRkL zDEj)+cDjyPBuE5>Fd@zowG5*lWaG9Ikr5@xKJ-JufFJ{h6q(>3Ts(J8hu+8eo!_|} z&i$R=J2COh6HgWKcFsN!6;x0Bwi0oqOWu#LT3&_T5))XZX@kP`5w+boM#%foS+MKgMr_<{od^ z(PH|ihX3thmELLgsC0STQ0Z#xk>cR(-;ew6d4uJUx0g;{ydbtP>j}!J{}v$LJ?jGLDht5t7BPpZvkR0qTn2q zgl2}Xz^k-;AYkdYdfYMlsAh$0M&(&Bv~|7a$ej0>Hm;X@q(9oFE$H6949}1!?5;pc zziYt049MBtS}MG42piaa8IY5pjf8i?#(?{#mIOEFo+VYN^*U3M^3}A_E^1YBIP8DFvp;=bV&&67Te%bIyNCW-D*; z-I8Iyg?$wtrkU*_xW#=|AvD265uyt02P`4H7oO*Q<`DfRcT5J`d}wtEmA5qdJ&D`h zWM10!OnFPA8Sec6aV0t;oFcZsiUQw?>@DmqmhTP;)VgG%A?8YI;?_5{Exv9~upk@OMy+I-TV(g#0wLEKWqh literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/09s.gif b/ch12/cardset-oxymoron/09s.gif new file mode 100644 index 0000000000000000000000000000000000000000..1322a37c3af3ac0a5f23e8a48534febf7b75f336 GIT binary patch literal 1280 zcmZWpUuauZ82|1$x5;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pW=CF7yle7XMURJxyFOdKZSPHp}3!Q@B-R#fgF>o1x9_jKPq|O{}8l4At@0Sg~KW@ zB}Ut!q*5PRBs2(DnGrA-$&}CBVl>d?7Bw2cnFCy$xy{0^OBk=JIR%$~%FF0Hqe?ZT zG5|BI(WNr?GrY|S-iX2!V<~rsT((`)0=ex&SvNt--B!?;&&;~Z)6Fa_cHOp+pxcbyiEkD!_{GhlfV8VE@m8TF rCh0bqkAQ}_dQh?^fr1J1;DNV9{u|fc4*<(@et!3>%hzEW0KNYKEkjNU literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/10h.gif b/ch12/cardset-oxymoron/10h.gif new file mode 100644 index 0000000000000000000000000000000000000000..5307b74fe804b753bc28630cb260cf4bec40d75c GIT binary patch literal 1349 zcma)6U1(cn7=FK>r62ROoVHRUr`l82fFxNsOgU|{U7W_WTb;we@S=Eg;yPh?+Ui<{ zLWR?$Mq1Y{k)anI81!nvjEs#j5bS9JMMXz?Wzj*xKpEZ`yc1;c{gSK`uRM?^@6Y$X z&+|P8&dKSivGL?IB;ikJJuY~j*92%b5jxNCqh}KDpIvbD#RccWQu4yZ^ZL2u#o5L4 zOECNwCjbP(@~B(`tm!BB9~s|IzkQZufBd>>zpy#d#jWc%oYTgZ;gk(Aep%gxawCQ zY;CA)$*4C%AN@pT{YyCRZr+;pzlW?|52^8NvXOLi3v>S4z3LfD^Ub5OdS>S^lD>oN zo>aE{SjJa&K4y&&&f|TJ2{%ZFFt9AF1pQar>_e!&F=2(!u&Z|BLAWJs?2XjK+O1*V zYCDMB`_xXvyipS2%l(Pe%KAd|o9lA(OC-wU{rMEKH!C8s3KdbJEG!xy!)p@4Ml}Tm zk^K;%N?Anct8h+2#K@+BiE0KR%UD#Y`v`mJd6&mBp0#=6l4o79j=}5|MfvUsoBHir z>yxo#`3k()lV@yP7%t377&q!EhzTQuP^avu$gjhUgrkO+f^E@QMeryK3F9(MN(dSG z6zqw7S^{Ok5@&q_BwV&^)M-l#tKp* z6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)(*5FTZ_S&H*Pefxw$ z`|-X-66+SDOmB1e)HxjX|Dl4|%}`N^kB+nqC!oacE<22-<#5BPN$MQWFmF){ko~>R zfS4ok_H_&=K##$Jkl^-Fu)7j_)goF^4Gf9dg$(jJmf7#1%VQTToq}O((LECDDLF5M z9kf@CRyHQsfcc;lan|FCj95~=k=#)|twfLA;rOystVX}ejNof>H37nS?RT;*AM;0T@QieG(eC3RC&fztvN1tV*byD+MOT&Q^BXF- zI^h&apJ9Blq&Pl(b4(t2BR%z;cZ>Iy*lC40Z8Nbalvd=D?ZsAv_-E+qWw@G5jxKO@ z?S^8z>qsHoD#=4oiG9F6k#0{YHGrNcg6R<=@M~cMeE-Rk?}EEJkaqWLLQU6cgz(8R zCIL*xb7MeBGIKe~IbKiP0LP3F=4c*>HjS=39;3KT!y$su-KdIs?s8a%Y*ykbY2oEf z{eN(2X)8x*oRuTtQQ^)K31Q*D)91ushk1GWoT+^z>QQBY_!qKe>@g0EO`Pc)F=#tQ z?TZS0;(I0&mb5B`<`=iLtZ4!5^@^5CueOyX&916JOHBW-h#XB&ThRTxx($9g)7=VB z(VSH_lgA`0%XrdFWr0n5VM=C)?r@@(_|}%Q9nB-#2~ItXZC5g0#sQCvC47-%tN@uQ zk~Sawzz<8iLl6%2%lkAk9R)d zw<2xZKX|IR{N?T9a{1=P;_^4M#btc!e8KFD$M1JdwX1CV*0b~*_{&F}5$f$<{qTbq K)yZ|>@&5u$jz&8G literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/11d.gif b/ch12/cardset-oxymoron/11d.gif new file mode 100644 index 0000000000000000000000000000000000000000..ba63b6da95d9a73c61f6a3fbbfe467ef0b549e8c GIT binary patch literal 3050 zcmZuzUu;`f9sbTa*Vj&TV|&F7W^v-1HkJZSrQ1Jj-IlVu!B(}rc=VwXNR_j8QYSnb z+DHkd57!H5)0TxGb%+;`;br56R1puA)`yc-K$(Ux6AwI8V2PJJz+}*nf`n?m-*N01 zM0#~}?z!Lj{l4G#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pBR{TueC3YMVNsKgF?kv0Wz-ghKl@=9;;!=|jYbZyQIa#V9)@ub_t!%0%Y1;Q81+OvM2h_C$m*;?Z+}7IY|+psM+xtxQZZ`gf7$#@?24 zjKjG4^s`!HZ{=txoHrNKr>~{A7Sl829N~C`Nta^IeU*w9)5FhUpmZz3dW4e09qHkQ zK~34fl1ibO2#vrx!LRQ4gVz^pspI^QzO(j1XhMrWWZdh^b;H7O^g6f{Rc29MsxrG literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/11h.gif b/ch12/cardset-oxymoron/11h.gif new file mode 100644 index 0000000000000000000000000000000000000000..2826910c3d4545c71c813762d30308726aa4ce79 GIT binary patch literal 2842 zcmbtWPi!Ms9sb_D@pzJs9k)%3Q;(fVNhBk6(QGyfW(liVRuFdSVM;j^kX93#N^Nmz z)cRo99G*8zBGFQXk^&M^Wy)o_RMGAQiOY+YqGq)eSL`8&N({FM7GyX;xzv1boIkte zh%Jxa%6D(B8;y6{f(U;y|C=R z^1TzEI@!4P!&hZV*q5z~acR7tvvQYm79GxbzC2}1->Vd=Xy@8A9Q<&C#;Tl^RamG% zf_C4kTE68O%gpepw0vB8?+DSoTw;aCp4+%2=O3Qe^rESklE_nvmz4Kfs>pFb{hcmAxM z_YmXIv0BV$R_k#>E;Uph6_>Jx!7UtF$BhJYF_3)ez&q9pOh>KgmO3b=?{`31hfz;U ztb4{JK_6Pm(Y~_Svm7mqrs{#P zYZvwb2Yeb#6zhy(+w=h;i zY;wIP5usB|c_I_w1WLHUgjp^y!G{5{E~Ww>5}-DOn`GG6r!abo{en^jz*{^ysqglJP&0~F3F^2dWP;!o2gAQ z?elo3Xvkb4B1#)q!Y^sqA%qt}nr`0ocsRpiJsrFunx?dHok)pQ{=c~w%a_6-_S4se zvjt3+wdXLE%8(uLR!Xc^sPg0KEDJY+R9sz+FgZ9z5bPl2p((+s1Y#v_B{)^qPML3- zR)Tm!aWr_$k@()=<~53@)i~_)A>XE5$Uvi!)kyyIA3U7`p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WK4s6q>D;M*P77n%E5z`f%wMxCk4!#RcYDV|1({X z`-nkWtW4mam^BHtYbD7Roo5PRp)&Jb?!U{jM&gxF>0 zvmmg@V^$r_=(G=KrJj@GKoTsB)U)olQJwP^u=Pm9LX5>I~AsY$dx22vsA{JaNmZ%Gz zo>GeiX0M?$Oj%@3vjx=Q!e9Wk?(cmRrdw)L2w&yiNQ+3)klHhac4otP*T`LFHJN1*`N6`5yxK_GMYrJBriiaFHRba*G_mQ)?-Zbo^gi89{3Ndv#Vni1Lcly=ZP zm5^eeH##zWGF&^tvB``{IyCyw&O7(Kb0b zs?L=l;fJfU{W<^o;5Ys2V0+2GKHB!LFFyN;OuBl*;VYNS#DJlndq5JyGy8Io?rWbv K@qO^nef+-%g%>LT literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/12c.gif b/ch12/cardset-oxymoron/12c.gif new file mode 100644 index 0000000000000000000000000000000000000000..758898e095cac8dfbac374bcb214ffebf26ec787 GIT binary patch literal 3045 zcmZ8iQHWeu8UD^WH+OEDGrN}*>~v?gIZ50YG!IuD*EL=3**Zj%f-Y2wD9Eg7bcD|bJ%V5d%> ze&yEOTzdZ6${NhZW=C6{fd6fRhcIUwX4=%DJC|jhYe`jBXLVIKkm$?Sl<{?&*uzFc z8^>K|8>s6JjNSpO6YwyP$mSfkE)VT6v9r}f)035k?hLK2<3O#u4(<1*vuOs`Mg@(; zwhQl#s@F0XJ#|x9v^m;OX|7+%n zyG9pz74OHgHnVmR(LjI64D(2+tN<=sf^KB+P0Pn#qVSOuAVFU-M}7mah!`e^z)t2> zb~-9^K=9@kTu5}X|HhTgY}+@HA*N_;k%6F8GxwHB3g=%O!pm7^BR_d_FhinXt{}<= zT!y-^(oJp%aaLKz^}pK0IkK{s5Z$=sft<2ebHppiN5NIkvVP?K_o)eU`vG8cp-kr@ z)0J-m*yQ5@_<&By9KBabL`Uf#ZIu;*5`#k)Wliwx!zc-2-@X{#bT*2j1a-31ZnJQ2 zr8_C9j!?T|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Evzm8PZ7P_g)3>@0(9{?!8-qv-Yk31El;nE&u=k literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/12h.gif b/ch12/cardset-oxymoron/12h.gif new file mode 100644 index 0000000000000000000000000000000000000000..3c7346a46ea6e0d30e90a2f55ec51c19f4dd6c60 GIT binary patch literal 2864 zcmZ8jU1%KF89jII?#xKNyIPAS9keTD9?|kR`nZ2;Qw6J(-8JF-MWFHN!wJ~N042S$@KeL~HzV+I3SKHyWtL-am zm#(b79A3V(`kiYpuVMDTIROYfWpUOF_xGbbykW$WDI4!Zafcc$eTS;cXukXO}$ z^OnpO!#OTNS{tY;VkPE@tz*`KRMRT29H)y==476K)1xg&2Vs%xkGmfS{mbxB54M2w z(87VAv|`+F3j3#=bZ_|fg(5CSX{3#Iq^}+UIV}zXzY$SeXJWsAbno4|#XO37_w|e% z$0s3-Uc~}FL@$;CXVqXi$$YfaFTV>t0e7ncEp-v&3;y1FQctS++w~TV2T6lQ#2zYB zzJIEB9}}5n{V(m{EP~dn&;dRblSxxw)Zx4DHo%$*SkkP z3mAk+{0mVSZ>C6iyqMcY>-xqUBIm9l6+ER}Jc_i$5*ALEdJYXf?yuV|h#{0Qz#331 zbg+RFXgRXZJ?h*tD5#Vh3h*ZU*g-vNIhcu}SU~l0vZ%nPP8xd$mk z7V_ChBTt-%wGcHYI&Rz%qywCUY60DazE4Pa&T~}j>x@*uWw+4=JrO;owo-#pm}TrSE<>wj6EBuJh-;aJItEYGR5>-SQlOJI z%#YD@VlffzjHpV9D3-EGZWT*VMvRMRi;%lxmOfQfv`23+hPvC`kYI{nPY|~?r%9jA z4@S7Y)tEvT%5-@EhJJV~Gx{e>GBmE!9vMZSXHh#qEB>s#q0=TX6G|z@N+3-$RfoXc zCrPHceQuGO91_eRN|9i9!MgLKco7tfl|b3-69b_Y75#y65yzzU8f~!;3Fa%A=Bo@Ko3FaI1gxK(FjGx&v_*)K3QSTT64iw{C zK6xt<1ye>?EW&$knWJVMwJIa>^)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ip~h8(LE2?gD7 ztYIHg!xIt4ucDr_z7y%nD^9o{ibvuV|4|9Uani<&pqd((-Z<(}FbyFfdvL%0#$9`1 z2nF~dKh;z(!j|P{)B~Np9|v;g|A_T1+-C?YLL@1PiAosHe&BNah830)8HIZtiN2QS#~a92{w*vU_#^Qb{jlvV2*DM{2B%yfka#W z0p#rBW{8cmKsCp)47lj*z~v6W;VS#1GRWBBmE$?oefIwh5!!p(m3@Y{M5D0l@%LjR z4O57?j(DY!`fwM`YUQn~*i3;Qo>m*_P;PqDdJuCO27hcOu`iIyU>6X54wZCGOnAV7 z@PJ)#L~?}{zjd)c^(p6ea@yG-;i;v9>7n}RV9*2Tmw=(#c@}~x=L~FTX3T1v@A*<% zw<5_AGW&5sfW@&IL~3mCOoy+tWtB^n8qwUbzC6qx>vt^cm!jsvi>_q{yd4oR_A1N( zWiDf03EkH!$Pp(5wjp)D#DAS;5*&$_gKLbD<^K;}6{rNa3$v!!1a7mGl_PojA()OuOyOnUM!$FFGmW~v zLQM_r|C!|Maab8%gP7r@b^>!~DNxU$aQ1_2KrRc+Xh1pH?LE!F3GXs%8hOUp_*IK? zW=mdltaZrzSvB%uKRcR1L+)lByM}LVDQ=9wvU8~`Q4zhq_g!pL$}X0L$X(3Q2$sFv z>A~v+ARs=?ZgiA}gVkbceIfS!R&J)I6zf&NJ3{_~N;}N++0N`R#0*fO42It-6d_oM za>ntbY&o8k7h7ce6$2M^Y=znT?TqJ}OEjH4QolpL%)hO=h{Y>j!-nJ$?o*wRhHAvn z0frqWc&Iu37}0*yew7U(*V$(WI7P5VSwD=Ys{%h-tQ}Yph5p-~cldZ9`ne{7kIr9S z`;blEE`j3o=PGMd#=0hqGEwj$=Zs>@)d_)|7`53trHFO0#E-BHUC6z literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/13d.gif b/ch12/cardset-oxymoron/13d.gif new file mode 100644 index 0000000000000000000000000000000000000000..aa30454c6cce63bb1e27cb9a3a46d30f0af30545 GIT binary patch literal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*XSdO9#p%UT4+#i1x?Bd zw5eL|4Y;}F&NB~iI1ho}jup%E|~HHX;O2>h_?l5;gGMyp~fOGj$9Z6aI$N@PS+1OWW_@RdDP~-9&SWcRW|l+ccT!J< zRF&GXCTszbo6PcVP-k@mo!26>0F}%c#S0a*N3G%{_1m)paw9n+GA9X!ugu~30 z$8u+UDL8<;(Hg->3t&eSeRf5}aydE-yqw`&BzSv6x^{P*6KvNWtAYY64vgqa{TljaYk&#?K0Z;nNgVe z>T^y>US3YB#r&82W>O_Ac)02r4ttEJ11tOvJ-CtMcs3u-9%>LF;7IKZyHNL7;k5d- z=5VA~#4!&Xja=3(g+mX^1_xtPWR*SpQ`A_a35vk$qWUE)`-s@2o)-C%@jfuvo zuBY5Bvv<>PjXUV)943$tL6J3SM|R-v<5-^u;uM7xlWY@rjvt!r{F!`zzCOP3dU1Mn7nw?K7G O>&l&ZvEwT6`2PX6Y)c~m literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/13h.gif b/ch12/cardset-oxymoron/13h.gif new file mode 100644 index 0000000000000000000000000000000000000000..845a65df1fdc87486fa86cfefa0f1651aeeb12dc GIT binary patch literal 2743 zcmZWrQEXdR8UD^a*Ecux*l~-sxwD&Hw+R>l)t#F~CPdQ>9qn2W@|c7M7{onte|M=vo6ZNmnpTa!;jr7mLTI-za1N}Z9@>hBAXyf(gUS5h`eR=7n z^Ybsgawd9l{*{GS&zwi)KfVGKz9N1C1KlsG4hs^qbWy6C-}|oA;Mq zh)b2v|M}b3mLELvw`lBAd#U^7Pm1LaPMlr(eX;!gxlexkezE+kpM2{_t+OAtE^q$s ztvlu5Y+w>tp;pj!HqJ zWJ;;6wK2D+ZQcvQV$_7qBEUWH#lz{i7u&wGo(|1DSUp!7?>t%UB@RmaX0f%s31qO| z+?aQ3>R3>Kn|G%?JwqTn*A6leL~B(x_XH8OJz%EGzjzkO%GGh-M_2+OuwhltNhweqI_)?$f<#7h$W4G>R zk>pWnTI90AM`(D#GgWl`i#dJ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Ym>KIi?n2f~EHXEQ1EK5qF)Jua7;Yz!FX+%WK}TmsNJ2)$CnTu$rYf_yv~M zkP-&Ji%d+JYih_G{p?dar8%7Iy~w<<@+VzO?OpDQH3GUWmVr#u`WP-h%-cv@COz4a z_KdzswjM#)QtayEOh&vp_RL`H!qS-`KSVwf3tRclA$&rY9cHCJr4vU=*!b;jkWEiS zP-V_Y8Aj@i1Mj`ql&reixgc1zUP|2Klnf>>GbwqpCwZB$3FOX_K07OJcq4`<9_f2T z6_HnuSO(5#S>H?ojH^P128K~tyoM^Jo+)vh^l84O*4dttW%yaqTLDkik&>YGglx~? zt{>xsLreU0ln=)*os*EsII@PD@i|f8(L%WA9GVWt0~V>9u#w_82)rd>8JdHK`y*Oa z6sU=;l;t%LP0UBa&Xk$_E^^L;zu7Q+2RSU(uYiS8u{js`Q@7p>ILY~; zrhwvedJ5*gSbylDkMaZ%lT=9lP~lkQT?p|-{W^|62Y;wW$J}JBk+k~XTi40*IOObH zd=~qSzpvfkyxv(K9b&rqyUC7je6teF$M+63x!k|`jkp|jr+}58U7DWy->F0g=n^vS jD_gwrWlD?+TlWvieYx`HW!BTijT86Z{NWyEfUo`^4gM~t literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/COPYRIGHT b/ch12/cardset-oxymoron/COPYRIGHT new file mode 100644 index 0000000..1c81a79 --- /dev/null +++ b/ch12/cardset-oxymoron/COPYRIGHT @@ -0,0 +1,10 @@ +This PySol cardset was adapted from cards-2.0.tar.gz. +http://www.waste.org/~oxymoron/cards/ + +Copyright (C) 1998 Oliver Xymoron +Copyright (C) 1999 Markus F.X.J. Oberhumer + +This cardset is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 of +the License, or (at your option) any later version. diff --git a/ch12/cardset-oxymoron/back001.gif b/ch12/cardset-oxymoron/back001.gif new file mode 100644 index 0000000000000000000000000000000000000000..463c0b04ccce7ae84feb2632d04c1c16427fedfd GIT binary patch literal 8291 zc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Koi`uMXsf|!z}&-WPt>tQ;edm$vUM3?6u!1=x4i$1K2|{Vj4Jrw z1k+WEdawhzy_R)2xrWpD)hptmlH*iYAf#Y+)QItiul)Tky6K2(5- zQnMCFBu))7;c9z)U=WPMT*Uz#{o**k2QNH;U$Whr!2E=Fm(Ydf$OK3@|LmR-(iNg* z)P~g1$CFF;W8%$0qf%xXGw<7?jfCniTuL|NjrTA%BXQ$TU%w?W`kS9p33oN!p1$!> zO>V-+Q|{)kx2}BCP5HQf+#?v>y__#wJQUA^40w>~Ewl06^#N{tv%k~m|;@=4F BZbkqA literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/back102.gif b/ch12/cardset-oxymoron/back102.gif new file mode 100644 index 0000000000000000000000000000000000000000..82b25f7b5ea89c4ed8e024e405b9855c7b2268b6 GIT binary patch literal 5513 zcmai2ZH!dq6+Z9%nD@OnPA`)sY|0E?+)=5e_431H7c{wm)uAEgqNc@m374u-QyVT0 zvsrON-w~0dA@>ZIlWy&jY+F*3y7UJj6o0fr+9syc=e)x= zGuG(cv+q6cInQ~{bIt|tTYvBH$kz3=l|Ci&kEYv4;*op5{ov;BZGUFZ#O@b=`Npr` zdH4Olo&31_{>taF|1OT7d2riPL1WufPwv?Inpza!+LV^o|TJA z?>_NK9B%x&bF`Izvh)4N}>&T|3i^ zSz>3YIRD7wrIziKPW)`$Jheu~O8#(^yjZ=faO(8J3@47`XKlE`DAoMrSDP#cftDvZ zy}U}QfypD&rI$xsRXK3v_3sKx-a8n?`HLD*YJt{{TUIdA;E=GCs?^)J9cmriRjw>g zXpObn^9PrwLF<)+vV3}ds>!lsxe{bB$^-QPM&4Rwmx^^?t$FUR`RPC{ zm50UVY8F*x&Ht@v)zYZyRc8MvhGsT?AeFCp8B zWj&&Vh*HephdM~^Gk4=?@z{=yCKNCiai%I6-kw+)b$a4(@w(#7yuG0+)9sO`ev;B+ zIrsJq&R#$ts|_yG zJI!4g2()NcKtgjc0LgxeP)tnY#F|_<*EJ5E^3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kShq>7oa~yJ5N0n`Y$LycLKaLT3uy z#4vCZ1O=5wA~$dBdl6U0LRoLJKk5fTjfkl{3_-;J-RB~}aeUdB+64Nn5Ne{@owA8K zHE|pJkj`a<^24uDBX{A?K@th-`}ud9^x+<^#XAMVu5&Mm}NrFlCVBxasg1 zUiFI!FvyO`P*zASxETPr4tRVkrB>MCcOd3MWBY~URl(3v46fnIF2i&;;-#mX(yp$I z4M8{``@c#tJc62?h!5QYnYm&oJfApZ#*x?TJXVl_aV>)=2`eVy{;`$;FGf+;}E9=86aXqpEAdaqEBs8Ur}+2ep{Qqey`Dlh7#MUOexD>(cr8!s9EMsS|58 zpn}<3=w~6|?ZDNVbil`Qz)L1kQTT&>GX>o^9697kVM4nOF(X8UeGwW)EKmc1V3G5>VSTlNju{O6qGcgw zZSeQAyKH-~Mf?>pv3UK=EX%k%L+0uTSV5<^!%n*&OdyISV*+`f9Ifv ATmS$7 literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/back111.gif b/ch12/cardset-oxymoron/back111.gif new file mode 100644 index 0000000000000000000000000000000000000000..d50079d329fa180fe4ea4aca752ad7ee70ceb8c1 GIT binary patch literal 5233 zcmdT`UuYc18UJQ>_Ov?^W={<6QAAnGI#?wlZ2P3P5Ju|VMN$PF`(9iV!YXkfhCqa4 z0wu+a54l7_G^)6|Y76el4t{8xL@#|btRN5VLlZxgP$&eww6Q6KK=aU2$o88#S<>C@ zxpEy!E707|Z)U#v{`|h*?lbd^>8~%%!xH=r?B4=_257^1fOY&m4{yH!9|GjRS?OV5~tZP02h<; zUHK#0q$69i7YK3Lf{JD&x$3eL!E_pKwdg|5Bk%SeTy?mdoR)jKm2e(Snl*==h{7GM zDXm8BFx447T@oYShMaGKBP!AJ`i-mOJxE3=_u8py;i=*Eii$%?t3Dl3N%{sEFRk?; zbl8hR)tdG3)Ks{vGve+Fq0Y*g*d6l56fEo#IwV+A$$7Ih7A{-wMG(zwGmPhCu=TYt zYtuTv`=oj+YlCyU^3z@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cbd3a5a9880cc00a392f6ac83e138f822ad90114 GIT binary patch literal 2598 zcmZ?wbhEHb^khh6_{abO4Gawo|NsA2{3jkz8JwS^P@JEWS(2Dpl&X-NSd>znTEd|C zlZBCifr&u}qyeOrf$9I0hLxw^@+TWH^>lB(x92y1QUgQFv(9DAi?*%nN;&9r{af$z zU-QyAj&XCfyYMg>S8K)_11V{N z=q2?r8XG7aFi2+T<^B(p+hG7zgvpRFU}k3GF=q4l6PXOvFYo|jBBo-f2pbDb7elRe z0vnK<#@mQ;*cv{R191P~P1c!#iV-4FK*v}kjU^v{v$cWcrI}DN?8eradJ|C)` zK?;u*ASpwrdm{7-A>R2fA#i}zIL6>Geu9CK$AFoQBf;P>!w*-J13VH64F`FcFBBZ) z5kG^UFn}qZqj8SGIH7@o&6tN&D?{3hVWyB|C6Cu>LRS7q@j8+>H=Hvf%g!3_6NK!< zWhD^O2_p5jD!Di|GJ1he` zFyPPZKy6?Jpz;EqQhK9S^^_(0L`#wiAFfcMa_<4n&kwHVD@lAI9@7v}Mz^0xx0CCY; A{r~^~ literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/back192.gif b/ch12/cardset-oxymoron/back192.gif new file mode 100644 index 0000000000000000000000000000000000000000..e7111b3aa2b5425b1ab4be93af14ef87d32472f0 GIT binary patch literal 2598 zcmbuBZ%7ky7{{Nx)AMRS(RaHg$oWDrl5z9aS_yJRWtNnXl+mJ_)2Sr*XHxVJe?wC= zjp$7aq9mg5O$b5yBI2es3WxY2i2lhS&=7+nh|K7^xqr5`n{FH2J={Id^L;+I`#!9) zYQJ@-y$bB`4OTxG6aYn0ivH+p&L3@Sv8EnW7O&PL8*?`&{2c0ti{76Cv&X|Nzz z3ZznvN2kB!Im(EktB>cNuH@B=&^tfyfV%hO(O|=5^_w5V3%~9(F+Sbq{=JA4E^a+7 zsHcMbhqZH3-)_lCy=y#s>y-26+k{iDlg)BkYKpB^f$wo+lfbo`TuHwI$A_{+Yx(wY zlswyI3ilKX3eB3`KTQtl1f!qjBpD%wR|8}HHA3JynRmdjPEqeo@ZqGyfaNKQL;`)_ z_X$U&J`n1dm>j-BGm$E|TrSac7VAVK9d_RpgWhTLBnc>|Bx1V{kBd2e8N<{NL23>* z!8A*ICnqmn#m+lUV4&C zrD;nxE5}V~VcHJANEh?@k$6eB!6wmqk2l-d{@;+t1_=n(2p*#egkKG0o7}&$gh{u5Z5|AmCLkR>U zfgl5^?l zA$>zzJUy*flD~EFzx}u+Gy1V{IsLQh?-z_J+4)~ z6LaloPQ<_%w9T%TttP1UjLmz$Flt(JBq2P*hh(cGYBX^%8m6^zVzWc;dS{QUi`YXe z{#=p0dR1I3PeYz%nW*l@FP!^y@6I~xU7H9E{{Ea+-n xP}O+BtC1nQ!9cnpp_@vOyHS^Ao4^gH1at1K`{sS$o0-!C zeX*nI0Z79-ls*|kfBng+vty%TZfta9GCeXeEDoh7GP&VN2>s#_0HH^R>Pf(93Hk1; zFFS^!_PeF9TRiy)?|jy^tEsdegv9QX|4L|^eywvEz=#le;{wovGsT>$3E@N zgH1p26xfYn*TzKX{Mq64u!EKb)&zE)Su<+F0ASZ2;M``&w3_Y0^xE$J2DTD05j``5d9w1TehK5(SkbqC_LP39HNa@+~Z5g&PgvSFQ SwSiBOFFu^R@Hxm1;_-hHjWxOe literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/bottom03.gif b/ch12/cardset-oxymoron/bottom03.gif new file mode 100644 index 0000000000000000000000000000000000000000..5357ddc41b9ae71f3e75d4293e9c564efdbc0106 GIT binary patch literal 864 zcmYL{Ur19?9LIn6oWuUK%}yX?#^Sgvi*30Lwj4p+>%u?a!-Za=2f53HG(qssLkr@L znL5O{5QOw}k%E~KrVu?OTuLnLp*@V0J%nhK1c8AN5oEtRt?tw3_x=8UzwbSV)7swB zluWln8oop2)4{SVq`Kcn)SH+3`@~>>U(ZmwXP{ejr3bDJb`L?_PbL9K5V8mCQ6Re= z`pmm;2fJcYabn@)%U@n*wch`HRBWwGw|U+i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Xf1f3OGuL9?E!7Xee~ zA-A4?-PYfN@)z&ETm9)~2}%H0`_*7KbibeM*)xwGaT-cPi16i2!OD{^6OUgnWi@2I)XZ9I+XV%Tv`V^t&*GK7b0fBD4Jjmd=>Al_df>nh3BX~re0GPB z1`QD&LQoD0AxPm|^aIcGdJ?K+|22q9EuT0xP^mY7LLg!-*33Al2^tUv8tMkJ^L8v_ z;!(oEJUcxbiT=A>Z_zRFGUDsA>Ctf%$Q*@kpI9pgD_|2?0Nl=WHLAy%5JjTC&;`lV zhw@JqF_FEJ!0Sgnz2FVpvfuPP;isOg3`{+%)KEyoqak$8Za!jQO-qeyp(@> z$5V(+SjdRl7c+vKi{JA^FBgk}``AWvi`@rS-{PRTJNf1?StR4m2Oc$(O}7a<^Vy#n5|FXPzQBD2OUS!d%8m*PB5u>Yd3-S8M|~S7IF- zstIx{D)8>I2?RN(7fHOtzEB-OF%ol@v6TK*aojUCSEQvcc?_kA=;EBw?{L`cL}emA zwh~px?D7T#CSV+g>XAzW@ECrH6X4JfzXtT-p-<3%gs#@L4uSeh5kk6Ercg!flDgd) ztp`@vq=!nvGY%B6p&7u)t971|a{!hu3#Z=Fxtj27WoY@yab}vgkf|$gEnXS)gX)x%euY}Fji-1lvI<~A{k^mMy Q3-pzA?fezQ)AMrh4_(YW-2eap literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/bottom06.gif b/ch12/cardset-oxymoron/bottom06.gif new file mode 100644 index 0000000000000000000000000000000000000000..fc5b61ae5e2c9daaf23951a8029776be0701d16d GIT binary patch literal 1808 zcmbVMOK1~O6us|d@|^U8H58hRf-f~KK}wA=i$+B!iZv}!LUki#k=PX5Qm{Y#tzP;O z(JF}+yB)PIL|1;GipVHMML{YqbRp7O7j{vw3q=u(Zzh@itZg+D=G}pN&OPVcVfHpP zHu$1V5QPQMe++`bAg>(1szN6Z9POfgN4q-uqaD3%v^Clr>uc)=#}5GkAgI#-8WeCU z$ZouxU)}0KQ|In{c=)qSU?>FUKmQ82p!wrqaN`)7G%KhbBt|kvM0P)m)jk2OrG(+a zLq?e^8G8C|BB`LlD-oY=*m^bs**2rS_)N+V!l%27&eN(h1MK=+5& zTiZcFjDQ50A|*jgR^6Y7K(r=gbpN#oP|uuMs50cV9KWtCuUXvPw!1KT?B z3P7x4Cayo)sTvrrI6OTQAE6Q8Ve*vp8yXTFK-3e|%%kJMX*Wy4KO3(Uny6h20}nbT zJLAafqdalWOsJcTnuu~8TJx#=W1YkxfKWoUbsqCIrnR8=H)_n>lT5@BI-)phN{fT{`9u!(kkCIK5$J;&<@SwXYru)o6?oJrA-XJz01v{wnbQBof+ zK?32@*Ao?(WYf;&?vQd}8I@(|U^I}9JmVvp(V~ao+!JXLZANpRg;Yr9JI$^yS6N&& ztR70+d5uNljwFv85tyY-zGo{y2(ugbA)MV#^Yns4_Ax^QA5)t)L+;eCesQETWS0 zJ_p=5CklKqORLNm$$JA(zc$WF^DSpZmV*l7_u36Bavy@HxyclLtJ{r>vrH3v7`t#0 r{l|{pY^KwAu^n+7cd9Zr literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/bottom07.gif b/ch12/cardset-oxymoron/bottom07.gif new file mode 100644 index 0000000000000000000000000000000000000000..8c8f330c8ff9165c82f2a0a988c081e96631a35c GIT binary patch literal 1858 zcmbVKUr1A76hGg$yUTU0nj$zy(w(hgAu*PPSr0dhImd!!f1Z5UaE6wksFd~e&HRUo zY*VNQA1)+>_|QWXGeSm5iHZsJP%kmUhlF~tCnIQm_ilIId$$bR9p63o0PTOj`k`2Btw*?*S>?q2Ea;Cnhd+IvIo-K~5}s5{)#+6(rd3<5wWo8HpfHD6sLKXPF-1i@UfEJA+Y6BZ#v#+4wdK-4W0x88r zu=XXO>=O&T`Iv}_Nc%)1soJ{HAmq}Nbp1Ofyl5Wk(xF8ZB*}9N1H0kD2&E7J!H(t! z50|uohzJWd$OdT}goUJQgJoDL2`Sls4ZOU2)5w%5_#BZ9tb$lmjSaL3A`lFwT>}R< zR})d`$nXd(GcsA}`ZruEQQyB-S=_AiBk=?QZACeA0U4Gc=nSSoIFEfr;#F*;Otdfb zKpfbOl!x}I4Fr}OVM4=|b_y+(8l*mg!mtJF?xatLB|cs;G?2`(5ae0z%hKDZKy1GB z$$o*eN^%04Be+a2)iq>3VQtzIpOgjBBM|&LWzEQqBD{LhH7+;Le47=Jj&BuiAn__vi~dMxvwiJ4kx2^qT9|#6m2dDwquMU&I^`+{iUDm-=3lC%zWzMBZ0Ov z+bI=nmoUO~y)Whx`K=VTW%p)6BB$}*-HVq!4n>+)FmK?vo8|v8qw7Zv_=IlYxe^9m ceA2RK_lRKtrmkVA;v*^3oy6-?w0Us$5BiBQhyVZp literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/config.txt b/ch12/cardset-oxymoron/config.txt new file mode 100644 index 0000000..cc42839 --- /dev/null +++ b/ch12/cardset-oxymoron/config.txt @@ -0,0 +1,6 @@ +PySol solitaire cardset;4;.gif;1;52;0 +1000_oxymoron_073097;Oxymoron +73 97 8 +18 18 7 7 +back001.gif +back001.gif;back101.gif;back102.gif;back111.gif;back191.gif;back192.gif diff --git a/ch12/cardset-oxymoron/l01.gif b/ch12/cardset-oxymoron/l01.gif new file mode 100644 index 0000000000000000000000000000000000000000..da0b22603af44c2f359b097ad6b675f9ba1d39b1 GIT binary patch literal 1772 zcmb7DU1$?o6h8OP57X=v%UI|%NPDBHsFdZB4XoCExRJ$H5sCO(Fu_DC6fB+kuzk8= z-9@yPL>Bf%a99NuMf?M+h|JW|KC}<<&4(gId{Bzui=e0*?@ThuB)y3EA4ku9g%$;WsKj<l`;rBMg;xGY&Bx4Mj!X$B_dRGdX5CI)Je_sWTYFfqLbK&9UXTGSB0nC#fV<^ zBC%Boi%5vx)3F+65r5E(GZ~Qj^eKF)pCRi~+-I?oq+UM?RhDi-BT^UrInvCMl8_*^ zT3DtjcPFRGSWN*+7LiqxmH~X0+Q^!2DXT*LGCRQX2phHHDe55WY*o=1l1%S7zpieQ zR;3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`&KgHr5oQWj5x+csQj8u!sI;NdtF0as zbX#_FQ9%BjInq7QkHucv?zfZkJX^!EURq!UkX$Ele%AK`eO9V8*XZFL!uJ3E?%7Gs ay{P_g_ml#ppD1ic5bM2dtGu>K$uEH)Jn0k1ivHbMl^qCMzsVyXuf z*-AmYt#}d<3JU%pvPx0WOY|fn5`Pdp2t5fZ7-u%S=_b~Q*)a2F_PuYu@4YuWF}Zha z`_v?+unhOdF#Kz1R^sM2Yvz z7oNPnJ8zTD$Er5QcAP7r?dH38&-3(t@$5`jv`tFP+4XR)S3DHNPyih!_s(pHR$vpR zA_>oECQ+tN=94O`!io6ae>L){(JzWT=*PE#l893~J0kV*B-mgQ`gL@%LJXWsr zpg1&)FA&$ohs3xgEQ?4-RpdGexd7e} zkpoOQEByycYehlGWmN&iK*?JYEpwY<-AIj*mbT^!1=$`7h;v_uGS`Oi(exRq3+MTn zE^3)MW6K*e{gNu0CKebB+83j|f`L7gUX&8Fu1SM!aY>XYZ#fsa1gWN?E9F6jkPQ-` z7J56BON2aeLZ(54R;p?jPP1sls`}zu+7^ANxKZ^~ix;7VN8Gt-`Q_8&B1gp(?@A6$ zH0vdc8Vem*175PaE0+kH5uZ`K0RfQn7+LR~HIdBe4n}grTed6LFD{HtrRU2mJnlra zyWkCtaNa@mSqeQs^eQM%B4;1cBJ`5`US3t^QbEH-&DO;%yaaTAnn zy;4QrDq+3&hE9GSHD)>_`y_cH;vnBl#Z?dX=^v5k*Lpa&*W{JYaL se*rMpq|&7~np|8dOn@afRf=Nb|J7?6ux=;+5;bbKZ+`95dDHIv4X`po&j0`b literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/l04.gif b/ch12/cardset-oxymoron/l04.gif new file mode 100644 index 0000000000000000000000000000000000000000..cc88f42bfaeeea5fb3c20cb879c3401bd04eff0a GIT binary patch literal 1832 zcmb7EUr19?82`@M-DQ($Dg(Ebbq6Cx47rF8YCfE))C?a+KDLKDHe-UJs1NmamL_5l zn-A4Xa06c=f}kEOBCa9!XA*m>hX^SNdy3m$stI>4wxSf!9Q*BYavCn?^1^7+MYkHkqFocq5zgyF)M+2J#H$eL3p83=IMx@k;(oj&~v1f+q}>Kh~0 zm5;A~T*>RC`pRWDyL%Tk*oE2f+IyZoPs~r&Wa~uZM&HZ1gYv-%UWfw=l4mzgwPrvk zT!sKxK`8)fW~f`TBnuF+(fRmCZNQ&(MEW+A0+)_fr)Y=y3rq z`%+PYZ_qX@EAe%Dg6UB@Ty2w}bI92l%^v^BKgC{U|E_RMqB_y+0Z{mShm!f zdxfSd_%yb8%VF`E{_%BvCx7}}2{8l-qi3_+Lq%DV3Ke;kHQDbg=au$4SC+8bxuIxn zb*%QuF798 zAZ%G=R+t8IufBPA<68w<@iuXh}2Pu z+Wm}oyv>5c#vVo_V%=B2bvNUH)_3m%@*^#q?tyO|#r^$4Y+o(ScQCn`ja*a=ICLpZ nM~p7@Hb{xOJwje=c%uF2?p-c`rc3yDuFpJubcK3ww$Adha-|%hYnQ%01q!7o ziI+&ide-CFU>WIqe@LJFJbAi*=qBj!3BY6eu^)ZkPTyZv3%gk@=G$(*p4r!K{kEBH zG5XSqyWuXV@DUo)jpD0mt;a!Whp4n@JS_Nj?O>pxdfp88&e|Tl?C`;6pf*y`C-Z`l7vd2z)|zsK+u)dBM;%98Q(y5!lC6&f(MKF|dJaARBif4*$(`WWdeB@&*|H07F-K AssI20 literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/shadow00.gif b/ch12/cardset-oxymoron/shadow00.gif new file mode 100644 index 0000000000000000000000000000000000000000..cc0560b2160985ecf7c7c6cf5c6a400490c95e8a GIT binary patch literal 722 zcmZ?wbhEHb^kCp)_`m=L4GfC^!~-gW^K%r6^K&vw5;KcZ6_OK+Qi@Yc7!-f9FfuSO zGU$Mmf;2HO{qN~tdHO8}6Nf?r0~5!CpZrD+3@lK@aa>M-ff0ffxVe}c7!(*d7??nm zgjX^WZ$_6q5>Mi^G!l9Lvum%8KuruHQ literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/shadow01.gif b/ch12/cardset-oxymoron/shadow01.gif new file mode 100644 index 0000000000000000000000000000000000000000..21e8cb263d57723a16165327fecf0ce335752409 GIT binary patch literal 673 zcmZ?wbhEHbWM>Fw_`m=L4GfC^!~-gW^K%r6^K&vw5;KcZ6_OK+Qi@Yc7!-f9FfuSO zGU$Mmf;2HO{pVp?C?K$ai9?}*0ZgzsFknR-3``9S3JfGu0t^ES6&M*8>Iu6c|XR1Q-SuDljwvy$N(TcE*1^ saw9?NKL>*Y0|U#5CH{|GuY-MlcQE)Lm_rp9fLRon;i$Iu6c|XR1Q-SuDljwvy$N(TcE*1^ yaw9?NKL>*Y0|U#5CH{|GuY-L)DEtr1p$ZJZEDFqU^k()9n9b-GJ1{aZSOWkfk84r@ literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/shadow07.gif b/ch12/cardset-oxymoron/shadow07.gif new file mode 100644 index 0000000000000000000000000000000000000000..b6cd41d04f66d9b8dad6a1c30db29557e167e89d GIT binary patch literal 1662 zcmZ?wbhEHbWM|mV@PPpg8WIu6c|XR1Q-SuDljwvy$N(TcE*1^ zaw9?NKL>*Y0|U#5CH{|GuY-L)DEtr1p$ZJZEDFqU^k)7aFq;R5#a85oJ1YZ&H2@GA Bc7Ff> literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/shadow08.gif b/ch12/cardset-oxymoron/shadow08.gif new file mode 100644 index 0000000000000000000000000000000000000000..dea6b926befe4c0590686285e09a5eea620bc4c3 GIT binary patch literal 1835 zcmZ?wbhEHbWM{a@@PPpg8WIu6c|XR1Q-SuDljwvy$N(TcE*1^ zaw9?NKL>*Y0|U#5CH{|GuY-L)DEtr1p$ZJZEDFqU^k)7aFq;R5#m@&Q-0ACk5e5cp E072-1-v9sr literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/shadow09.gif b/ch12/cardset-oxymoron/shadow09.gif new file mode 100644 index 0000000000000000000000000000000000000000..3c85f2d4be3b3fd9c0962c3b90cfeecc4c584dca GIT binary patch literal 2009 zcmZ?wbhEHbWM_EH@PPpg8WIu6c|XR1Q-SuDljwvy$N(TcE*1^ zaw9?NKL>*Y0|U#5CH{|GuY-L)DEtr1p$ZJZEDFqU^k)7aFq;R5#s3E=+y{s685pJx NNUFo{`v3+8YXFO}jSK() literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/shadow10.gif b/ch12/cardset-oxymoron/shadow10.gif new file mode 100644 index 0000000000000000000000000000000000000000..2b47bfa1e9fc56d2e805b1b92642b3b276b36c64 GIT binary patch literal 2184 zcmZ?wbhEHbWM}xw@PPpg8WIu6c|XR1Q-SuDljwvy$N(TcE*1^ zaw9?NKL>*Y0|U#5CH{|GuY-L)DEtr1p$ZJZEDFqU^k)7aFq;R5#s3E=+y{s685n@& W-vFe#!Qy)k1{aEb@4(2wU=09H@|bM^ literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/shadow11.gif b/ch12/cardset-oxymoron/shadow11.gif new file mode 100644 index 0000000000000000000000000000000000000000..85bedaab728abca6a920a74f783628d1c60c4941 GIT binary patch literal 2357 zcmZ?wbhEHbWM^P!{J;PP4GfC^!~-gW^K%r6^K&vw5;KcZ6_OK+Qi@Yc7!-f9FfuSO zGU$Mmf;2HO{pVp?C?K$ai9?}*0ZgzsFknR-3``9S3JfGu0t^ES6&M;A7?^vgct2ZjHEIaGlGm_>mZj^51w17`E!u=xJ~h5O*}Jp%)< W{2PE&H&}en!SHc}`JR=5!5RRZ-l3cT literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/shadow12.gif b/ch12/cardset-oxymoron/shadow12.gif new file mode 100644 index 0000000000000000000000000000000000000000..0f5ab82e8667ea9f68132b13f0381c7f83aaab51 GIT binary patch literal 2531 zcmZ?wbhEHbWM`0M{J;PP4GfC^!~-gW^K%r6^K&vw5;KcZ6_OK+Qi@Yc7!-f9FfuSO zGU$Mmf;2HO{pVp?C?K$ai9?}*0ZgzsFknR-3``9S3JfGu0t^ES6&M;A7?^vgct2ZjHEIaGlGm_>mZj^51w17`E!u=xJ~h5O*}Jp%)< h{2PE&H&}en!2qiN=$+>VkM9|n<_~J$i!d-)0|3-dto#4~ literal 0 HcmV?d00001 diff --git a/ch12/cardset-oxymoron/shadow13.gif b/ch12/cardset-oxymoron/shadow13.gif new file mode 100644 index 0000000000000000000000000000000000000000..3d17c17387258de3bf14b8b609c4100a98ec2ec1 GIT binary patch literal 2711 zcmZ?wbhEHbWM|N3{J;PP4GfC^!~-gW^K%r6^K&vw5;KcZ6_OK+Qi@Yc7!-f9FfuSO zGU$Mmf;2HO{pVp?C?K$ai9?}*0ZgzsFknR-3``9S3JfGu0t^ES6&M;A7?^vgct2ZjHEIaGlGm_>mZj^51w17`E!u=xJ~h5O*}Jp%)< r{2PE&H&}en!2qiN=$+>VkMDu)pAqeQhK687(F<%CQUe7rFjxZsg@Ck6 literal 0 HcmV?d00001 From 97e50915f98bfe8b43d768f8a95e29a2dc1021d2 Mon Sep 17 00:00:00 2001 From: Allen Downey Date: Thu, 3 Mar 2016 16:20:06 -0500 Subject: [PATCH 02/29] Adding code for chapters 13-14 --- ch13/Card.java | 1 + ch13/Deck.java | 197 +++++++++++++++++++++++++++++++++++++++ ch13/Test.java | 42 +++++++++ ch14/Card.java | 1 + ch14/CardCollection.java | 129 +++++++++++++++++++++++++ ch14/Deck.java | 18 ++++ ch14/Eights.java | 145 ++++++++++++++++++++++++++++ ch14/Hand.java | 23 +++++ ch14/Player.java | 124 ++++++++++++++++++++++++ ch14/Test.java | 22 +++++ 10 files changed, 702 insertions(+) create mode 120000 ch13/Card.java create mode 100644 ch13/Deck.java create mode 100644 ch13/Test.java create mode 120000 ch14/Card.java create mode 100644 ch14/CardCollection.java create mode 100644 ch14/Deck.java create mode 100644 ch14/Eights.java create mode 100644 ch14/Hand.java create mode 100644 ch14/Player.java create mode 100644 ch14/Test.java diff --git a/ch13/Card.java b/ch13/Card.java new file mode 120000 index 0000000..1c6483e --- /dev/null +++ b/ch13/Card.java @@ -0,0 +1 @@ +../ch12/Card.java \ No newline at end of file diff --git a/ch13/Deck.java b/ch13/Deck.java new file mode 100644 index 0000000..d567844 --- /dev/null +++ b/ch13/Deck.java @@ -0,0 +1,197 @@ +import java.util.Arrays; +import java.util.Random; + +/** + * A deck of playing cards (of fixed size). + */ +public class Deck { + + // This is a class variable so we don't have to create + // a new Random object every time we call randomInt. + private static Random random = new Random(); + + private Card[] cards; + + /** + * Constructs a standard deck of 52 cards. + */ + public Deck() { + this.cards = new Card[52]; + int index = 0; + for (int suit = 0; suit <= 3; suit++) { + for (int rank = 1; rank <= 13; rank++) { + this.cards[index] = new Card(rank, suit); + index++; + } + } + } + + /** + * Constructs a deck of n cards (null). + */ + public Deck(int n) { + this.cards = new Card[n]; + } + + /** + * Gets the internal cards array. + */ + public Card[] getCards() { + return this.cards; + } + + /** + * Returns a string representation of the deck. + */ + public String toString() { + return Arrays.toString(this.cards); + } + + /** + * Swaps the cards at indexes i and j. + */ + public void swapCards(int i, int j) { + Card temp = this.cards[i]; + this.cards[i] = this.cards[j]; + this.cards[j] = temp; + } + + /** + * Chooses a random number between low and high, including both. + */ + public int randomInt(int low, int high) { + int range = high - low + 1; + return low + random.nextInt(range); + } + + /** + * Randomly permutes the array of cards. + */ + public void shuffle() { + for (int i = 0; i < this.cards.length - 1; i++) { + int j = this.randomInt(i, this.cards.length - 1); + this.swapCards(i, j); + } + } + + /** + * Finds the index of the lowest card + * between low and high inclusive. + */ + public int indexLowest(int low, int high) { + int index = low; + Card minCard = this.cards[low]; + for (int i = low + 1; i <= high; i++) { + Card card = this.cards[i]; + if (card.compareTo(minCard) < 0) { + index = i; + minCard = card; + } + } + return index; + } + + /** + * Sorts the cards (in place) using selection sort. + */ + public void selectionSort() { + int high = this.cards.length - 1; + for (int i = 0; i < this.cards.length; i++) { + int j = this.indexLowest(i, high); + this.swapCards(i, j); + } + } + + /** + * Returns a subset of the cards in the deck. + */ + public Deck subdeck(int low, int high) { + Deck sub = new Deck(high - low + 1); + for (int i = 0; i < sub.cards.length; i++) { + sub.cards[i] = this.cards[low + i]; + } + return sub; + } + + /** + * Combines two previously sorted subdecks. + */ + public static Deck merge(Deck d1, Deck d2) { + Card[] c1 = d1.cards; + Card[] c2 = d2.cards; + Deck result = new Deck(c1.length + c2.length); + Card[] c3 = result.cards; + int i = 0; // index in c1 + int j = 0; // index in c2 + + // for each index in the result + for (int k = 0; k < c3.length; k++) { + int choice; + + // determine which card to merge next + if (i >= c1.length) { + choice = 2; // c1 is empty + } else if (j >= c2.length) { + choice = 1; // c2 is empty + } else if (c1[i].compareTo(c2[j]) < 0) { + choice = 1; // c1 is lower + } else { + choice = 2; // c2 is lower + } + + // store the chosen card in the result + if (choice == 1) { + c3[k] = c1[i]; + i++; + } else { + c3[k] = c2[j]; + j++; + } + } + return result; + } + + /** + * Returns a sorted copy of the deck using merge sort. + */ + public Deck mergeSort() { + + // 0 or 1 cards, already sorted + int len = this.cards.length; + if (len < 2) { + return this; + } + + // cut the deck about in half + int mid = len / 2; + Deck d1 = this.subdeck(0, mid - 1); + Deck d2 = this.subdeck(mid, len - 1); + + // sort each half and merge + d1 = d1.mergeSort(); + d2 = d2.mergeSort(); + return merge(d1, d2); + } + + /** + * Reorders the cards (in place) using insertion sort. + */ + public void insertionSort() { + for (int i = 1; i < this.cards.length; i++) { + Card card = this.cards[i]; + this.insert(card, i); + } + } + + /** + * Helper method for insertion sort. + */ + private void insert(Card card, int i) { + int j = i; + while (j > 0 && card.compareTo(this.cards[j - 1]) < 0) { + this.cards[j] = this.cards[j - 1]; + j--; + } + this.cards[j] = card; + } +} diff --git a/ch13/Test.java b/ch13/Test.java new file mode 100644 index 0000000..c5431ee --- /dev/null +++ b/ch13/Test.java @@ -0,0 +1,42 @@ +/** + * Test sorting algorithms for decks of cards. + */ +public class Test { + + /** + * Checks that the deck is sorted. + */ + public static void checkSorted(Deck deck) { + Card[] cards = deck.getCards(); + for (int i = 0; i < cards.length - 1; i++) { + if (cards[i].compareTo(cards[i + 1]) >= 0) { + System.out.println("Card #" + i + " not sorted!"); + } + } + } + + /** + * Demonstrates how to call the sorting methods. + */ + public static void main(String[] args) { + Deck deck; + + System.out.println("Testing selection..."); + deck = new Deck(); + deck.shuffle(); + deck.selectionSort(); + checkSorted(deck); + + System.out.println("Testing mergesort..."); + deck = new Deck(); + deck.shuffle(); + deck = deck.mergeSort(); + checkSorted(deck); + + System.out.println("Testing insertion..."); + deck = new Deck(); + deck.shuffle(); + deck.insertionSort(); + checkSorted(deck); + } +} diff --git a/ch14/Card.java b/ch14/Card.java new file mode 120000 index 0000000..1c6483e --- /dev/null +++ b/ch14/Card.java @@ -0,0 +1 @@ +../ch12/Card.java \ No newline at end of file diff --git a/ch14/CardCollection.java b/ch14/CardCollection.java new file mode 100644 index 0000000..5129496 --- /dev/null +++ b/ch14/CardCollection.java @@ -0,0 +1,129 @@ +import java.util.ArrayList; +import java.util.Random; + +/** + * A collection of playing cards. + */ +public class CardCollection { + + private String label; + private ArrayList cards; + + /** + * Constructs an empty collection. + */ + public CardCollection(String label) { + this.label = label; + this.cards = new ArrayList(); + } + + /** + * Returns the label. + */ + public String getLabel() { + return label; + } + + /** + * Returns the number of cards. + */ + public int size() { + return cards.size(); + } + + /** + * True if the collection is empty, false otherwise. + */ + public boolean empty() { + return cards.size() == 0; + } + + /** + * Randomly permute the cards. + */ + public void shuffle() { + Random random = new Random(); + for (int i = size() - 1; i > 0; i--) { + int j = random.nextInt(i); + swapCards(i, j); + } + } + + /** + * Swaps the cards at indexes i and j. + */ + public void swapCards(int i, int j) { + Card temp = cards.get(i); + cards.set(i, cards.get(j)); + cards.set(j, temp); + } + + /** + * Moves n cards from this collection to the given collection. + */ + public void deal(CardCollection that, int n) { + for (int i = 0; i < n; i++) { + Card card = popCard(); + that.addCard(card); + } + } + + /** + * Moves all remaining cards to the given collection. + */ + public void dealAll(CardCollection that) { + int n = size(); + deal(that, n); + } + + /** + * Adds the given card to the collection. + */ + public void addCard(Card card) { + cards.add(card); + } + + /** + * Returns the card with the given index. + */ + public Card getCard(int i) { + return cards.get(i); + } + + /** + * Returns the last card. + */ + public Card last() { + int i = size() - 1; + return cards.get(i); + } + + /** + * Removes and returns the card with the given index. + */ + public Card popCard(int i) { + return cards.remove(i); + } + + /** + * Removes and returns the last card. + */ + public Card popCard() { + int i = size() - 1; + return popCard(i); + } + + /** + * Returns a string representation of the card collection. + */ + public String toString() { + return label + ": " + cards.toString(); + } + + /** + * Gets the internal cards array (should only be used for testing). + */ + public Card[] getCards() { + return (Card[]) cards.toArray(); + } +} diff --git a/ch14/Deck.java b/ch14/Deck.java new file mode 100644 index 0000000..10ba798 --- /dev/null +++ b/ch14/Deck.java @@ -0,0 +1,18 @@ +/** + * A deck of playing cards. + */ +public class Deck extends CardCollection { + + /** + * Constructs a standard deck of 52 cards. + */ + public Deck(String label) { + super(label); + + for (int suit = 0; suit <= 3; suit++) { + for (int rank = 1; rank <= 13; rank++) { + addCard(new Card(rank, suit)); + } + } + } +} diff --git a/ch14/Eights.java b/ch14/Eights.java new file mode 100644 index 0000000..78a767b --- /dev/null +++ b/ch14/Eights.java @@ -0,0 +1,145 @@ +import java.util.Scanner; + +/** + * Simulates a game of Crazy Eights. See + * https://en.wikipedia.org/wiki/Crazy_Eights + * for basic play and scoring rules. + */ +public class Eights { + + private Player one; + private Player two; + private Hand drawPile; + private Hand discardPile; + private Scanner in; + + /** + * Initializes the state of the game. + */ + public Eights() { + Deck deck = new Deck("Deck"); + deck.shuffle(); + + // deal cards to each player + int handSize = 5; + one = new Player("Allen"); + deck.deal(one.getHand(), handSize); + + two = new Player("Chris"); + deck.deal(two.getHand(), handSize); + + // turn one card face up + discardPile = new Hand("Discards"); + deck.deal(discardPile, 1); + + // put the rest of the deck face down + drawPile = new Hand("Draw pile"); + deck.dealAll(drawPile); + + // create the scanner we'll use to wait for the user + in = new Scanner(System.in); + } + + /** + * Displays the state of the game. + */ + public void displayState() { + one.display(); + two.display(); + discardPile.display(); + System.out.print("Draw pile: "); + System.out.println(drawPile.size() + " cards"); + } + + /** + * Returns true if either hand is empty. + */ + public boolean isDone() { + return one.getHand().empty() || two.getHand().empty(); + } + + /** + * Moves cards from the discard pile to the draw pile and shuffles. + */ + public void reshuffle() { + // save the top card + Card prev = discardPile.popCard(); + + // move the rest of the cards + discardPile.dealAll(drawPile); + + // put the top card back + discardPile.addCard(prev); + + // shuffle the draw pile + drawPile.shuffle(); + } + + /** + * One player takes a turn. + */ + public void takeTurn(Player player) { + Card prev = discardPile.last(); + Card next = player.play(this, prev); + + System.out.println(player.getName() + " plays " + next); + System.out.println(); + + discardPile.addCard(next); + } + + /** + * Returns a card from the draw pile. + */ + public Card draw() { + if (drawPile.empty()) { + reshuffle(); + } + return drawPile.popCard(); + } + + /** + * Waits for the user to press enter. + */ + public void waitForUser() { + in.nextLine(); + } + + /** + * Switches players. + */ + public Player nextPlayer(Player current) { + if (current == one) { + return two; + } else { + return one; + } + } + + /** + * Plays the game. + */ + public void playGame() { + Player player = one; + + // keep playing until there's a winner + while (!isDone()) { + displayState(); + waitForUser(); + takeTurn(player); + player = nextPlayer(player); + } + + // display the final score + one.displayScore(); + two.displayScore(); + } + + /** + * Creates the game and runs it. + */ + public static void main(String[] args) { + Eights game = new Eights(); + game.playGame(); + } +} diff --git a/ch14/Hand.java b/ch14/Hand.java new file mode 100644 index 0000000..a65b7f5 --- /dev/null +++ b/ch14/Hand.java @@ -0,0 +1,23 @@ +/** + * A hand of playing cards. + */ +public class Hand extends CardCollection { + + /** + * Constructs an empty hand. + */ + public Hand(String label) { + super(label); + } + + /** + * Prints the label and cards. + */ + public void display() { + System.out.println(getLabel() + ": "); + for (int i = 0; i < size(); i++) { + System.out.println(getCard(i)); + } + System.out.println(); + } +} diff --git a/ch14/Player.java b/ch14/Player.java new file mode 100644 index 0000000..c9c9695 --- /dev/null +++ b/ch14/Player.java @@ -0,0 +1,124 @@ +/** + * A player in a game of crazy eights. + */ +public class Player { + + private String name; + private Hand hand; + + /** + * Constructs a player with an empty hand. + */ + public Player(String name) { + this.name = name; + this.hand = new Hand(name); + } + + /** + * Gets the player's name. + */ + public String getName() { + return name; + } + + /** + * Gets the player's hand. + */ + public Hand getHand() { + return hand; + } + + /** + * Removes and returns a legal card from the player's hand. + */ + public Card play(Eights eights, Card prev) { + Card card = searchForMatch(prev); + if (card == null) { + card = drawForMatch(eights, prev); + } + return card; + } + + /** + * Searches the player's hand for a matching card. + */ + public Card searchForMatch(Card prev) { + for (int i = 0; i < hand.size(); i++) { + Card card = hand.getCard(i); + if (cardMatches(card, prev)) { + return hand.popCard(i); + } + } + return null; + } + + /** + * Draws cards until a match is found. + */ + public Card drawForMatch(Eights eights, Card prev) { + while (true) { + Card card = eights.draw(); + System.out.println(name + " draws " + card); + if (cardMatches(card, prev)) { + return card; + } + hand.addCard(card); + } + } + + /** + * Checks whether two cards match. + */ + public static boolean cardMatches(Card card1, Card card2) { + if (card1.getSuit() == card2.getSuit()) { + return true; + } + if (card1.getRank() == card2.getRank()) { + return true; + } + if (card1.getRank() == 8) { + return true; + } + return false; + } + + /** + * Calculates the player's score (penalty points). + */ + public int score() { + int sum = 0; + for (int i = 0; i < hand.size(); i++) { + Card card = hand.getCard(i); + int rank = card.getRank(); + if (rank == 8) { + sum -= 20; + } else if (rank > 10) { + sum -= 10; + } else { + sum -= rank; + } + } + return sum; + } + + /** + * Returns a string representation of the player. + */ + public String toString() { + return name + ": " + hand; + } + + /** + * Displays the player's hand. + */ + public void display() { + hand.display(); + } + + /** + * Displays the player's name and score. + */ + public void displayScore() { + System.out.println(name + " has " + score() + " points"); + } +} diff --git a/ch14/Test.java b/ch14/Test.java new file mode 100644 index 0000000..0e5c243 --- /dev/null +++ b/ch14/Test.java @@ -0,0 +1,22 @@ +/** + * Test code for Deck and Hand. + */ +public class Test { + + /** + * Test code. + */ + public static void main(String[] args) { + Deck deck = new Deck("Deck"); + deck.shuffle(); + System.out.println(deck); + + Hand hand = new Hand("Hand"); + deck.deal(hand, 5); + hand.display(); + + Hand drawPile = new Hand("Draw Pile"); + deck.dealAll(drawPile); + System.out.println(drawPile.size()); + } +} From 76175fddeffef62e6bb865ca4edf74e9f99517c6 Mon Sep 17 00:00:00 2001 From: Allen Downey Date: Thu, 3 Mar 2016 16:25:42 -0500 Subject: [PATCH 03/29] Update README.md --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e3a6b5..54c33b7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ # ThinkJavaCode -Supporting code for Think Java by Allen Downey and Chris Mayfield. +Supporting code for *Think Java* by Allen Downey and Chris Mayfield. + +This is a Git repository that contains the code examples from the book and starter code for some exercises. + +Git is a version control system that allows you to keep track of the files that make up a project. +A collection of files under Git's control is called a repository. + +There are several ways you can work with the code: + +* You can create a copy of this repository on GitHub by pressing the "Fork" button in the upper right. +If you don't already have a GitHub account, you'll need to create one. +After forking, you'll have your own repository on GitHub that you can use to keep track of code you write. +Then you can ``clone'' the repository, which downloads a copy of the files to your computer. + +* Or you could clone the repository without forking. +If you choose this option, you don't need a GitHub account, but you won't be able to save your changes back in GitHub. + +* If you don't want to use Git at all, you can download the code in a zip archive using the "Download ZIP" button on this page, or [this link](http://tinyurl.com/ThinkJavaCodeZip). + +After you clone the repository or unzip the zip file, you should have a directory called `ThinkJavaCode` with a subdirectory for each chapter in the book. + +All the examples in this book were developed and tested using Java SE Development Kit 7. +If you are using a more recent version, the examples in this book should still work. +If you are using an older version, some of them may not. + From 06e362b26b358bcf5643d3e1a62b91ecf472b32f Mon Sep 17 00:00:00 2001 From: Allen Downey Date: Thu, 3 Mar 2016 16:29:01 -0500 Subject: [PATCH 04/29] Update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 54c33b7..fe3da55 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,14 @@ If you don't already have a GitHub account, you'll need to create one. After forking, you'll have your own repository on GitHub that you can use to keep track of code you write. Then you can ``clone'' the repository, which downloads a copy of the files to your computer. -* Or you could clone the repository without forking. -If you choose this option, you don't need a GitHub account, but you won't be able to save your changes back in GitHub. +* Or you could clone the repository without forking. If you choose this option, you don't need a GitHub account, but you won't be able to save your changes back in GitHub. * If you don't want to use Git at all, you can download the code in a zip archive using the "Download ZIP" button on this page, or [this link](http://tinyurl.com/ThinkJavaCodeZip). +To clone a repository, you need a Git client installed on your computer. The URL of this repository is `https://github.com/AllenDowney/ThinkJavaCode.git`. If you use Git from the command line, you can clone it like this: + + git clone https://github.com/AllenDowney/ThinkJavaCode.git + After you clone the repository or unzip the zip file, you should have a directory called `ThinkJavaCode` with a subdirectory for each chapter in the book. All the examples in this book were developed and tested using Java SE Development Kit 7. From 14359e1db6c80e03f2ae5396841f28c74673f032 Mon Sep 17 00:00:00 2001 From: Allen Downey Date: Mon, 7 Mar 2016 11:35:22 -0500 Subject: [PATCH 05/29] Adding ap02 code --- ap02/Drawing.java | 23 +++++++++++++++++++++++ ap02/Mickey.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ ap02/Moire.java | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 ap02/Drawing.java create mode 100644 ap02/Mickey.java create mode 100644 ap02/Moire.java diff --git a/ap02/Drawing.java b/ap02/Drawing.java new file mode 100644 index 0000000..1453913 --- /dev/null +++ b/ap02/Drawing.java @@ -0,0 +1,23 @@ +import java.awt.Canvas; +import java.awt.Graphics; +import javax.swing.JFrame; + +public class Drawing extends Canvas { + + // this is here to suppress a warning; you can read about it at + // http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html + static final long serialVersionUID = 1; + + public static void main(String[] args) { + JFrame frame = new JFrame("My Drawing"); + Canvas drawing = new Drawing(); + drawing.setSize(400, 400); + frame.add(drawing); + frame.pack(); + frame.setVisible(true); + } + + public void paint(Graphics g) { + g.fillOval(100, 100, 200, 200); + } +} diff --git a/ap02/Mickey.java b/ap02/Mickey.java new file mode 100644 index 0000000..14e93b9 --- /dev/null +++ b/ap02/Mickey.java @@ -0,0 +1,45 @@ +import java.awt.Canvas; +import java.awt.Graphics; +import java.awt.Rectangle; + +import javax.swing.JFrame; + + +public class Mickey extends Canvas { + + // this is here to suppress a warning; you can read about it at + // http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html + static final long serialVersionUID = 1; + + public static void main(String[] args) { + JFrame frame = new JFrame("My Drawing"); + Canvas canvas = new Mickey(); + canvas.setSize(400, 400); + frame.add(canvas); + frame.pack(); + frame.setVisible(true); + } + + public void paint(Graphics g) { + Rectangle bb = new Rectangle(100, 100, 200, 200); + mickey(g, bb); + } + + public void mickey(Graphics g, Rectangle bb) { + boxOval(g, bb); + + int dx = bb.width / 2; + int dy = bb.height / 2; + Rectangle half = new Rectangle(bb.x, bb.y, dx, dy); + + half.translate(-dx / 2, -dy / 2); + boxOval(g, half); + + half.translate(dx * 2, 0); + boxOval(g, half); + } + + public void boxOval(Graphics g, Rectangle bb) { + g.fillOval(bb.x, bb.y, bb.width, bb.height); + } +} diff --git a/ap02/Moire.java b/ap02/Moire.java new file mode 100644 index 0000000..78a1c22 --- /dev/null +++ b/ap02/Moire.java @@ -0,0 +1,37 @@ +import java.awt.Canvas; +import java.awt.Color; +import java.awt.Graphics; + +import javax.swing.JFrame; + + +public class Moire extends Canvas { + + // this is here to suppress a warning; you can read about it at + // http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html + static final long serialVersionUID = 1; + + public void paint(Graphics g) { + int i = 90; + while (i < getWidth()) { + g.drawOval (0, 0, i, i); + i = i + 3; + } + } + + public static void main(String[] args) { + // make the frame + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + // add the canvas + Canvas canvas = new Moire(); + canvas.setSize(400, 400); + canvas.setBackground(Color.white); + frame.getContentPane().add(canvas); + + // show the frame + frame.pack(); + frame.setVisible(true); + } +} From cd34cf8bdd70786ce62d4bc63d6a9eb6dacc3ecd Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Tue, 8 Mar 2016 15:04:24 -0500 Subject: [PATCH 06/29] ch03 sync w/book --- ch03/Convert.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ch03/Convert.java b/ch03/Convert.java index 5c93d3d..92fc06b 100644 --- a/ch03/Convert.java +++ b/ch03/Convert.java @@ -8,7 +8,8 @@ public class Convert { public static void main(String[] args) { double cm; int feet, inches, remainder; - final double centPerInch = 2.54; + final double CM_PER_INCH = 2.54; + final int IN_PER_FOOT = 12; Scanner in = new Scanner(System.in); // prompt the user and get the value @@ -16,9 +17,9 @@ public static void main(String[] args) { cm = in.nextDouble(); // convert and output the result - inches = (int) (cm / centPerInch); - feet = inches / 12; - remainder = inches % 12; + inches = (int) (cm / CM_PER_INCH); + feet = inches / IN_PER_FOOT; + remainder = inches % IN_PER_FOOT; System.out.printf("%.2f cm = %d ft, %d in\n", cm, feet, remainder); } From c560ff5757c1067e2aab9f72461e7346dfdc0f43 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Tue, 8 Mar 2016 19:23:43 -0500 Subject: [PATCH 07/29] read through ch04 --- ch04/Exercise.java | 25 +++++++++++++++++++++++++ ch04/Methods.java | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 ch04/Exercise.java diff --git a/ch04/Exercise.java b/ch04/Exercise.java new file mode 100644 index 0000000..3db4c56 --- /dev/null +++ b/ch04/Exercise.java @@ -0,0 +1,25 @@ +public class Exercise { + + public static void zoop() { + baffle(); + System.out.print("You wugga "); + baffle(); + } + + public static void main(String[] args) { + System.out.print("No, I "); + zoop(); + System.out.print("I "); + baffle(); + } + + public static void baffle() { + System.out.print("wug"); + ping(); + } + + public static void ping() { + System.out.println("."); + } + +} diff --git a/ch04/Methods.java b/ch04/Methods.java index c6fa25e..c03c5ac 100644 --- a/ch04/Methods.java +++ b/ch04/Methods.java @@ -13,7 +13,8 @@ public static void main(String[] args) { double radians = Math.toRadians(180.0); double degrees2 = Math.toDegrees(Math.PI); long x = Math.round(Math.PI * 20.0); - double x2 = Math.cos(angle + Math.PI / 2); + + double x2 = Math.cos(angle + Math.PI / 2.0); double x3 = Math.exp(Math.log(10.0)); double x4 = Math.pow(2.0, 10.0); } From 6b00a8bad859f490734fe3ab05779bdd69eca2e2 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Tue, 8 Mar 2016 20:52:52 -0500 Subject: [PATCH 08/29] read through ch05 --- ch05/Conditional.java | 121 ++++-------------------------------------- ch05/Exercise.java | 28 ++++++++++ ch05/Logarithm.java | 44 +++++++++++++++ ch05/Recursion.java | 71 +++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 111 deletions(-) create mode 100644 ch05/Exercise.java create mode 100644 ch05/Logarithm.java create mode 100644 ch05/Recursion.java diff --git a/ch05/Conditional.java b/ch05/Conditional.java index 61b3485..eb2224d 100644 --- a/ch05/Conditional.java +++ b/ch05/Conditional.java @@ -4,25 +4,25 @@ * Examples from Chapter 5. */ public class Conditional { - + public static void main(String[] args) { String fruit1 = "Apple"; String fruit2 = "Orange"; System.out.println(fruit1.equals(fruit2)); - + int x = 17; int n = 18; - + if (x > 0) { System.out.println("x is positive"); } - + if (x % 2 == 0) { System.out.println("x is even"); } else { System.out.println("x is odd"); } - + if (x > 0) { System.out.println("x is positive"); } else if (x < 0) { @@ -30,7 +30,7 @@ public static void main(String[] args) { } else { System.out.println("x is zero"); } - + if (x == 0) { System.out.println("x is zero"); } else { @@ -40,118 +40,17 @@ public static void main(String[] args) { System.out.println("x is negative"); } } + boolean evenFlag = (n % 2 == 0); // true if n is even boolean positiveFlag = (x > 0); // true if x is positive - + if (evenFlag) { System.out.println("n was even when I checked it"); } - + if (!evenFlag) { System.out.println("n was odd when I checked it"); } - - System.out.println("printLogarithm"); - printLogarithm(3.0); - - System.out.println("countdown"); - countdown(3); - - System.out.println("countup"); - countup(3); - - System.out.println("newLine"); - newLine(); - - System.out.println("nLines"); - nLines(3); - - System.out.println("threeLine"); - threeLine(); - - System.out.println("displayBinary"); - displayBinary(23); - System.out.println(); - - System.out.println("scandouble"); - scanDouble(); - - System.out.println("scandouble2"); - scanDouble2(); - } - - public static void printLogarithm(double x) { - if (x <= 0.0) { - System.err.println("Error: x must be positive."); - return; - } - double result = Math.log(x); - System.out.println("The log of x is " + result); - } - - public static void scanDouble() { - Scanner in = new Scanner(System.in); - System.out.print("Enter a number: "); - double x = in.nextDouble(); - printLogarithm(x); - } - - public static void scanDouble2() { - Scanner in = new Scanner(System.in); - System.out.print("Enter a number: "); - if (!in.hasNextDouble()) { - String word = in.next(); - System.err.println(word + " is not a number"); - return; - } - double x = in.nextDouble(); - printLogarithm(x); - } - - public static void countdown(int n) { - if (n == 0) { - System.out.println("Blastoff!"); - } else { - System.out.println(n); - countdown(n - 1); - } - } - - public static void newLine() { - System.out.println(); - } - - public static void threeLine() { - newLine(); - newLine(); - newLine(); - } - - public static void nLines(int n) { - if (n > 0) { - System.out.println(); - nLines(n - 1); - } - } - - public static void forever(String s) { - System.out.println(s); - forever(s); - } - - public static void countup(int n) { - if (n == 0) { - System.out.println("Blastoff!"); - } else { - countup(n - 1); - System.out.println(n); - } - } - - public static void displayBinary(int value) { - if (value > 0) { - displayBinary(value / 2); - System.out.print(value % 2); - } } + } diff --git a/ch05/Exercise.java b/ch05/Exercise.java new file mode 100644 index 0000000..410de7a --- /dev/null +++ b/ch05/Exercise.java @@ -0,0 +1,28 @@ +public class Exercise { + + public static void zoop(String fred, int bob) { + System.out.println(fred); + if (bob == 5) { + ping("not "); + } else { + System.out.println("!"); + } + } + + public static void main(String[] args) { + int bizz = 5; + int buzz = 2; + zoop("just for", bizz); + clink(2 * buzz); + } + + public static void clink(int fork) { + System.out.print("It's "); + zoop("breakfast ", fork) ; + } + + public static void ping(String strangStrung) { + System.out.println("any " + strangStrung + "more "); + } + +} diff --git a/ch05/Logarithm.java b/ch05/Logarithm.java new file mode 100644 index 0000000..1784eea --- /dev/null +++ b/ch05/Logarithm.java @@ -0,0 +1,44 @@ +import java.util.Scanner; + +public class Logarithm { + + public static void main(String[] args) { + System.out.println("printLogarithm"); + printLogarithm(3.0); + + System.out.println("scandouble"); + scanDouble(); + + System.out.println("scandouble2"); + scanDouble2(); + } + + public static void printLogarithm(double x) { + if (x <= 0.0) { + System.err.println("Error: x must be positive."); + return; + } + double result = Math.log(x); + System.out.println("The log of x is " + result); + } + + public static void scanDouble() { + Scanner in = new Scanner(System.in); + System.out.print("Enter a number: "); + double x = in.nextDouble(); + printLogarithm(x); + } + + public static void scanDouble2() { + Scanner in = new Scanner(System.in); + System.out.print("Enter a number: "); + if (!in.hasNextDouble()) { + String word = in.next(); + System.err.println(word + " is not a number"); + return; + } + double x = in.nextDouble(); + printLogarithm(x); + } + +} diff --git a/ch05/Recursion.java b/ch05/Recursion.java new file mode 100644 index 0000000..ef1383f --- /dev/null +++ b/ch05/Recursion.java @@ -0,0 +1,71 @@ +public class Recursion { + + public static void main(String[] args) { + System.out.println("countdown"); + countdown(3); + + System.out.println("countup"); + countup(3); + + System.out.println("newLine"); + newLine(); + + System.out.println("nLines"); + nLines(3); + + System.out.println("threeLine"); + threeLine(); + + System.out.println("displayBinary"); + displayBinary(23); + System.out.println(); + } + + public static void countdown(int n) { + if (n == 0) { + System.out.println("Blastoff!"); + } else { + System.out.println(n); + countdown(n - 1); + } + } + + public static void newLine() { + System.out.println(); + } + + public static void threeLine() { + newLine(); + newLine(); + newLine(); + } + + public static void nLines(int n) { + if (n > 0) { + System.out.println(); + nLines(n - 1); + } + } + + public static void forever(String s) { + System.out.println(s); + forever(s); + } + + public static void countup(int n) { + if (n == 0) { + System.out.println("Blastoff!"); + } else { + countup(n - 1); + System.out.println(n); + } + } + + public static void displayBinary(int value) { + if (value > 0) { + displayBinary(value / 2); + System.out.print(value % 2); + } + } + +} From 7fc0d151a0d6db7f2406d91e125ac0f089187270 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Tue, 8 Mar 2016 21:37:21 -0500 Subject: [PATCH 09/29] remove duplicate file --- ch06/ValueMethods.java | 113 ----------------------------------------- 1 file changed, 113 deletions(-) delete mode 100644 ch06/ValueMethods.java diff --git a/ch06/ValueMethods.java b/ch06/ValueMethods.java deleted file mode 100644 index 3a54d1b..0000000 --- a/ch06/ValueMethods.java +++ /dev/null @@ -1,113 +0,0 @@ -public class ValueMethods { - - public static void countup(int n) { - if (n == 0) { - System.out.println("Blastoff!"); - } else { - countup(n - 1); - System.out.println(n); - } - } - - public static double area(double radius) { - double area = Math.PI * radius * radius; - return area; - } - - public static double area2(double radius) { - return Math.PI * radius * radius; - } - - public static double absoluteValue(double x) { - if (x < 0) { - return -x; - } else { - return x; - } - } - - public static double distance - (double x1, double y1, double x2, double y2) { - double dx = x2 - x1; - double dy = y2 - y1; - System.out.println("dx is " + dx); - System.out.println("dy is " + dy); - return 0.0; - } - - public static double distance2 - (double x1, double y1, double x2, double y2) { - double dx = x2 - x1; - double dy = y2 - y1; - double dsquared = dx * dx + dy * dy; - System.out.println("dsquared is " + dsquared); - return 0.0; - } - - public static double distance3 - (double x1, double y1, double x2, double y2) { - double dx = x2 - x1; - double dy = y2 - y1; - double dsquared = dx * dx + dy * dy; - double result = Math.sqrt(dsquared); - return result; - } - - public static double circleArea - (double xc, double yc, double xp, double yp) { - double radius = distance(xc, yc, xp, yp); - double area = area(radius); - return area; - } - - public static double area - (double xc, double yc, double xp, double yp) { - return area(distance(xc, yc, xp, yp)); - } - - public static boolean isSingleDigit(int x) { - if (x >= 0 && x < 10) { - return true; - } else { - return false; - } - } - - public static boolean isSingleDigit2(int x) { - return x >= 0 && x < 10; - } - - public static int factorial(int n) { - if (n == 0) { - return 1; - } - int recurse = factorial(n - 1); - int result = n * recurse; - return result; - } - - public static int fibonacci(int n) { - if (n == 1 || n == 2) { - return 1; - } - return fibonacci(n - 1) + fibonacci(n - 2); - } - - public static void main(String[] args) { - countup(3); - System.out.println("Have a nice day."); - - double x = area(3.0); - double y = area(1.0, 2.0, 4.0, 6.0); - - System.out.println(isSingleDigit(2)); - boolean bigFlag = !isSingleDigit(17); - - int z = 17; - if (isSingleDigit(z)) { - System.out.println("z is small"); - } else { - System.out.println("z is big"); - } - } -} From b006db326a4470d45f9a5cdcffe727558f8b8972 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Tue, 8 Mar 2016 22:01:02 -0500 Subject: [PATCH 10/29] read through ch06 --- ch06/Exercise.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ch06/Exercise.java diff --git a/ch06/Exercise.java b/ch06/Exercise.java new file mode 100644 index 0000000..9bd8c08 --- /dev/null +++ b/ch06/Exercise.java @@ -0,0 +1,36 @@ +public class Exercise { + + public static void main(String[] args) { + boolean flag1 = isHoopy(202); + boolean flag2 = isFrabjuous(202); + System.out.println(flag1); + System.out.println(flag2); + if (flag1 && flag2) { + System.out.println("ping!"); + } + if (flag1 || flag2) { + System.out.println("pong!"); + } + } + + public static boolean isHoopy(int x) { + boolean hoopyFlag; + if (x % 2 == 0) { + hoopyFlag = true; + } else { + hoopyFlag = false; + } + return hoopyFlag; + } + + public static boolean isFrabjuous(int x) { + boolean frabjuousFlag; + if (x > 0) { + frabjuousFlag = true; + } else { + frabjuousFlag = false; + } + return frabjuousFlag; + } + +} From 2b9b3d60bdd8f916608e712090a213fd7f84fabe Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 9 Mar 2016 11:05:34 -0500 Subject: [PATCH 11/29] added missing exercises --- ch05/Buzz.java | 22 ++++++++++++++++++++++ ch06/Recursive.java | 17 +++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 ch05/Buzz.java create mode 100644 ch06/Recursive.java diff --git a/ch05/Buzz.java b/ch05/Buzz.java new file mode 100644 index 0000000..95e1c2a --- /dev/null +++ b/ch05/Buzz.java @@ -0,0 +1,22 @@ +public class Buzz { + + public static void baffle(String blimp) { + System.out.println(blimp); + zippo("ping", -5); + } + + public static void zippo(String quince, int flag) { + if (flag < 0) { + System.out.println(quince + " zoop"); + } else { + System.out.println("ik"); + baffle(quince); + System.out.println("boo-wa-ha-ha"); + } + } + + public static void main(String[] args) { + zippo("rattle", 13); + } + +} diff --git a/ch06/Recursive.java b/ch06/Recursive.java new file mode 100644 index 0000000..0d29924 --- /dev/null +++ b/ch06/Recursive.java @@ -0,0 +1,17 @@ +public class Recursive { + + public static void main(String[] args) { + System.out.println(prod(1, 4)); + } + + public static int prod(int m, int n) { + if (m == n) { + return n; + } else { + int recurse = prod(m, n-1); + int result = n * recurse; + return result; + } + } + +} From d48e1210bfdc76a0515f20bc31a2b125acfadc42 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 9 Mar 2016 11:06:01 -0500 Subject: [PATCH 12/29] consistent whitespace --- ch04/Exercise.java | 10 +++++----- ch04/Methods.java | 2 +- ch05/Conditional.java | 20 ++++++++++---------- ch05/Exercise.java | 10 +++++----- ch05/Logarithm.java | 14 +++++++------- ch05/Recursion.java | 28 ++++++++++++++-------------- ch06/Exercise.java | 8 ++++---- 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/ch04/Exercise.java b/ch04/Exercise.java index 3db4c56..ba8c2a9 100644 --- a/ch04/Exercise.java +++ b/ch04/Exercise.java @@ -1,25 +1,25 @@ public class Exercise { - + public static void zoop() { baffle(); System.out.print("You wugga "); baffle(); } - + public static void main(String[] args) { System.out.print("No, I "); zoop(); System.out.print("I "); baffle(); } - + public static void baffle() { System.out.print("wug"); ping(); } - + public static void ping() { System.out.println("."); } - + } diff --git a/ch04/Methods.java b/ch04/Methods.java index c03c5ac..035a392 100644 --- a/ch04/Methods.java +++ b/ch04/Methods.java @@ -13,7 +13,7 @@ public static void main(String[] args) { double radians = Math.toRadians(180.0); double degrees2 = Math.toDegrees(Math.PI); long x = Math.round(Math.PI * 20.0); - + double x2 = Math.cos(angle + Math.PI / 2.0); double x3 = Math.exp(Math.log(10.0)); double x4 = Math.pow(2.0, 10.0); diff --git a/ch05/Conditional.java b/ch05/Conditional.java index eb2224d..1fd36ce 100644 --- a/ch05/Conditional.java +++ b/ch05/Conditional.java @@ -4,25 +4,25 @@ * Examples from Chapter 5. */ public class Conditional { - + public static void main(String[] args) { String fruit1 = "Apple"; String fruit2 = "Orange"; System.out.println(fruit1.equals(fruit2)); - + int x = 17; int n = 18; - + if (x > 0) { System.out.println("x is positive"); } - + if (x % 2 == 0) { System.out.println("x is even"); } else { System.out.println("x is odd"); } - + if (x > 0) { System.out.println("x is positive"); } else if (x < 0) { @@ -30,7 +30,7 @@ public static void main(String[] args) { } else { System.out.println("x is zero"); } - + if (x == 0) { System.out.println("x is zero"); } else { @@ -40,17 +40,17 @@ public static void main(String[] args) { System.out.println("x is negative"); } } - + boolean evenFlag = (n % 2 == 0); // true if n is even boolean positiveFlag = (x > 0); // true if x is positive - + if (evenFlag) { System.out.println("n was even when I checked it"); } - + if (!evenFlag) { System.out.println("n was odd when I checked it"); } } - + } diff --git a/ch05/Exercise.java b/ch05/Exercise.java index 410de7a..46774e0 100644 --- a/ch05/Exercise.java +++ b/ch05/Exercise.java @@ -1,5 +1,5 @@ public class Exercise { - + public static void zoop(String fred, int bob) { System.out.println(fred); if (bob == 5) { @@ -8,21 +8,21 @@ public static void zoop(String fred, int bob) { System.out.println("!"); } } - + public static void main(String[] args) { int bizz = 5; int buzz = 2; zoop("just for", bizz); clink(2 * buzz); } - + public static void clink(int fork) { System.out.print("It's "); zoop("breakfast ", fork) ; } - + public static void ping(String strangStrung) { System.out.println("any " + strangStrung + "more "); } - + } diff --git a/ch05/Logarithm.java b/ch05/Logarithm.java index 1784eea..bc21157 100644 --- a/ch05/Logarithm.java +++ b/ch05/Logarithm.java @@ -1,18 +1,18 @@ import java.util.Scanner; public class Logarithm { - + public static void main(String[] args) { System.out.println("printLogarithm"); printLogarithm(3.0); - + System.out.println("scandouble"); scanDouble(); - + System.out.println("scandouble2"); scanDouble2(); } - + public static void printLogarithm(double x) { if (x <= 0.0) { System.err.println("Error: x must be positive."); @@ -21,14 +21,14 @@ public static void printLogarithm(double x) { double result = Math.log(x); System.out.println("The log of x is " + result); } - + public static void scanDouble() { Scanner in = new Scanner(System.in); System.out.print("Enter a number: "); double x = in.nextDouble(); printLogarithm(x); } - + public static void scanDouble2() { Scanner in = new Scanner(System.in); System.out.print("Enter a number: "); @@ -40,5 +40,5 @@ public static void scanDouble2() { double x = in.nextDouble(); printLogarithm(x); } - + } diff --git a/ch05/Recursion.java b/ch05/Recursion.java index ef1383f..0e772c8 100644 --- a/ch05/Recursion.java +++ b/ch05/Recursion.java @@ -1,26 +1,26 @@ public class Recursion { - + public static void main(String[] args) { System.out.println("countdown"); countdown(3); - + System.out.println("countup"); countup(3); - + System.out.println("newLine"); newLine(); - + System.out.println("nLines"); nLines(3); - + System.out.println("threeLine"); threeLine(); - + System.out.println("displayBinary"); displayBinary(23); System.out.println(); } - + public static void countdown(int n) { if (n == 0) { System.out.println("Blastoff!"); @@ -29,29 +29,29 @@ public static void countdown(int n) { countdown(n - 1); } } - + public static void newLine() { System.out.println(); } - + public static void threeLine() { newLine(); newLine(); newLine(); } - + public static void nLines(int n) { if (n > 0) { System.out.println(); nLines(n - 1); } } - + public static void forever(String s) { System.out.println(s); forever(s); } - + public static void countup(int n) { if (n == 0) { System.out.println("Blastoff!"); @@ -60,12 +60,12 @@ public static void countup(int n) { System.out.println(n); } } - + public static void displayBinary(int value) { if (value > 0) { displayBinary(value / 2); System.out.print(value % 2); } } - + } diff --git a/ch06/Exercise.java b/ch06/Exercise.java index 9bd8c08..b826b44 100644 --- a/ch06/Exercise.java +++ b/ch06/Exercise.java @@ -1,5 +1,5 @@ public class Exercise { - + public static void main(String[] args) { boolean flag1 = isHoopy(202); boolean flag2 = isFrabjuous(202); @@ -12,7 +12,7 @@ public static void main(String[] args) { System.out.println("pong!"); } } - + public static boolean isHoopy(int x) { boolean hoopyFlag; if (x % 2 == 0) { @@ -22,7 +22,7 @@ public static boolean isHoopy(int x) { } return hoopyFlag; } - + public static boolean isFrabjuous(int x) { boolean frabjuousFlag; if (x > 0) { @@ -32,5 +32,5 @@ public static boolean isFrabjuous(int x) { } return frabjuousFlag; } - + } From fe4a34958400d84d800357c597aade8bacbb3b3d Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 9 Mar 2016 13:29:42 -0500 Subject: [PATCH 13/29] added Javadoc comment --- ch06/Series.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ch06/Series.java b/ch06/Series.java index c256828..64ad34e 100644 --- a/ch06/Series.java +++ b/ch06/Series.java @@ -68,8 +68,14 @@ public static double absoluteValue(double x) { return area(distance(xc, yc, xp, yp)); } + /** + * Tests whether x is a single digit integer. + * + * @param x the integer to test + * @return true if x has one digit, false otherwise + */ public static boolean isSingleDigit(int x) { - if (x >= 0 && x < 10) { + if (x > -10 && x < 10) { return true; } else { return false; @@ -77,7 +83,7 @@ public static boolean isSingleDigit(int x) { } public static boolean isSingleDigit2(int x) { - return x >= 0 && x < 10; + return x > -10 && x < 10; } public static int factorial(int n) { From 98d82bc78675099b04c740c35e717e7efbe618f7 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 9 Mar 2016 14:23:18 -0500 Subject: [PATCH 14/29] read through ch07 --- ch07/Tables.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ch07/Tables.java b/ch07/Tables.java index 692ca39..57efe1d 100644 --- a/ch07/Tables.java +++ b/ch07/Tables.java @@ -41,11 +41,11 @@ public static void example2() { } public static void example3() { - final double log2 = Math.log(2); + final double LOG2 = Math.log(2); int i = 1; while (i < 100) { double x = (double) i; - System.out.println(x + " " + Math.log(x) / log2); + System.out.println(x + " " + Math.log(x) / LOG2); i = i * 2; } } From 2dd19cc7afc1d82a254d0ccef91344b46e3c51b8 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 9 Mar 2016 17:30:27 -0500 Subject: [PATCH 15/29] added ch07 TODO sections --- ch07/Loops.java | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ ch07/Tables.java | 77 ++++++++++++++++------------------------------- 2 files changed, 104 insertions(+), 51 deletions(-) create mode 100644 ch07/Loops.java diff --git a/ch07/Loops.java b/ch07/Loops.java new file mode 100644 index 0000000..be02722 --- /dev/null +++ b/ch07/Loops.java @@ -0,0 +1,78 @@ +import java.util.Scanner; + +public class Loops { + + public static void countdown(int n) { + while (n > 0) { + System.out.println(n); + n = n - 1; + } + System.out.println("Blastoff!"); + } + + public static void sequence(int n) { + while (n != 1) { + System.out.println(n); + if (n % 2 == 0) { // n is even + n = n / 2; + } else { // n is odd + n = n * 3 + 1; + } + } + } + + public static double scanDouble() { + Scanner in = new Scanner(System.in); + boolean okay; + do { + System.out.print("Enter a number: "); + if (in.hasNextDouble()) { + okay = true; + } else { + okay = false; + String word = in.next(); + System.err.println(word + " is not a number"); + } + } while (!okay); + double x = in.nextDouble(); + return x; + } + + public static double scanDouble2() { + Scanner in = new Scanner(System.in); + while (true) { + System.out.print("Enter a number: "); + if (in.hasNextDouble()) { + break; + } + String word = in.next(); + System.err.println(word + " is not a number"); + } + double x = in.nextDouble(); + return x; + } + + public static double addNumbers() { + Scanner in = new Scanner(System.in); + int x = -1; + int sum = 0; + while (x != 0) { + x = in.nextInt(); + if (x <= 0) { + continue; + } + System.out.println("Adding " + x); + sum += x; + } + return sum; + } + + public static void main(String[] args) { + System.out.println("countdown"); + countdown(3); + + System.out.println("sequence"); + sequence(10); + } + +} diff --git a/ch07/Tables.java b/ch07/Tables.java index 57efe1d..4d5cd39 100644 --- a/ch07/Tables.java +++ b/ch07/Tables.java @@ -2,26 +2,7 @@ * Examples from Chapter 7. */ public class Tables { - - public static void countdown(int n) { - while (n > 0) { - System.out.println(n); - n = n - 1; - } - System.out.println("Blastoff!"); - } - - public static void sequence(int n) { - while (n != 1) { - System.out.println(n); - if (n % 2 == 0) { // n is even - n = n / 2; - } else { // n is odd - n = n * 3 + 1; - } - } - } - + public static void example() { int i = 1; while (i < 10) { @@ -30,7 +11,7 @@ public static void example() { i = i + 1; } } - + public static void example2() { int i = 1; while (i < 10) { @@ -39,7 +20,7 @@ public static void example2() { i = i + 1; } } - + public static void example3() { final double LOG2 = Math.log(2); int i = 1; @@ -49,7 +30,7 @@ public static void example3() { i = i * 2; } } - + public static void example4() { int i = 1; while (i <= 6) { @@ -58,7 +39,7 @@ public static void example4() { } System.out.println(); } - + public static void printRow() { int i = 1; while (i <= 6) { @@ -67,7 +48,7 @@ public static void printRow() { } System.out.println(); } - + public static void printRow2(int n) { int i = 1; while (i <= 6) { @@ -76,7 +57,7 @@ public static void printRow2(int n) { } System.out.println(); } - + public static void example5() { int i = 1; while (i <= 6) { @@ -84,7 +65,7 @@ public static void example5() { i = i + 1; } } - + public static void printTable() { int i = 1; while (i <= 6) { @@ -92,7 +73,7 @@ public static void printTable() { i = i + 1; } } - + public static void printTable2(int rows) { int i = 1; while (i <= rows) { @@ -100,7 +81,7 @@ public static void printTable2(int rows) { i = i + 1; } } - + public static void printRow3(int n, int cols) { int i = 1; while (i <= cols) { @@ -109,7 +90,7 @@ public static void printRow3(int n, int cols) { } System.out.println(); } - + public static void printTable3(int rows) { int i = 1; while (i <= rows) { @@ -117,13 +98,13 @@ public static void printTable3(int rows) { i = i + 1; } } - + public static void printTable4(int rows) { for (int i = 1; i <= rows; i = i + 1) { printRow3(i, rows); } } - + public static void printRow4(int n, int cols) { int i; for (i = 1; i <= cols; i = i + 1) { @@ -131,50 +112,44 @@ public static void printRow4(int n, int cols) { } System.out.println(i); } - + public static void main(String[] args) { - System.out.println("countdown"); - countdown(3); - - System.out.println("sequence"); - sequence(10); - System.out.println("example"); example(); - + System.out.println("example2"); example2(); - + System.out.println("example3"); example3(); - + System.out.println("example4"); example4(); - + System.out.println("example5"); example5(); - + System.out.println("printRow"); printRow(); - + System.out.println("printRow2"); printRow2(6); - + System.out.println("printTable"); printTable(); - + System.out.println("printTable2"); printTable2(6); - + System.out.println("printRow3"); printRow3(6, 6); - + System.out.println("printTable3"); printTable3(6); - + System.out.println("printRow4"); printRow4(6, 6); - + System.out.println("printTable4"); printTable4(6); } From 1340ba020541bf3296b1be16729a28a8f122ac52 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 9 Mar 2016 20:08:17 -0500 Subject: [PATCH 16/29] consistent whitespace --- ch06/Series.java | 2 +- ch07/Loops.java | 16 +++++++-------- ch07/Tables.java | 52 ++++++++++++++++++++++++------------------------ 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/ch06/Series.java b/ch06/Series.java index 64ad34e..8ce7c30 100644 --- a/ch06/Series.java +++ b/ch06/Series.java @@ -70,7 +70,7 @@ public static double absoluteValue(double x) { /** * Tests whether x is a single digit integer. - * + * * @param x the integer to test * @return true if x has one digit, false otherwise */ diff --git a/ch07/Loops.java b/ch07/Loops.java index be02722..58c7bd6 100644 --- a/ch07/Loops.java +++ b/ch07/Loops.java @@ -1,7 +1,7 @@ import java.util.Scanner; public class Loops { - + public static void countdown(int n) { while (n > 0) { System.out.println(n); @@ -9,7 +9,7 @@ public static void countdown(int n) { } System.out.println("Blastoff!"); } - + public static void sequence(int n) { while (n != 1) { System.out.println(n); @@ -20,7 +20,7 @@ public static void sequence(int n) { } } } - + public static double scanDouble() { Scanner in = new Scanner(System.in); boolean okay; @@ -37,7 +37,7 @@ public static double scanDouble() { double x = in.nextDouble(); return x; } - + public static double scanDouble2() { Scanner in = new Scanner(System.in); while (true) { @@ -51,7 +51,7 @@ public static double scanDouble2() { double x = in.nextDouble(); return x; } - + public static double addNumbers() { Scanner in = new Scanner(System.in); int x = -1; @@ -66,13 +66,13 @@ public static double addNumbers() { } return sum; } - + public static void main(String[] args) { System.out.println("countdown"); countdown(3); - + System.out.println("sequence"); sequence(10); } - + } diff --git a/ch07/Tables.java b/ch07/Tables.java index 4d5cd39..e586699 100644 --- a/ch07/Tables.java +++ b/ch07/Tables.java @@ -2,7 +2,7 @@ * Examples from Chapter 7. */ public class Tables { - + public static void example() { int i = 1; while (i < 10) { @@ -11,7 +11,7 @@ public static void example() { i = i + 1; } } - + public static void example2() { int i = 1; while (i < 10) { @@ -20,7 +20,7 @@ public static void example2() { i = i + 1; } } - + public static void example3() { final double LOG2 = Math.log(2); int i = 1; @@ -30,7 +30,7 @@ public static void example3() { i = i * 2; } } - + public static void example4() { int i = 1; while (i <= 6) { @@ -39,7 +39,7 @@ public static void example4() { } System.out.println(); } - + public static void printRow() { int i = 1; while (i <= 6) { @@ -48,7 +48,7 @@ public static void printRow() { } System.out.println(); } - + public static void printRow2(int n) { int i = 1; while (i <= 6) { @@ -57,7 +57,7 @@ public static void printRow2(int n) { } System.out.println(); } - + public static void example5() { int i = 1; while (i <= 6) { @@ -65,7 +65,7 @@ public static void example5() { i = i + 1; } } - + public static void printTable() { int i = 1; while (i <= 6) { @@ -73,7 +73,7 @@ public static void printTable() { i = i + 1; } } - + public static void printTable2(int rows) { int i = 1; while (i <= rows) { @@ -81,7 +81,7 @@ public static void printTable2(int rows) { i = i + 1; } } - + public static void printRow3(int n, int cols) { int i = 1; while (i <= cols) { @@ -90,7 +90,7 @@ public static void printRow3(int n, int cols) { } System.out.println(); } - + public static void printTable3(int rows) { int i = 1; while (i <= rows) { @@ -98,13 +98,13 @@ public static void printTable3(int rows) { i = i + 1; } } - + public static void printTable4(int rows) { for (int i = 1; i <= rows; i = i + 1) { printRow3(i, rows); } } - + public static void printRow4(int n, int cols) { int i; for (i = 1; i <= cols; i = i + 1) { @@ -112,44 +112,44 @@ public static void printRow4(int n, int cols) { } System.out.println(i); } - + public static void main(String[] args) { System.out.println("example"); example(); - + System.out.println("example2"); example2(); - + System.out.println("example3"); example3(); - + System.out.println("example4"); example4(); - + System.out.println("example5"); example5(); - + System.out.println("printRow"); printRow(); - + System.out.println("printRow2"); printRow2(6); - + System.out.println("printTable"); printTable(); - + System.out.println("printTable2"); printTable2(6); - + System.out.println("printRow3"); printRow3(6, 6); - + System.out.println("printTable3"); printTable3(6); - + System.out.println("printRow4"); printRow4(6, 6); - + System.out.println("printTable4"); printTable4(6); } From c54190dc7f48a562dcdd253f2d9919fabb930a51 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 9 Mar 2016 21:49:16 -0500 Subject: [PATCH 17/29] moved makeHistogram --- ch08/ArrayExamples.java | 58 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/ch08/ArrayExamples.java b/ch08/ArrayExamples.java index dfc8d1e..a9a4e9a 100644 --- a/ch08/ArrayExamples.java +++ b/ch08/ArrayExamples.java @@ -66,35 +66,6 @@ public static void main(String[] args) { makeHistogram(); } - /** - * Example code related to histograms. - */ - public static void makeHistogram() { - int numValues = 8; - int[] array = randomArray(numValues); - printArray(array); - - int[] scores = randomArray(30); - int a = inRange(scores, 90, 100); - int b = inRange(scores, 80, 90); - int c = inRange(scores, 70, 80); - int d = inRange(scores, 60, 70); - int f = inRange(scores, 0, 60); - - // making a histogram - int[] counts = new int[100]; - for (int i = 0; i < scores.length; i++) { - int index = scores[i]; - counts[index]++; - } - - // histogram with enhanced for loop - counts = new int[100]; - for (int score : scores) { - counts[score]++; - } - } - /** * Prints the elements of an array. */ @@ -153,4 +124,33 @@ public static int inRange(int[] a, int low, int high) { } return count; } + + /** + * Example code related to histograms. + */ + public static void makeHistogram() { + int numValues = 8; + int[] array = randomArray(numValues); + printArray(array); + + int[] scores = randomArray(30); + int a = inRange(scores, 90, 100); + int b = inRange(scores, 80, 90); + int c = inRange(scores, 70, 80); + int d = inRange(scores, 60, 70); + int f = inRange(scores, 0, 60); + + // making a histogram + int[] counts = new int[100]; + for (int i = 0; i < scores.length; i++) { + int index = scores[i]; + counts[index]++; + } + + // histogram with enhanced for loop + counts = new int[100]; + for (int score : scores) { + counts[score]++; + } + } } From 0639135fcdbf3ee65322a99b911e78419ceecc96 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 9 Mar 2016 23:26:42 -0500 Subject: [PATCH 18/29] read through ch09 --- ch09/Max.java | 19 +++++++++++++++++++ ch09/StringsThings.java | 20 ++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 ch09/Max.java diff --git a/ch09/Max.java b/ch09/Max.java new file mode 100644 index 0000000..01417f0 --- /dev/null +++ b/ch09/Max.java @@ -0,0 +1,19 @@ +import java.util.Arrays; + +/** + * Demonstrates command-line arguments. + */ +public class Max { + + public static void main(String[] args) { + System.out.println(Arrays.toString(args)); + + int max = Integer.MIN_VALUE; + for (String arg : args) { + int value = Integer.parseInt(arg); + if (value > max) { + max = value; + } + } + } +} diff --git a/ch09/StringsThings.java b/ch09/StringsThings.java index bdec09c..20357c1 100644 --- a/ch09/StringsThings.java +++ b/ch09/StringsThings.java @@ -28,13 +28,6 @@ public static void main(String[] args) { } System.out.println(); - String fruit = "banana"; - - for (int i = 0; i < fruit.length(); i++) { - char letter = fruit.charAt(i); - System.out.println(letter); - } - String name1 = "Alan Turing"; String name2 = "Ada Lovelace"; if (name1.equals(name2)) { @@ -50,6 +43,17 @@ public static void main(String[] args) { System.out.println("name2 comes before name1."); } - System.out.println(reverse(name1)); + String fruit = "banana"; + + for (int i = 0; i < fruit.length(); i++) { + char letter = fruit.charAt(i); + System.out.println(letter); + } + + for (char letter : fruit.toCharArray()) { + System.out.println(letter); + } + + System.out.println(reverse(fruit)); } } From 19511bbfedfdda74b94d2eb64af49607d20cd07c Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Thu, 10 Mar 2016 13:27:51 -0500 Subject: [PATCH 19/29] added String.format section --- ch09/Format.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ch09/Format.java diff --git a/ch09/Format.java b/ch09/Format.java new file mode 100644 index 0000000..7e3ff8a --- /dev/null +++ b/ch09/Format.java @@ -0,0 +1,33 @@ +/** + * Example using the String.format method. + */ +public class Format { + + /** + * Returns a time string in 12-hour format. + * + * @param hour between 0 and 23 + * @param minute between 0 and 59 + */ + public static String timeString(int hour, int minute) { + String ampm; + if (hour < 12) { + ampm = "AM"; + if (hour == 0) { + hour = 12; // midnight + } + } else { + ampm = "PM"; + hour = hour - 12; + } + return String.format("%02d:%02d %s", hour, minute, ampm); + } + + public static void main(String[] args) { + System.out.println(timeString(0, 0)); + System.out.println(timeString(7, 30)); + System.out.println(timeString(12, 5)); + System.out.println(timeString(23, 59)); + } + +} From 353123ff82492c716b96c4ca84715017cb7d5f3f Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Thu, 10 Mar 2016 16:15:06 -0500 Subject: [PATCH 20/29] read through ch12 --- ch12/Search.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ch12/Search.java b/ch12/Search.java index 520a838..3cfe2d1 100644 --- a/ch12/Search.java +++ b/ch12/Search.java @@ -24,14 +24,14 @@ public static int binarySearch(Card[] cards, Card target) { while (low <= high) { System.out.println(low + ", " + high); - int mid = (low + high) / 2; // step 1 + int mid = (low + high) / 2; // step 1 int comp = cards[mid].compareTo(target); - if (comp == 0) { // step 2 + if (comp == 0) { // step 2 return mid; - } else if (comp < 0) { // step 3 + } else if (comp < 0) { // step 3 low = mid + 1; - } else { // step 4 + } else { // step 4 high = mid - 1; } } @@ -48,14 +48,14 @@ public static int binarySearchRec(Card[] cards, Card target, if (high < low) { return -1; } - int mid = (low + high) / 2; // step 1 + int mid = (low + high) / 2; // step 1 int comp = cards[mid].compareTo(target); - if (comp == 0) { // step 2 + if (comp == 0) { // step 2 return mid; - } else if (comp < 0) { // step 3 + } else if (comp < 0) { // step 3 return binarySearchRec(cards, target, mid + 1, high); - } else { // step 4 + } else { // step 4 return binarySearchRec(cards, target, low, mid - 1); } } From 5bc037ba87865db163348261e0fedec9f369da6d Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Wed, 20 Apr 2016 16:55:30 -0400 Subject: [PATCH 21/29] stubs for ch13 --- ch13/Deck.java | 126 +++---------------------------------------------- 1 file changed, 6 insertions(+), 120 deletions(-) diff --git a/ch13/Deck.java b/ch13/Deck.java index d567844..864d52e 100644 --- a/ch13/Deck.java +++ b/ch13/Deck.java @@ -6,10 +6,6 @@ */ public class Deck { - // This is a class variable so we don't have to create - // a new Random object every time we call randomInt. - private static Random random = new Random(); - private Card[] cards; /** @@ -41,65 +37,24 @@ public Card[] getCards() { } /** - * Returns a string representation of the deck. - */ - public String toString() { - return Arrays.toString(this.cards); - } - - /** - * Swaps the cards at indexes i and j. + * Displays each of the cards in the deck. */ - public void swapCards(int i, int j) { - Card temp = this.cards[i]; - this.cards[i] = this.cards[j]; - this.cards[j] = temp; - } - - /** - * Chooses a random number between low and high, including both. - */ - public int randomInt(int low, int high) { - int range = high - low + 1; - return low + random.nextInt(range); + public void print() { + for (int i = 0; i < this.cards.length; i++) { + System.out.println(this.cards[i]); + } } /** * Randomly permutes the array of cards. */ public void shuffle() { - for (int i = 0; i < this.cards.length - 1; i++) { - int j = this.randomInt(i, this.cards.length - 1); - this.swapCards(i, j); - } - } - - /** - * Finds the index of the lowest card - * between low and high inclusive. - */ - public int indexLowest(int low, int high) { - int index = low; - Card minCard = this.cards[low]; - for (int i = low + 1; i <= high; i++) { - Card card = this.cards[i]; - if (card.compareTo(minCard) < 0) { - index = i; - minCard = card; - } - } - return index; } /** * Sorts the cards (in place) using selection sort. */ public void selectionSort() { - int high = this.cards.length - 1; - for (int i = 0; i < this.cards.length; i++) { - int j = this.indexLowest(i, high); - this.swapCards(i, j); - } } /** @@ -113,85 +68,16 @@ public Deck subdeck(int low, int high) { return sub; } - /** - * Combines two previously sorted subdecks. - */ - public static Deck merge(Deck d1, Deck d2) { - Card[] c1 = d1.cards; - Card[] c2 = d2.cards; - Deck result = new Deck(c1.length + c2.length); - Card[] c3 = result.cards; - int i = 0; // index in c1 - int j = 0; // index in c2 - - // for each index in the result - for (int k = 0; k < c3.length; k++) { - int choice; - - // determine which card to merge next - if (i >= c1.length) { - choice = 2; // c1 is empty - } else if (j >= c2.length) { - choice = 1; // c2 is empty - } else if (c1[i].compareTo(c2[j]) < 0) { - choice = 1; // c1 is lower - } else { - choice = 2; // c2 is lower - } - - // store the chosen card in the result - if (choice == 1) { - c3[k] = c1[i]; - i++; - } else { - c3[k] = c2[j]; - j++; - } - } - return result; - } - /** * Returns a sorted copy of the deck using merge sort. */ public Deck mergeSort() { - - // 0 or 1 cards, already sorted - int len = this.cards.length; - if (len < 2) { - return this; - } - - // cut the deck about in half - int mid = len / 2; - Deck d1 = this.subdeck(0, mid - 1); - Deck d2 = this.subdeck(mid, len - 1); - - // sort each half and merge - d1 = d1.mergeSort(); - d2 = d2.mergeSort(); - return merge(d1, d2); + return this; } /** * Reorders the cards (in place) using insertion sort. */ public void insertionSort() { - for (int i = 1; i < this.cards.length; i++) { - Card card = this.cards[i]; - this.insert(card, i); - } - } - - /** - * Helper method for insertion sort. - */ - private void insert(Card card, int i) { - int j = i; - while (j > 0 && card.compareTo(this.cards[j - 1]) < 0) { - this.cards[j] = this.cards[j - 1]; - j--; - } - this.cards[j] = card; } } From aa70d99c54de2dcbac42787094337e56356f61a7 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Thu, 28 Apr 2016 16:47:22 -0400 Subject: [PATCH 22/29] review ch1-7 --- ch02/Variables.java | 15 ++++++------ ch03/GuessStarter.java | 2 +- ch06/Recursive.java | 2 +- ch06/Series.java | 34 +++++++++++++-------------- ch06/SeriesTest.java | 3 +++ ch07/Loops.java | 52 +++-------------------------------------- ch07/Tables.java | 2 +- ch07/Validate.java | 53 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 86 insertions(+), 77 deletions(-) create mode 100644 ch07/Validate.java diff --git a/ch02/Variables.java b/ch02/Variables.java index b4a99d6..0312023 100644 --- a/ch02/Variables.java +++ b/ch02/Variables.java @@ -14,14 +14,14 @@ public static void main(String[] args) { int hour, minute; message = "Hello!"; // give message the value "Hello!" - hour = 10; // assign the value 10 to hour + hour = 11; // assign the value 11 to hour minute = 59; // set minute to 59 - message = "123"; // legal - // message = 123; not legal + message = "123"; // legal + // message = 123; // not legal String message2 = "Hello!"; - int hour2 = 10; + int hour2 = 11; int minute2 = 59; int a = 5; @@ -43,7 +43,6 @@ public static void main(String[] args) { System.out.print("Number of minutes since midnight: "); System.out.println(hour * 60 + minute); - System.out.print("Fraction of the hour that has passed: "); System.out.println(minute / 60); @@ -61,10 +60,10 @@ public static void main(String[] args) { System.out.println(0.1 * 10); System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1 - + 0.1 + 0.1 + 0.1 + 0.1 + 0.1); + + 0.1 + 0.1 + 0.1 + 0.1 + 0.1); double balance = 123.45; // potential rounding error - int balance2 = 12345; // total number of cents + int balance2 = 12345; // total number of cents System.out.println(1 + 2 + "Hello"); // the output is 3Hello @@ -79,6 +78,6 @@ public static void main(String[] args) { percentage = (minute * 100) / 60; hour = minute + 1; // correct - // minute + 1 = hour; syntax error + // minute + 1 = hour; // compiler error } } diff --git a/ch03/GuessStarter.java b/ch03/GuessStarter.java index 92d7f50..f3240c0 100644 --- a/ch03/GuessStarter.java +++ b/ch03/GuessStarter.java @@ -1,7 +1,7 @@ import java.util.Random; /** - * Starter code for the "guess my number" exercise. + * Starter code for the "Guess My Number" exercise. */ public class GuessStarter { diff --git a/ch06/Recursive.java b/ch06/Recursive.java index 0d29924..f045844 100644 --- a/ch06/Recursive.java +++ b/ch06/Recursive.java @@ -8,7 +8,7 @@ public static int prod(int m, int n) { if (m == n) { return n; } else { - int recurse = prod(m, n-1); + int recurse = prod(m, n - 1); int result = n * recurse; return result; } diff --git a/ch06/Series.java b/ch06/Series.java index 8ce7c30..6db5643 100644 --- a/ch06/Series.java +++ b/ch06/Series.java @@ -12,12 +12,12 @@ public static void countup(int n) { } } - public static double area(double radius) { - double area = Math.PI * radius * radius; - return area; + public static double calculateArea(double radius) { + double result = Math.PI * radius * radius; + return result; } - public static double area2(double radius) { + public static double calculateArea2(double radius) { return Math.PI * radius * radius; } @@ -59,13 +59,13 @@ public static double absoluteValue(double x) { public static double circleArea (double xc, double yc, double xp, double yp) { double radius = distance(xc, yc, xp, yp); - double area = area(radius); + double area = calculateArea(radius); return area; } - public static double area + public static double calculateArea (double xc, double yc, double xp, double yp) { - return area(distance(xc, yc, xp, yp)); + return calculateArea(distance(xc, yc, xp, yp)); } /** @@ -106,17 +106,17 @@ public static void main(String[] args) { countup(3); System.out.println("Have a nice day."); - System.out.println("area"); - System.out.println(area(3.0)); + System.out.println("calculateArea"); + System.out.println(calculateArea(3.0)); - System.out.println("area2"); - System.out.println(area2(3.0)); + System.out.println("calculateArea2"); + System.out.println(calculateArea2(3.0)); System.out.println("circleArea"); System.out.println(circleArea(1.0, 2.0, 4.0, 6.0)); - System.out.println("area with 4 doubles"); - System.out.println(area(1.0, 2.0, 4.0, 6.0)); + System.out.println("calculateArea with 4 doubles"); + System.out.println(calculateArea(1.0, 2.0, 4.0, 6.0)); System.out.println("absolute value"); System.out.println(absoluteValue(-2)); @@ -133,11 +133,11 @@ public static void main(String[] args) { System.out.println(isSingleDigit(2)); boolean bigFlag = !isSingleDigit2(17); - int i = 9; - if (isSingleDigit(i)) { - System.out.println("i is small"); + int z = 9; + if (isSingleDigit(z)) { + System.out.println("z is small"); } else { - System.out.println("i is big"); + System.out.println("z is big"); } System.out.println("factorial"); diff --git a/ch06/SeriesTest.java b/ch06/SeriesTest.java index 7517c85..93b5420 100644 --- a/ch06/SeriesTest.java +++ b/ch06/SeriesTest.java @@ -1,5 +1,8 @@ import junit.framework.TestCase; +/** + * Example JUnit test from Appendix A. + */ public class SeriesTest extends TestCase { public void testFibonacci() { diff --git a/ch07/Loops.java b/ch07/Loops.java index 58c7bd6..d5c915f 100644 --- a/ch07/Loops.java +++ b/ch07/Loops.java @@ -1,5 +1,6 @@ -import java.util.Scanner; - +/** + * Examples from Chapter 7. + */ public class Loops { public static void countdown(int n) { @@ -21,52 +22,6 @@ public static void sequence(int n) { } } - public static double scanDouble() { - Scanner in = new Scanner(System.in); - boolean okay; - do { - System.out.print("Enter a number: "); - if (in.hasNextDouble()) { - okay = true; - } else { - okay = false; - String word = in.next(); - System.err.println(word + " is not a number"); - } - } while (!okay); - double x = in.nextDouble(); - return x; - } - - public static double scanDouble2() { - Scanner in = new Scanner(System.in); - while (true) { - System.out.print("Enter a number: "); - if (in.hasNextDouble()) { - break; - } - String word = in.next(); - System.err.println(word + " is not a number"); - } - double x = in.nextDouble(); - return x; - } - - public static double addNumbers() { - Scanner in = new Scanner(System.in); - int x = -1; - int sum = 0; - while (x != 0) { - x = in.nextInt(); - if (x <= 0) { - continue; - } - System.out.println("Adding " + x); - sum += x; - } - return sum; - } - public static void main(String[] args) { System.out.println("countdown"); countdown(3); @@ -74,5 +29,4 @@ public static void main(String[] args) { System.out.println("sequence"); sequence(10); } - } diff --git a/ch07/Tables.java b/ch07/Tables.java index e586699..0fbfbbe 100644 --- a/ch07/Tables.java +++ b/ch07/Tables.java @@ -1,5 +1,5 @@ /** - * Examples from Chapter 7. + * Generating tables; encapsulation and generalization. */ public class Tables { diff --git a/ch07/Validate.java b/ch07/Validate.java new file mode 100644 index 0000000..eeb81da --- /dev/null +++ b/ch07/Validate.java @@ -0,0 +1,53 @@ +import java.util.Scanner; + +/** + * Do-while, break, and continue. + */ +public class Validate { + + public static double scanDouble() { + Scanner in = new Scanner(System.in); + boolean okay; + do { + System.out.print("Enter a number: "); + if (in.hasNextDouble()) { + okay = true; + } else { + okay = false; + String word = in.next(); + System.err.println(word + " is not a number"); + } + } while (!okay); + double x = in.nextDouble(); + return x; + } + + public static double scanDouble2() { + Scanner in = new Scanner(System.in); + while (true) { + System.out.print("Enter a number: "); + if (in.hasNextDouble()) { + break; + } + String word = in.next(); + System.err.println(word + " is not a number"); + } + double x = in.nextDouble(); + return x; + } + + public static double addNumbers() { + Scanner in = new Scanner(System.in); + int x = -1; + int sum = 0; + while (x != 0) { + x = in.nextInt(); + if (x <= 0) { + continue; + } + System.out.println("Adding " + x); + sum += x; + } + return sum; + } +} From ae811e02f8259d7d5cef3559914605fb3bdce8c0 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Fri, 29 Apr 2016 15:56:57 -0400 Subject: [PATCH 23/29] review ap01..ch07 --- ap01/Series.java | 25 +++++++++++++++++++++++++ {ch06 => ap01}/SeriesTest.java | 1 + ap02/Drawing.java | 5 +---- ap02/Mickey.java | 17 +++++++---------- ap02/Moire.java | 29 +++++++++-------------------- ch01/Goodbye.java | 1 + ch01/Hello.java | 1 + ch02/Variables.java | 2 +- ch03/Convert.java | 1 + ch03/Echo.java | 1 + ch03/GuessStarter.java | 1 + ch03/Input.java | 1 + ch03/ScannerBug.java | 1 + ch04/Methods.java | 1 + ch04/NewLine.java | 1 + ch04/PrintTime.java | 1 + ch04/PrintTwice.java | 1 + ch06/Series.java | 1 + ch07/Exercise.java | 19 +++++++++++++++++++ ch07/Loops.java | 1 + ch07/Tables.java | 1 + ch07/Validate.java | 1 + 22 files changed, 78 insertions(+), 35 deletions(-) create mode 100644 ap01/Series.java rename {ch06 => ap01}/SeriesTest.java (99%) create mode 100644 ch07/Exercise.java diff --git a/ap01/Series.java b/ap01/Series.java new file mode 100644 index 0000000..2d2d66c --- /dev/null +++ b/ap01/Series.java @@ -0,0 +1,25 @@ +/** + * Example method from Chapter 6. + */ +public class Series { + + public static int fibonacci(int n) { + if (n == 1 || n == 2) { + return 1; + } + return fibonacci(n - 1) + fibonacci(n - 2); + } + + public static void main(String[] args) { + if (fibonacci(1) != 1) { + System.err.println("fibonacci(1) is incorrect"); + } + if (fibonacci(2) != 1) { + System.err.println("fibonacci(2) is incorrect"); + } + if (fibonacci(3) != 2) { + System.err.println("fibonacci(3) is incorrect"); + } + } + +} diff --git a/ch06/SeriesTest.java b/ap01/SeriesTest.java similarity index 99% rename from ch06/SeriesTest.java rename to ap01/SeriesTest.java index 93b5420..6309616 100644 --- a/ch06/SeriesTest.java +++ b/ap01/SeriesTest.java @@ -10,4 +10,5 @@ public void testFibonacci() { assertEquals(1, Series.fibonacci(2)); assertEquals(2, Series.fibonacci(3)); } + } diff --git a/ap02/Drawing.java b/ap02/Drawing.java index 1453913..e82bfca 100644 --- a/ap02/Drawing.java +++ b/ap02/Drawing.java @@ -4,10 +4,6 @@ public class Drawing extends Canvas { - // this is here to suppress a warning; you can read about it at - // http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html - static final long serialVersionUID = 1; - public static void main(String[] args) { JFrame frame = new JFrame("My Drawing"); Canvas drawing = new Drawing(); @@ -20,4 +16,5 @@ public static void main(String[] args) { public void paint(Graphics g) { g.fillOval(100, 100, 200, 200); } + } diff --git a/ap02/Mickey.java b/ap02/Mickey.java index 14e93b9..6dfa3bc 100644 --- a/ap02/Mickey.java +++ b/ap02/Mickey.java @@ -1,20 +1,16 @@ import java.awt.Canvas; +import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; - import javax.swing.JFrame; - public class Mickey extends Canvas { - // this is here to suppress a warning; you can read about it at - // http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html - static final long serialVersionUID = 1; - public static void main(String[] args) { - JFrame frame = new JFrame("My Drawing"); + JFrame frame = new JFrame("Mickey Mouse"); Canvas canvas = new Mickey(); canvas.setSize(400, 400); + canvas.setBackground(Color.white); frame.add(canvas); frame.pack(); frame.setVisible(true); @@ -25,6 +21,10 @@ public void paint(Graphics g) { mickey(g, bb); } + public void boxOval(Graphics g, Rectangle bb) { + g.fillOval(bb.x, bb.y, bb.width, bb.height); + } + public void mickey(Graphics g, Rectangle bb) { boxOval(g, bb); @@ -39,7 +39,4 @@ public void mickey(Graphics g, Rectangle bb) { boxOval(g, half); } - public void boxOval(Graphics g, Rectangle bb) { - g.fillOval(bb.x, bb.y, bb.width, bb.height); - } } diff --git a/ap02/Moire.java b/ap02/Moire.java index 78a1c22..750bad3 100644 --- a/ap02/Moire.java +++ b/ap02/Moire.java @@ -1,15 +1,19 @@ import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; - import javax.swing.JFrame; - public class Moire extends Canvas { - // this is here to suppress a warning; you can read about it at - // http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html - static final long serialVersionUID = 1; + public static void main(String[] args) { + JFrame frame = new JFrame("Moire Pattern"); + Canvas canvas = new Moire(); + canvas.setSize(400, 400); + canvas.setBackground(Color.white); + frame.add(canvas); + frame.pack(); + frame.setVisible(true); + } public void paint(Graphics g) { int i = 90; @@ -19,19 +23,4 @@ public void paint(Graphics g) { } } - public static void main(String[] args) { - // make the frame - JFrame frame = new JFrame(); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - // add the canvas - Canvas canvas = new Moire(); - canvas.setSize(400, 400); - canvas.setBackground(Color.white); - frame.getContentPane().add(canvas); - - // show the frame - frame.pack(); - frame.setVisible(true); - } } diff --git a/ch01/Goodbye.java b/ch01/Goodbye.java index 0b165c3..2963e2e 100644 --- a/ch01/Goodbye.java +++ b/ch01/Goodbye.java @@ -10,4 +10,5 @@ public static void main(String[] args) { System.out.print("Goodbye, "); // note the space System.out.println("cruel world"); } + } diff --git a/ch01/Hello.java b/ch01/Hello.java index 13dacf5..593557b 100644 --- a/ch01/Hello.java +++ b/ch01/Hello.java @@ -4,4 +4,5 @@ public static void main(String[] args) { // generate some simple output System.out.println("Hello, World!"); } + } diff --git a/ch02/Variables.java b/ch02/Variables.java index 0312023..a295abf 100644 --- a/ch02/Variables.java +++ b/ch02/Variables.java @@ -6,7 +6,6 @@ public class Variables { public static void main(String[] args) { String message; - int x; String firstName; @@ -80,4 +79,5 @@ public static void main(String[] args) { hour = minute + 1; // correct // minute + 1 = hour; // compiler error } + } diff --git a/ch03/Convert.java b/ch03/Convert.java index 92fc06b..d31fe77 100644 --- a/ch03/Convert.java +++ b/ch03/Convert.java @@ -23,4 +23,5 @@ public static void main(String[] args) { System.out.printf("%.2f cm = %d ft, %d in\n", cm, feet, remainder); } + } diff --git a/ch03/Echo.java b/ch03/Echo.java index b82b2d4..500fd9f 100644 --- a/ch03/Echo.java +++ b/ch03/Echo.java @@ -14,4 +14,5 @@ public static void main(String[] args) { line = in.nextLine(); System.out.println("You also said: " + line); } + } diff --git a/ch03/GuessStarter.java b/ch03/GuessStarter.java index f3240c0..64984df 100644 --- a/ch03/GuessStarter.java +++ b/ch03/GuessStarter.java @@ -11,4 +11,5 @@ public static void main(String[] args) { int number = random.nextInt(100) + 1; System.out.println(number); } + } diff --git a/ch03/Input.java b/ch03/Input.java index 574290d..de97dc0 100644 --- a/ch03/Input.java +++ b/ch03/Input.java @@ -12,4 +12,5 @@ public static void main(String[] args) { double pi = 3.14159; double x = (int) pi * 20.0; } + } diff --git a/ch03/ScannerBug.java b/ch03/ScannerBug.java index 7a2d079..353affb 100644 --- a/ch03/ScannerBug.java +++ b/ch03/ScannerBug.java @@ -22,4 +22,5 @@ public static void main(String[] args) { name = in.nextLine(); System.out.printf("Hello %s, age %d\n", name, age); } + } diff --git a/ch04/Methods.java b/ch04/Methods.java index 035a392..90c1b7a 100644 --- a/ch04/Methods.java +++ b/ch04/Methods.java @@ -18,4 +18,5 @@ public static void main(String[] args) { double x3 = Math.exp(Math.log(10.0)); double x4 = Math.pow(2.0, 10.0); } + } diff --git a/ch04/NewLine.java b/ch04/NewLine.java index b13ddfc..a554e40 100644 --- a/ch04/NewLine.java +++ b/ch04/NewLine.java @@ -15,4 +15,5 @@ public static void main(String[] args) { threeLine(); System.out.println("Second line."); } + } diff --git a/ch04/PrintTime.java b/ch04/PrintTime.java index fe3549c..019d579 100644 --- a/ch04/PrintTime.java +++ b/ch04/PrintTime.java @@ -11,4 +11,5 @@ public static void main(String[] args) { int minute = 59; printTime(hour, minute); } + } diff --git a/ch04/PrintTwice.java b/ch04/PrintTwice.java index c34ed1c..7131085 100644 --- a/ch04/PrintTwice.java +++ b/ch04/PrintTwice.java @@ -8,4 +8,5 @@ public static void printTwice(String s) { public static void main(String[] args) { printTwice("Don't make me say this twice!"); } + } diff --git a/ch06/Series.java b/ch06/Series.java index 6db5643..10d2b41 100644 --- a/ch06/Series.java +++ b/ch06/Series.java @@ -146,4 +146,5 @@ public static void main(String[] args) { System.out.println("fibonacci"); System.out.println(fibonacci(3)); } + } diff --git a/ch07/Exercise.java b/ch07/Exercise.java new file mode 100644 index 0000000..6c7b3df --- /dev/null +++ b/ch07/Exercise.java @@ -0,0 +1,19 @@ +public class Exercise { + + public static void main(String[] args) { + loop(10); + } + + public static void loop(int n) { + int i = n; + while (i > 1) { + System.out.println(i); + if (i % 2 == 0) { + i = i / 2; + } else { + i = i + 1; + } + } + } + +} diff --git a/ch07/Loops.java b/ch07/Loops.java index d5c915f..dfc03ce 100644 --- a/ch07/Loops.java +++ b/ch07/Loops.java @@ -29,4 +29,5 @@ public static void main(String[] args) { System.out.println("sequence"); sequence(10); } + } diff --git a/ch07/Tables.java b/ch07/Tables.java index 0fbfbbe..44e9e62 100644 --- a/ch07/Tables.java +++ b/ch07/Tables.java @@ -153,4 +153,5 @@ public static void main(String[] args) { System.out.println("printTable4"); printTable4(6); } + } diff --git a/ch07/Validate.java b/ch07/Validate.java index eeb81da..e825705 100644 --- a/ch07/Validate.java +++ b/ch07/Validate.java @@ -50,4 +50,5 @@ public static double addNumbers() { } return sum; } + } From a60b1d128cd92c17881aa4fc5f60488e60dcc882 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Fri, 29 Apr 2016 16:03:49 -0400 Subject: [PATCH 24/29] review ch08..ch11 --- ch08/ArrayExamples.java | 56 --------------------------- ch08/Fruit.java | 35 +++++++++++++++++ ch08/Histogram.java | 59 ++++++++++++++++++++++++++++ ch08/MakeDubMus.java | 34 ++++++++++++++++ ch09/Exercise.java | 22 +++++++++++ ch09/Max.java | 5 +++ ch09/Recurse.java | 34 ++++++++++++++++ ch09/StringsThings.java | 86 +++++++++++++++++++++++++++++++---------- ch10/Max.java | 23 ----------- ch10/PointRect.java | 59 +++++++++++++++++++++------- ch10/Pow.java | 24 ++++++++++++ ch10/Riddle.java | 23 +++++++++++ ch11/Time.java | 16 -------- ch11/TimeClient.java | 29 +++++++++++--- 14 files changed, 370 insertions(+), 135 deletions(-) create mode 100644 ch08/Fruit.java create mode 100644 ch08/Histogram.java create mode 100644 ch08/MakeDubMus.java create mode 100644 ch09/Exercise.java create mode 100644 ch09/Recurse.java delete mode 100644 ch10/Max.java create mode 100644 ch10/Pow.java create mode 100644 ch10/Riddle.java diff --git a/ch08/ArrayExamples.java b/ch08/ArrayExamples.java index a9a4e9a..a4cb6c3 100644 --- a/ch08/ArrayExamples.java +++ b/ch08/ArrayExamples.java @@ -1,5 +1,4 @@ import java.util.Arrays; -import java.util.Random; /** * Demonstrates uses of arrays. @@ -62,8 +61,6 @@ public static void main(String[] args) { // reduce double total = sum(a); System.out.println("total = " + total); - - makeHistogram(); } /** @@ -100,57 +97,4 @@ public static double sum(double[] a) { return total; } - /** - * Returns an array of random integers. - */ - public static int[] randomArray(int size) { - Random random = new Random(); - int[] a = new int[size]; - for (int i = 0; i < a.length; i++) { - a[i] = random.nextInt(100); - } - return a; - } - - /** - * Computes the number of array elements in [low, high). - */ - public static int inRange(int[] a, int low, int high) { - int count = 0; - for (int i = 0; i < a.length; i++) { - if (a[i] >= low && a[i] < high) { - count++; - } - } - return count; - } - - /** - * Example code related to histograms. - */ - public static void makeHistogram() { - int numValues = 8; - int[] array = randomArray(numValues); - printArray(array); - - int[] scores = randomArray(30); - int a = inRange(scores, 90, 100); - int b = inRange(scores, 80, 90); - int c = inRange(scores, 70, 80); - int d = inRange(scores, 60, 70); - int f = inRange(scores, 0, 60); - - // making a histogram - int[] counts = new int[100]; - for (int i = 0; i < scores.length; i++) { - int index = scores[i]; - counts[index]++; - } - - // histogram with enhanced for loop - counts = new int[100]; - for (int score : scores) { - counts[score]++; - } - } } diff --git a/ch08/Fruit.java b/ch08/Fruit.java new file mode 100644 index 0000000..50428c5 --- /dev/null +++ b/ch08/Fruit.java @@ -0,0 +1,35 @@ +/** + * Fruit exercise. + */ +public class Fruit { + + public static int banana(int[] a) { + int kiwi = 1; + int i = 0; + while (i < a.length) { + kiwi = kiwi * a[i]; + i++; + } + return kiwi; + } + + public static int grapefruit(int[] a, int grape) { + for (int i = 0; i < a.length; i++) { + if (a[i] == grape) { + return i; + } + } + return -1; + } + + public static int pineapple(int[] a, int apple) { + int pear = 0; + for (int pine: a) { + if (pine == apple) { + pear++; + } + } + return pear; + } + +} diff --git a/ch08/Histogram.java b/ch08/Histogram.java new file mode 100644 index 0000000..32b029c --- /dev/null +++ b/ch08/Histogram.java @@ -0,0 +1,59 @@ +import java.util.Random; + +/** + * Example code related to histograms. + */ +public class Histogram { + + /** + * Returns an array of random integers. + */ + public static int[] randomArray(int size) { + Random random = new Random(); + int[] a = new int[size]; + for (int i = 0; i < a.length; i++) { + a[i] = random.nextInt(100); + } + return a; + } + + /** + * Computes the number of array elements in [low, high). + */ + public static int inRange(int[] a, int low, int high) { + int count = 0; + for (int i = 0; i < a.length; i++) { + if (a[i] >= low && a[i] < high) { + count++; + } + } + return count; + } + + public static void main(String[] args) { + int numValues = 8; + int[] array = randomArray(numValues); + ArrayExamples.printArray(array); + + int[] scores = randomArray(30); + int a = inRange(scores, 90, 100); + int b = inRange(scores, 80, 90); + int c = inRange(scores, 70, 80); + int d = inRange(scores, 60, 70); + int f = inRange(scores, 0, 60); + + // making a histogram + int[] counts = new int[100]; + for (int i = 0; i < scores.length; i++) { + int index = scores[i]; + counts[index]++; + } + + // histogram with enhanced for loop + counts = new int[100]; + for (int score : scores) { + counts[score]++; + } + } + +} diff --git a/ch08/MakeDubMus.java b/ch08/MakeDubMus.java new file mode 100644 index 0000000..9c7e193 --- /dev/null +++ b/ch08/MakeDubMus.java @@ -0,0 +1,34 @@ +/** + * Stack diagram exercise. + */ +public class MakeDubMus { + + public static int[] make(int n) { + int[] a = new int[n]; + for (int i = 0; i < n; i++) { + a[i] = i + 1; + } + return a; + } + + public static void dub(int[] jub) { + for (int i = 0; i < jub.length; i++) { + jub[i] *= 2; + } + } + + public static int mus(int[] zoo) { + int fus = 0; + for (int i = 0; i < zoo.length; i++) { + fus += zoo[i]; + } + return fus; + } + + public static void main(String[] args) { + int[] bob = make(5); + dub(bob); + System.out.println(mus(bob)); + } + +} diff --git a/ch09/Exercise.java b/ch09/Exercise.java new file mode 100644 index 0000000..d8a605d --- /dev/null +++ b/ch09/Exercise.java @@ -0,0 +1,22 @@ +/** + * Exercise on encapsulation and generalization. + */ +public class Exercise { + + public static void main(String[] args) { + String s = "((3 + 7) * 2)"; + int count = 0; + + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + if (c == '(') { + count++; + } else if (c == ')') { + count--; + } + } + + System.out.println(count); + } + +} diff --git a/ch09/Max.java b/ch09/Max.java index 01417f0..2bf923e 100644 --- a/ch09/Max.java +++ b/ch09/Max.java @@ -5,6 +5,9 @@ */ public class Max { + /** + * Converts args to integers and prints the max. + */ public static void main(String[] args) { System.out.println(Arrays.toString(args)); @@ -15,5 +18,7 @@ public static void main(String[] args) { max = value; } } + System.out.println("The max is " + max); } + } diff --git a/ch09/Recurse.java b/ch09/Recurse.java new file mode 100644 index 0000000..c4ba2fb --- /dev/null +++ b/ch09/Recurse.java @@ -0,0 +1,34 @@ +/** + * Recursion exercise. + */ +public class Recurse { + + /** + * Returns the first character of the given String. + */ + public static char first(String s) { + return s.charAt(0); + } + + /** + * Returns all but the first letter of the given String. + */ + public static String rest(String s) { + return s.substring(1); + } + + /** + * Returns all but the first and last letter of the String. + */ + public static String middle(String s) { + return s.substring(1, s.length() - 1); + } + + /** + * Returns the length of the given String. + */ + public static int length(String s) { + return s.length(); + } + +} diff --git a/ch09/StringsThings.java b/ch09/StringsThings.java index 20357c1..8b95e7e 100644 --- a/ch09/StringsThings.java +++ b/ch09/StringsThings.java @@ -3,19 +3,17 @@ */ public class StringsThings { - /** - * Reverses a string, returns a new String. - */ - public static String reverse(String s) { - String r = ""; - for (int i = s.length() - 1; i >= 0; i--) { - r = r + s.charAt(i); - } - return r; - } - public static void main(String[] args) { + // Characters + + String fruit = "banana"; + char letter0 = fruit.charAt(0); + + if (letter0 == 'a') { + System.out.println('?'); + } + System.out.print("Roman alphabet: "); for (char c = 'A'; c <= 'Z'; c++) { System.out.print(c); @@ -28,6 +26,47 @@ public static void main(String[] args) { } System.out.println(); + // Strings are immutable + + String name = "Alan Turing"; + String upperName = name.toUpperCase(); + + String text = "Computer Science is fun!"; + text = text.replace("Computer Science", "CS"); + + // String traversal + + for (int i = 0; i < fruit.length(); i++) { + char letter = fruit.charAt(i); + System.out.println(letter); + } + + for (char letter : fruit.toCharArray()) { + System.out.println(letter); + } + + int length = fruit.length(); + char last = fruit.charAt(length - 1); // correct + + System.out.println(reverse(fruit)); + + // Substrings + + System.out.println(fruit.substring(0)); + System.out.println(fruit.substring(2)); + System.out.println(fruit.substring(6)); + + System.out.println(fruit.substring(0, 3)); + System.out.println(fruit.substring(2, 5)); + System.out.println(fruit.substring(6, 6)); + + // The indexOf method + + int index = fruit.indexOf('a'); + int index2 = fruit.indexOf('a', 2); + + // String comparison + String name1 = "Alan Turing"; String name2 = "Ada Lovelace"; if (name1.equals(name2)) { @@ -43,17 +82,24 @@ public static void main(String[] args) { System.out.println("name2 comes before name1."); } - String fruit = "banana"; + // Wrapper classes - for (int i = 0; i < fruit.length(); i++) { - char letter = fruit.charAt(i); - System.out.println(letter); - } + String str = "12345"; + int num = Integer.parseInt(str); - for (char letter : fruit.toCharArray()) { - System.out.println(letter); - } + num = 12345; + str = Integer.toString(num); + } - System.out.println(reverse(fruit)); + /** + * Reverses a string, returns a new String. + */ + public static String reverse(String s) { + String r = ""; + for (int i = s.length() - 1; i >= 0; i--) { + r = r + s.charAt(i); + } + return r; } + } diff --git a/ch10/Max.java b/ch10/Max.java deleted file mode 100644 index a7ecea5..0000000 --- a/ch10/Max.java +++ /dev/null @@ -1,23 +0,0 @@ -import java.util.Arrays; - -/** - * Demonstrates command-line arguments. - */ -public class Max { - - /** - * Converts the command line arguments to integers and prints the max. - */ - public static void main(String[] args) { - System.out.println(Arrays.toString(args)); - - int max = Integer.MIN_VALUE; - for (String arg : args) { - int value = Integer.parseInt(arg); - if (value > max) { - max = value; - } - } - System.out.println("The max is " + max); - } -} diff --git a/ch10/PointRect.java b/ch10/PointRect.java index d0da1df..36801a5 100644 --- a/ch10/PointRect.java +++ b/ch10/PointRect.java @@ -6,6 +6,28 @@ */ public class PointRect { + public static void main(String[] args) { + Point blank; + blank = new Point(3, 4); + System.out.println(blank); + + int x = blank.x; + System.out.println(blank.x + ", " + blank.y); + int sum = blank.x * blank.x + blank.y * blank.y; + + Rectangle box = new Rectangle(0, 0, 100, 200); + moveRect(box, 50, 100); + System.out.println(box); + box.translate(50, 100); + + Rectangle box1 = new Rectangle(0, 0, 100, 200); + Rectangle box2 = box1; + + System.out.println(box2.width); + box1.grow(50, 50); + System.out.println(box2.width); + } + /** * Prints the attributes of a Point object. */ @@ -17,8 +39,8 @@ public static void printPoint(Point p) { * Computes the distance between two points. */ public static double distance(Point p1, Point p2) { - double dx = (double) (p2.x - p1.x); - double dy = (double) (p2.y - p1.y); + int dx = p2.x - p1.x; + int dy = p2.y - p1.y; return Math.sqrt(dx * dx + dy * dy); } @@ -40,22 +62,29 @@ public static void moveRect(Rectangle box, int dx, int dy) { } /** - * Tests the methods in this class. + * Exercise on returning objects. */ - public static void main(String[] args) { - Point blank; - blank = new Point(3, 4); - System.out.println(blank); + public static void exercise2() { + Point blank = new Point(5, 8); - Rectangle box = new Rectangle(0, 0, 100, 200); - moveRect(box, 50, 100); - System.out.println(box); + Rectangle rect = new Rectangle(0, 2, 4, 4); + Point center = findCenter(rect); - Rectangle box1 = new Rectangle(0, 0, 100, 200); - Rectangle box2 = box1; + double dist = distance(center, blank); + System.out.println(dist); + } - System.out.println(box2.width); - box1.grow(50, 50); - System.out.println(box2.width); + /** + * Exercise on aliasing. + */ + public static void exercise3() { + Rectangle box1 = new Rectangle(2, 4, 7, 9); + Point p1 = findCenter(box1); + printPoint(p1); + + box1.grow(1, 1); + Point p2 = findCenter(box1); + printPoint(p2); } + } diff --git a/ch10/Pow.java b/ch10/Pow.java new file mode 100644 index 0000000..9ba0952 --- /dev/null +++ b/ch10/Pow.java @@ -0,0 +1,24 @@ +/** + * BigInteger exercise. + */ +public class Pow { + + /** + * Integer exponentiation. + */ + public static int pow(int x, int n) { + if (n == 0) return 1; + + // find x to the n/2 recursively + int t = pow(x, n / 2); + + // if n is even, the result is t squared + // if n is odd, the result is t squared times x + if (n % 2 == 0) { + return t * t; + } else { + return t * t * x; + } + } + +} diff --git a/ch10/Riddle.java b/ch10/Riddle.java new file mode 100644 index 0000000..cd04a16 --- /dev/null +++ b/ch10/Riddle.java @@ -0,0 +1,23 @@ +import java.awt.Point; + +/** + * Exercise on passing objects as parameters. + */ +public class Riddle { + + public static int riddle(int x, Point p) { + x = x + 7; + return x + p.x + p.y; + } + + public static void main(String[] args) { + int x = 5; + Point blank = new Point(1, 2); + + System.out.println(riddle(x, blank)); + System.out.println(x); + System.out.println(blank.x); + System.out.println(blank.y); + } + +} diff --git a/ch11/Time.java b/ch11/Time.java index 99e75db..53afa0d 100644 --- a/ch11/Time.java +++ b/ch11/Time.java @@ -99,20 +99,4 @@ public void increment(double seconds) { } } - /** - * Test the methods in this class. - */ - public static void main(String[] args) { - Time time = new Time(11, 59, 59.9); - System.out.println(time); - - 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)); - } } diff --git a/ch11/TimeClient.java b/ch11/TimeClient.java index 59ef451..aa90401 100644 --- a/ch11/TimeClient.java +++ b/ch11/TimeClient.java @@ -3,12 +3,31 @@ */ public class TimeClient { - /** - * Demonstrates that we cannot access private variables from another - * class. - */ public static void main(String[] args) { Time time = new Time(11, 59, 59.9); - System.out.println(time.hour); // ERROR + 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); } + } From eaf96b152df96ba3af4eef74917d3fff37665eee Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Fri, 29 Apr 2016 16:07:13 -0400 Subject: [PATCH 25/29] review ch12..ch14 --- ch12/Card.java | 1 + ch12/CardTable.java | 11 +++--- ch12/Search.java | 66 ++++++++++++++++++++---------------- ch13/Deck.java | 36 ++++++++++++++++++++ ch13/Test.java | 1 + ch14/CardCollection.java | 72 ++++++++++++++++++---------------------- ch14/Deck.java | 1 + ch14/Eights.java | 62 +++++++++++++++++----------------- ch14/Hand.java | 1 + ch14/Player.java | 8 +---- ch14/Test.java | 8 ++--- 11 files changed, 151 insertions(+), 116 deletions(-) diff --git a/ch12/Card.java b/ch12/Card.java index 7bd1202..e7a0661 100644 --- a/ch12/Card.java +++ b/ch12/Card.java @@ -79,4 +79,5 @@ public int position() { public String toString() { return RANKS[this.rank] + " of " + SUITS[this.suit]; } + } diff --git a/ch12/CardTable.java b/ch12/CardTable.java index 5b2b8ca..727d307 100644 --- a/ch12/CardTable.java +++ b/ch12/CardTable.java @@ -7,13 +7,10 @@ import javax.swing.JFrame; public class CardTable extends Canvas { + private Image[][] images; private int cardWidth, cardHeight; - // this long is here to suppress a warning; you can read about it at - // http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html - static final long serialVersionUID = 1; - /** * Creates a CardTable. * cardset is the name of the folder that contains the card images. @@ -29,7 +26,8 @@ public CardTable(String cardset) { char c = suits.charAt(suit); for (int rank = 1; rank <= 13; rank++) { - String s = String.format("%s/%02d%c.gif", cardset, rank, c); + String s = String.format("%s/%02d%c.gif", + cardset, rank, c); images[rank][suit] = new ImageIcon(s).getImage(); } } @@ -79,7 +77,7 @@ public void paint(Graphics g) { public static void main(String[] args) { // make the frame - JFrame frame = new JFrame(); + JFrame frame = new JFrame("Card Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // add the CardTable @@ -91,4 +89,5 @@ public static void main(String[] args) { frame.pack(); frame.setVisible(true); } + } diff --git a/ch12/Search.java b/ch12/Search.java index 3cfe2d1..2f83023 100644 --- a/ch12/Search.java +++ b/ch12/Search.java @@ -3,6 +3,30 @@ */ public class Search { + /** + * Make an array of 52 cards. + */ + public static Card[] makeDeck() { + Card[] cards = new Card[52]; + int index = 0; + for (int suit = 0; suit <= 3; suit++) { + for (int rank = 1; rank <= 13; rank++) { + cards[index] = new Card(rank, suit); + index++; + } + } + return cards; + } + + /** + * Displays the given deck of cards. + */ + public static void printDeck(Card[] cards) { + for (int i = 0; i < cards.length; i++) { + System.out.println(cards[i]); + } + } + /** * Sequential search. */ @@ -24,14 +48,14 @@ public static int binarySearch(Card[] cards, Card target) { while (low <= high) { System.out.println(low + ", " + high); - int mid = (low + high) / 2; // step 1 + int mid = (low + high) / 2; // step 1 int comp = cards[mid].compareTo(target); - if (comp == 0) { // step 2 + if (comp == 0) { // step 2 return mid; - } else if (comp < 0) { // step 3 + } else if (comp < 0) { // step 3 low = mid + 1; - } else { // step 4 + } else { // step 4 high = mid - 1; } } @@ -41,40 +65,25 @@ public static int binarySearch(Card[] cards, Card target) { /** * Binary search (recursive version). */ - public static int binarySearchRec(Card[] cards, Card target, - int low, int high) { + public static int binarySearch(Card[] cards, Card target, + int low, int high) { System.out.println(low + ", " + high); if (high < low) { return -1; } - int mid = (low + high) / 2; // step 1 + int mid = (low + high) / 2; // step 1 int comp = cards[mid].compareTo(target); - if (comp == 0) { // step 2 + if (comp == 0) { // step 2 return mid; - } else if (comp < 0) { // step 3 - return binarySearchRec(cards, target, mid + 1, high); - } else { // step 4 - return binarySearchRec(cards, target, low, mid - 1); + } else if (comp < 0) { // step 3 + return binarySearch(cards, target, mid + 1, high); + } else { // step 4 + return binarySearch(cards, target, low, mid - 1); } } - /** - * Make an array of 52 cards. - */ - public static Card[] makeDeck() { - Card[] cards = new Card[52]; - int index = 0; - for (int suit = 0; suit <= 3; suit++) { - for (int rank = 1; rank <= 13; rank++) { - cards[index] = new Card(rank, suit); - index++; - } - } - return cards; - } - /** * Demonstrates how to call the search methods. */ @@ -96,7 +105,8 @@ public static void main(String[] args) { System.out.println(); System.out.println("Recursive binary search"); - System.out.println(binarySearch(cards, jack)); + System.out.println(binarySearch(cards, jack, 0, 51)); System.out.println(); } + } diff --git a/ch13/Deck.java b/ch13/Deck.java index 864d52e..742120e 100644 --- a/ch13/Deck.java +++ b/ch13/Deck.java @@ -45,12 +45,40 @@ public void print() { } } + /** + * Returns a string representation of the deck. + */ + public String toString() { + return Arrays.toString(this.cards); + } + + /** + * Chooses a random number between low and high, including both. + */ + public int randomInt(int low, int high) { + return 0; + } + + /** + * Swaps the cards at indexes i and j. + */ + public void swapCards(int i, int j) { + } + /** * Randomly permutes the array of cards. */ public void shuffle() { } + /** + * Finds the index of the lowest card + * between low and high inclusive. + */ + public int indexLowest(int low, int high) { + return 0; + } + /** * Sorts the cards (in place) using selection sort. */ @@ -68,6 +96,13 @@ public Deck subdeck(int low, int high) { return sub; } + /** + * Combines two previously sorted subdecks. + */ + public static Deck merge(Deck d1, Deck d2) { + return null; + } + /** * Returns a sorted copy of the deck using merge sort. */ @@ -80,4 +115,5 @@ public Deck mergeSort() { */ public void insertionSort() { } + } diff --git a/ch13/Test.java b/ch13/Test.java index c5431ee..5f49ef1 100644 --- a/ch13/Test.java +++ b/ch13/Test.java @@ -39,4 +39,5 @@ public static void main(String[] args) { deck.insertionSort(); checkSorted(deck); } + } diff --git a/ch14/CardCollection.java b/ch14/CardCollection.java index 5129496..f9c3be2 100644 --- a/ch14/CardCollection.java +++ b/ch14/CardCollection.java @@ -18,44 +18,46 @@ public CardCollection(String label) { } /** - * Returns the label. + * Returns the label of the card collection. */ public String getLabel() { return label; } /** - * Returns the number of cards. + * Adds the given card to the collection. */ - public int size() { - return cards.size(); + public void addCard(Card card) { + cards.add(card); } /** - * True if the collection is empty, false otherwise. + * Removes and returns the card with the given index. */ - public boolean empty() { - return cards.size() == 0; + public Card popCard(int i) { + return cards.remove(i); } /** - * Randomly permute the cards. + * Removes and returns the last card. */ - public void shuffle() { - Random random = new Random(); - for (int i = size() - 1; i > 0; i--) { - int j = random.nextInt(i); - swapCards(i, j); - } + public Card popCard() { + int i = size() - 1; + return popCard(i); } /** - * Swaps the cards at indexes i and j. + * Returns the number of cards. */ - public void swapCards(int i, int j) { - Card temp = cards.get(i); - cards.set(i, cards.get(j)); - cards.set(j, temp); + public int size() { + return cards.size(); + } + + /** + * True if the collection is empty, false otherwise. + */ + public boolean empty() { + return cards.size() == 0; } /** @@ -76,13 +78,6 @@ public void dealAll(CardCollection that) { deal(that, n); } - /** - * Adds the given card to the collection. - */ - public void addCard(Card card) { - cards.add(card); - } - /** * Returns the card with the given index. */ @@ -99,18 +94,23 @@ public Card last() { } /** - * Removes and returns the card with the given index. + * Swaps the cards at indexes i and j. */ - public Card popCard(int i) { - return cards.remove(i); + public void swapCards(int i, int j) { + Card temp = cards.get(i); + cards.set(i, cards.get(j)); + cards.set(j, temp); } /** - * Removes and returns the last card. + * Randomly permute the cards. */ - public Card popCard() { - int i = size() - 1; - return popCard(i); + public void shuffle() { + Random random = new Random(); + for (int i = size() - 1; i > 0; i--) { + int j = random.nextInt(i); + swapCards(i, j); + } } /** @@ -120,10 +120,4 @@ public String toString() { return label + ": " + cards.toString(); } - /** - * Gets the internal cards array (should only be used for testing). - */ - public Card[] getCards() { - return (Card[]) cards.toArray(); - } } diff --git a/ch14/Deck.java b/ch14/Deck.java index 10ba798..8db1814 100644 --- a/ch14/Deck.java +++ b/ch14/Deck.java @@ -15,4 +15,5 @@ public Deck(String label) { } } } + } diff --git a/ch14/Eights.java b/ch14/Eights.java index 78a767b..13b7961 100644 --- a/ch14/Eights.java +++ b/ch14/Eights.java @@ -40,17 +40,6 @@ public Eights() { in = new Scanner(System.in); } - /** - * Displays the state of the game. - */ - public void displayState() { - one.display(); - two.display(); - discardPile.display(); - System.out.print("Draw pile: "); - System.out.println(drawPile.size() + " cards"); - } - /** * Returns true if either hand is empty. */ @@ -75,19 +64,6 @@ public void reshuffle() { drawPile.shuffle(); } - /** - * One player takes a turn. - */ - public void takeTurn(Player player) { - Card prev = discardPile.last(); - Card next = player.play(this, prev); - - System.out.println(player.getName() + " plays " + next); - System.out.println(); - - discardPile.addCard(next); - } - /** * Returns a card from the draw pile. */ @@ -98,13 +74,6 @@ public Card draw() { return drawPile.popCard(); } - /** - * Waits for the user to press enter. - */ - public void waitForUser() { - in.nextLine(); - } - /** * Switches players. */ @@ -116,6 +85,36 @@ public Player nextPlayer(Player current) { } } + /** + * Displays the state of the game. + */ + public void displayState() { + one.display(); + two.display(); + discardPile.display(); + System.out.print("Draw pile: "); + System.out.println(drawPile.size() + " cards"); + } + + /** + * Waits for the user to press enter. + */ + public void waitForUser() { + in.nextLine(); + } + + /** + * One player takes a turn. + */ + public void takeTurn(Player player) { + Card prev = discardPile.last(); + Card next = player.play(this, prev); + discardPile.addCard(next); + + System.out.println(player.getName() + " plays " + next); + System.out.println(); + } + /** * Plays the game. */ @@ -142,4 +141,5 @@ public static void main(String[] args) { Eights game = new Eights(); game.playGame(); } + } diff --git a/ch14/Hand.java b/ch14/Hand.java index a65b7f5..8089a49 100644 --- a/ch14/Hand.java +++ b/ch14/Hand.java @@ -20,4 +20,5 @@ public void display() { } System.out.println(); } + } diff --git a/ch14/Player.java b/ch14/Player.java index c9c9695..433ff28 100644 --- a/ch14/Player.java +++ b/ch14/Player.java @@ -101,13 +101,6 @@ public int score() { return sum; } - /** - * Returns a string representation of the player. - */ - public String toString() { - return name + ": " + hand; - } - /** * Displays the player's hand. */ @@ -121,4 +114,5 @@ public void display() { public void displayScore() { System.out.println(name + " has " + score() + " points"); } + } diff --git a/ch14/Test.java b/ch14/Test.java index 0e5c243..274710c 100644 --- a/ch14/Test.java +++ b/ch14/Test.java @@ -3,13 +3,9 @@ */ public class Test { - /** - * Test code. - */ public static void main(String[] args) { Deck deck = new Deck("Deck"); deck.shuffle(); - System.out.println(deck); Hand hand = new Hand("Hand"); deck.deal(hand, 5); @@ -17,6 +13,8 @@ public static void main(String[] args) { Hand drawPile = new Hand("Draw Pile"); deck.dealAll(drawPile); - System.out.println(drawPile.size()); + System.out.printf("Draw Pile has %d cards.\n", + drawPile.size()); } + } From 390cbbe83b803fe6a01be0baf659804755082de1 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Fri, 6 May 2016 09:33:10 -0400 Subject: [PATCH 26/29] sync with 6.1.0 --- LICENSE | 2 +- README.md | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/LICENSE b/LICENSE index 749dcd6..89ed830 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 Allen Downey +Copyright (c) 2016 Allen Downey and Chris Mayfield Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index fe3da55..10592d0 100644 --- a/README.md +++ b/README.md @@ -13,17 +13,19 @@ If you don't already have a GitHub account, you'll need to create one. After forking, you'll have your own repository on GitHub that you can use to keep track of code you write. Then you can ``clone'' the repository, which downloads a copy of the files to your computer. -* Or you could clone the repository without forking. If you choose this option, you don't need a GitHub account, but you won't be able to save your changes back in GitHub. +* Alternatively, you could clone the repository without forking. +If you choose this option, you don't need a GitHub account, but you won't be able to save your changes back in GitHub. * If you don't want to use Git at all, you can download the code in a zip archive using the "Download ZIP" button on this page, or [this link](http://tinyurl.com/ThinkJavaCodeZip). -To clone a repository, you need a Git client installed on your computer. The URL of this repository is `https://github.com/AllenDowney/ThinkJavaCode.git`. If you use Git from the command line, you can clone it like this: +To clone a repository, you need a Git client installed on your computer. +The URL of this repository is `https://github.com/AllenDowney/ThinkJavaCode.git`. +If you use Git from the command line, you can clone it like this: git clone https://github.com/AllenDowney/ThinkJavaCode.git After you clone the repository or unzip the zip file, you should have a directory called `ThinkJavaCode` with a subdirectory for each chapter in the book. -All the examples in this book were developed and tested using Java SE Development Kit 7. +All examples in this book were developed and tested using Java SE Development Kit 8. If you are using a more recent version, the examples in this book should still work. If you are using an older version, some of them may not. - From bc927971a210887c511c9ccd942c6728a79f806c Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Tue, 6 Sep 2016 21:27:43 -0400 Subject: [PATCH 27/29] checkstyle 7.1.1 --- ap02/Moire.java | 2 +- ch05/Conditional.java | 2 -- ch05/Exercise.java | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ap02/Moire.java b/ap02/Moire.java index 750bad3..8e7247f 100644 --- a/ap02/Moire.java +++ b/ap02/Moire.java @@ -18,7 +18,7 @@ public static void main(String[] args) { public void paint(Graphics g) { int i = 90; while (i < getWidth()) { - g.drawOval (0, 0, i, i); + g.drawOval(0, 0, i, i); i = i + 3; } } diff --git a/ch05/Conditional.java b/ch05/Conditional.java index 1fd36ce..f2d6d19 100644 --- a/ch05/Conditional.java +++ b/ch05/Conditional.java @@ -1,5 +1,3 @@ -import java.util.Scanner; - /** * Examples from Chapter 5. */ diff --git a/ch05/Exercise.java b/ch05/Exercise.java index 46774e0..dbbb6e9 100644 --- a/ch05/Exercise.java +++ b/ch05/Exercise.java @@ -18,7 +18,7 @@ public static void main(String[] args) { public static void clink(int fork) { System.out.print("It's "); - zoop("breakfast ", fork) ; + zoop("breakfast ", fork); } public static void ping(String strangStrung) { From 9fb1ef4d514055e2e31c56b786ccbd6c384e41a5 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Tue, 27 Dec 2016 12:27:10 -0500 Subject: [PATCH 28/29] sync with 6.1.2 --- ch05/Logarithm.java | 12 ++++++------ ch07/Tables.java | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ch05/Logarithm.java b/ch05/Logarithm.java index bc21157..5c5986a 100644 --- a/ch05/Logarithm.java +++ b/ch05/Logarithm.java @@ -6,11 +6,13 @@ public static void main(String[] args) { System.out.println("printLogarithm"); printLogarithm(3.0); + Scanner in = new Scanner(System.in); + System.out.println("scandouble"); - scanDouble(); + scanDouble(in); System.out.println("scandouble2"); - scanDouble2(); + scanDouble2(in); } public static void printLogarithm(double x) { @@ -22,15 +24,13 @@ public static void printLogarithm(double x) { System.out.println("The log of x is " + result); } - public static void scanDouble() { - Scanner in = new Scanner(System.in); + public static void scanDouble(Scanner in) { System.out.print("Enter a number: "); double x = in.nextDouble(); printLogarithm(x); } - public static void scanDouble2() { - Scanner in = new Scanner(System.in); + public static void scanDouble2(Scanner in) { System.out.print("Enter a number: "); if (!in.hasNextDouble()) { String word = in.next(); diff --git a/ch07/Tables.java b/ch07/Tables.java index 44e9e62..3e33905 100644 --- a/ch07/Tables.java +++ b/ch07/Tables.java @@ -6,7 +6,7 @@ public class Tables { public static void example() { int i = 1; while (i < 10) { - double x = (double) i; + double x = i; System.out.println(x + " " + Math.log(x)); i = i + 1; } @@ -15,7 +15,7 @@ public static void example() { public static void example2() { int i = 1; while (i < 10) { - double x = (double) i; + double x = i; System.out.println(x + " " + Math.log(x) / Math.log(2)); i = i + 1; } @@ -25,7 +25,7 @@ public static void example3() { final double LOG2 = Math.log(2); int i = 1; while (i < 100) { - double x = (double) i; + double x = i; System.out.println(x + " " + Math.log(x) / LOG2); i = i * 2; } From 373dd806db8685fdbf7a5fa2e9c8c8eb4028cf3b Mon Sep 17 00:00:00 2001 From: Jayaprabhakar Date: Wed, 15 Nov 2017 03:48:30 -0800 Subject: [PATCH 29/29] Add link to source code hosted on Codiva online java ide Let students directly edit, compile and run java programs on Codiva.io Online Java IDE. This is suitable for beginneers of Java, because they don't have to understand Git, in their early days of learning to code. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 10592d0..0a68248 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Git is a version control system that allows you to keep track of the files that A collection of files under Git's control is called a repository. There are several ways you can work with the code: +* You can edit and run the code on [Codiva online java IDE](https://www.codiva.io/tutorials/thinkjavacode). * You can create a copy of this repository on GitHub by pressing the "Fork" button in the upper right. If you don't already have a GitHub account, you'll need to create one.