![]() |
Computer Science 202 |
![]() |

|
CLICK HERE TO INSTALL JAVA & ECLIPSE |
|||||||||||||||||||||||||||||
| Topic | Assignments | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Test-Driven DevelopmentShortcut To Print To Console: Enter the "stuff" to be printed. → Highlight "stuff" with the mouse. → <Ctrl-Space> → <Up-Arrow> → <Enter> → Eclipse surrounds the "stuff" with System.out.println( ). To create a separate testing folder to isolate JUnit testing code from application code: File → New → Source Folder → Folder Name: test → Finish. This avoids deploying testing code with an application. To create a JUnit package containing the same name as the application package being tested: Select ("highlight") the name of the testing folder in the package view → File → New → Package → Type the same name as the source code package. (Both the application and testing package have the same names.) → Finish. To create a JUnit test class: Right mouse click the testing package → New → Other → JUnit → JUnit Test Case → Type name of testing class == name of class to be test followed by "Test" (eg: "BeHappyTest") → Place desired ✓s for method stubs → Finish → Finish. To create a JUnit test suite: Highlight the testing package. → Right mouse click → New → Other → JUnit → JUnit Test Suite → Next → Place desired ✓s → Finish. This creates a single-button test for an entire application! Names of all JUnit testing methods begin with "test..." Variable name that is italicized is a static variable. To open a new Java Scrapbook Page: File → New → Other.... → Select Java → Java Run/Debug → Scrapbook Page. → Click Next. Don't forget to later select ("highlight") the code before clicking the "inspect" button. To automatically generate accessor &/or mutator methods: Source → Generate Getters and Setters... → Place desired ✓s → OK. Quick Fix: <Ctrl><1> ( ie: Control-One ) OR Click on the light bulb. The Java editor offers corrections for most problems underlined with a problem highlight line. TODO Comment: // TODO tada tada tada Comment a section of code: Highlight the section of code → <Ctrl>< / > Toggling <Ctrl>< / > "uncomments" commented code. To provide package access to a class member: Remove all scope modifiers. Scope modifiers are private, public and protected. To convert a local variable to an instance variable (ie: instance "field"): Select a declaration or a reference to a local variable → Refactor → Convert Local Variable to Field... → Select access modifier → Select location for initialization → Select whether field is to be static → Select whether field is to be final (ie: a constant) → OK To automatically extract a method from a block of code: Highlight the lines → Refactor → Extract Method... → Type methodName → OK Same blocks of code throughout the class are replaced by the method call! To automatically create a public method template: Type "pub" (initial three letters of "public") → <Ctrl-Space> → Select "Public_method - public method" → Type "void" or other return type → Enter → Tab → Type "testToString" or other name of method Do a similar process for a private method template. To automatically create the public static void main( String[ ] args ) template: Type "main" → <Ctrl-Space> → Press <Enter> This is the point in Java where execution of the program begins. To automatically create an assertEquals( expected, actual) call: Type "asserte" (initial letters of "assertEquals...") → <Ctrl-Space> → Press Enter → Type "Smith" or other string → Enter → Tab → Type b2.toString() or other string reference call → Type a semicolon to end the statement Do a similar process for other standard method calls. |
For the final code, including all application and testing code, submit a printed copy of a wordprocessing document containing:
|
||||||||||||||||||||||||||||
|
To create an executable JAR file: [ Hint: First save the path to your
project so you can later paste it as the destination location of your executable JAR file →
Right mouse click name of project → Properties → Select ("highlight") the location
(eg: "H:\TotalBeginnerProjects\TB11") → Copy with To check the run of your JAR file from the command line prompt: Copy the path of your JAR file location: Right mouse click name of JAR file → Properties → Select ("highlight") the location sans name of file (eg: "H:\TotalBeginnerProjects\TB16") → Copy with <Ctrl-C> → OK ] → [ Note: In order for the JAR file to "automatically" execute at the command line prompt, the O/S environmental path variable must be contain the path to Java's jar.exe file. An example of the location of a jar.exe file is: C:\Program Files\Java\jdk1.6.0_01\bin.] → Start → Run... → Type cmd in the Open dialog window → A command prompt window (aka DOS window) opens → On the prompt line, type the drive location of the file (eg: "H:) → Press <Enter> → The prompt now reflects the root of the drive where the JAR file is located ( eg: H:\> ) → On the prompt line, type "cd" (stands for "change directory") → Press the space bar once. → Right mouse click the title bar. → Edit → Paste → The prompt line should now include the path of the JAR file. [ eg: H:\TotalBeginnerProjects\TB15\TB16> ] → Type "dir" to call the directory → You should now see the jar file. → At the command line, type "java -jar followed by the name of the jar file. [ eg: java -jar mylibrary.jar ] → Press <Enter> → The JAR file should now execute. |
|||||||||||||||||||||||||||||
Create A "New" Project From An Existing ProjectThese are really "backups of prior stages" of a single, cumulative project. It would be tragic if, upon experiencing a "bug" during tutorial #12 that could not be corrected, you had to redo all eleven prior tutorials in order to continue the project. Taking a few moments at the beginning of each new stage of the project (each new tutorial) ensures that you always have a "last good stage" that is only one tutorial away. This also facilitates later review of code of a specific tutorial at that particular stage of development.
| |||||||||||||||||||||||||||||
| Resources | Assignments | ||||||||||||||||||||||||||||
Boolean |
|||||||||||||||||||||||||||||
Check out former student web pages on this topic:
The ACSL Handout: Boolean Algebra [doc] offers a brief introduction.
Read How Boolean Logic Works on the web site How Stuff Works.
Digital Logic by Ken Bigelow offers a structured and cohesive introduction to Boolean Logic.
Richard Jones' treatment of IB - Boolean Logic as found on his web site, IB Computing Home clarifies IBO's expectations.
Check out xLogicCircuits Lab 1: Logic Circuits from David Eck's book, The Most Complex Machine: A Survey of Computers and Computing.
Do all 10 exercises in Eck's LogicCircuits Lab 1: Logic Circuits [csg] [web]. You cannot normally save from an applet. Do a screen dump to a wordprocessor or paint programme to capture the image: Focus (mouse click) on the applet --> [Alt-PrtScn] --> Go to wordprocessor or paint program --> Focus --> [Ctrl-v].
|
Check out xLogicCircuits Lab 2: Memory Circuits from David Eck's book, The Most Complex Machine: A Survey of Computers and Computing.
Do all 9 exercises in Eck's xLogicCircuits Lab 2: Memory Circuits [csg] [web]. You cannot normally save from an applet. Do a screen dump to a wordprocessor or paint programme to capture the image: Focus (mouse click) on the applet --> [Alt-PrtScn] --> Go to wordprocessor or paint program --> Focus --> [Ctrl-v]. |
| Operator | Logical | Bitwise |
|---|---|---|
| NOT | ! | ~ |
| AND | & && | & |
| OR | | | | | | |
| XOR | ^ | ^![]() |
| shift left | Not Applicable | << |
| arithmetic shift right | Not Applicable | >> |
| bitwise shift right | Not Applicable | >>> |
Check out this TopCoder article: A bit of fun: fun with bits
The ACSL Handout Bit-String Flicking [doc] uses the slang but colourful term flicking to describe these operations which change a one to zero and vice versa.
Review interesting presentations of Boolean Expressions and Short-circuit Operators and Truth Tables and De Morgan's Rules by Bradley Kjell.
Bit and Shift operations are summarized in Horstmann's Big Java 2nd Ed, Appendix M, pages 1158-1160.
This topic is better described as Binary Numbers and Logical Operators. It is an extension of the larger topic about Java Operators.
Note that a pair of symbols are used for the logical operations, "logical AND" [&&] and "inclusive OR" [ | | ] whereas a single symbol is used for bitwise operations, "bitwise AND" [&], "inclusive OR" [ | ], and "exclusive OR" [^].
The usefulness and application of these operations are seen in context in Kjell's course for assembly language programming, Programmed Introduction to MIPS Assembly Language. See in particular Kjell's chapters:
Bit and shift operations compare equivaltent binary patterns of decimal or other integers. See example below.
public class BooleanOps
{
public static void main(String[] args)
{
System.out.println(3 & 22); // 2
System.out.println(13 ^ 6); //11
System.out.println(0 & (3-3)); // 0
System.out.println(45 | 16); //61
System.out.println((2 & 5) | ((7^3) & 5 )); // 4
}
} |
public class DemoXOR
{
public static void main( String[] args )
{
int x = 5, z=10 ;
if ( (x<10) ^ (z>5) )
System.out.println("True Block") ;
else System.out.println("False Block");
}
}
|
Horstmann Chap 8
Kjell 46 47 48 49A 49B 49C 49D
Deitel Chap 7
|
Chapter 8 Demo Source Code ArrayListTester.java BankAccount.java Bank.java BankAccount.java BankTester.java TicTacToe.java TicTacToeTester.java |
Study the Kjell chapters: 46 47 48 49A 49B 49C 49D
Do exercises of the above Kjell chapters on arrays before appplying Java's Array List class: 46 [1-5], 47 [1-5 ], 48 [1-3], 49B [1-3], 49C [1-9] and 49D [1-3].
Study Kjell's Tutorial in ArrayLists and Iterators.
Study Horstmann's Arrays and Array Lists: Chapter 8.
Programming Exercises To Be Graded (pp 315-319): P8.2, P8.4, P8.6, P8.8, P8.10, P8.12, P8.14, P8.16, P8.18.
For each exercise, submit a printed copy of a wordprocessing document containing:
Horstmann Chap 9
Sedgewick Chap 2.6
Litvin Chap 9
Deitel Chap 8
Study Horstmann's Designing Classes: Chapter 9.
Study Horstmann's Javadoc Summary in BIG JAVA, Appendix K, pages 1149-1151. Implement JavaDoc tags in documenting source code.
Refer to the UBC instructions, Using Custom tags with Javadoc and Eclipse. Customize Eclipse to use the @invariant, @pre, and @post JavaDoc tags.
|
This chapter does not have a model program. |
Programming Exercises To Be Graded (pp 366-368): P9.2, P9.4, P9.6, P9.8, P9.10, P9.12, P9.14, P9.16.
For each exercise, submit a printed copy of a wordprocessing document containing:
|
Follow and implement the lessons and activities of Mark Dexter's seven 15-minute tutorials of Using the Debugger [csg] [web] Refer to this Tutorial Companion Guide [pdf]. Import this DebuggerTutorial project into your Eclipse workspace. |
Horstmann Chap 10
Sedgewick Chap 3.0
Follow and implement the lessons and activities of Mark Dexter's seven 15-minute tutorials of Using the Debugger [csg] [web]. See the lower pink box in the far left column.
Study Horstmann's Designing Classes: Chapter 10.
Note: You need not understand the math of the following exercises in order to do them!
Programming Exercises To Be Graded (pp 439-441): P10.2, P10.4, P10.6, P10.8, P10.10, P10.12.
Do the tutorials found in Learn JUnit Regression Testing.
For each tutorial, submit a printed copy of a wordprocessing document containing:
Horstmann Chap 11
Sedgewick Chap 3.0
Read Gerry Donaldson's explanation of an interface in response to another teacher's question.
Read Joe Bergin's explanation of an interface in response to another teacher's question.
Study the Kjell chapters:
Programming Exercises To Be Graded: Kjell's Chapter 53B - Exercises 1 and 2
Study Horstmann's Interfaces & Polymorphism: Chapter 11.
Programming Exercises To Be Graded (pp 439-441): P11.2, P11.4, P11.6, P11.8, P11.10, P11.12, P11.14, 11.16, 11.18.
For each exercise, submit a printed copy of a wordprocessing document containing:
Horstmann Chap 13
Sedgewick Chap 3.0
|
Chapter 13 Demo Source Code AccountTester.java BankAccount.java CheckingAccount.java SavingsAccount.java |
Study Horstmann's Inheritance: Chapter 13.
Programming Exercises To Be Graded (pp 512-513): P13.2, P13.4, P13.6, P13.8.
For each exercise, submit a printed copy of a wordprocessing document containing:
Read Gerry Donaldson's explanation of an interface in response to another teacher's question.
Read Joe Bergin's explanation of an interface in response to another teacher's question.
"In order to understand recursion you must understand recursion."
- Dan R. Ghica, Java Workshop: Recursion
|
Three Rules For Recursion:
Source: How TO teach and NOT TO teach Recursion (opinions from the experts?), page 14 [pdf] by Fran Trees |
Teaching Strategies |
Real Recursion - Fibonacci Numbers and Nature
Kjell's Java Tutorials
70,
71,
72,
73,
74
Sedgewick Chap 2.7
Chapter 16, "Squashing Bugs", in Eclipse For Dummies by Barry Burd [ISBN: 0-7645-7470-1], pp 315-321
MIT Eclipse Debug Tutorial [pdf]
Leszek's Eclipse Debug Tutorial
Learn about recursion by studying the Recursion Tutorial [csg] [web] retrieved from the web site of North Carolina teacher Ruth Hartsook.
Study Mark Dexter's 15-minute screencast tutorial Study Recursion, Stack Frames → Anatomy of a Recursive Method. Implement the tutorial's code after importing this Eclipse project. Go here for instructions on importing an Eclipse project.
Read and do the recursive examples in Fran Trees' presentation, How TO teach and NOT TO teach Recursion (opinions from the experts?) [pdf].
How does the song There's a Hole in the Bucket exemplify infinite recursion?
Read and study the Kjell Java Tutorials covering "Recursion": 70, 71, 72, 73, and 74.
Study Horstmann's Recursion: Chapter 18.
Recursion = Russian Nesting Dolls:
Russian nesting dolls (aka "matryoshka") may be seen as a metaphor for recursion. Can you see why?
In what way does each smaller doll represent a smaller version of the same "problem" of the larger
doll in which it was/is encased?
Recursion = Shockwave app of a red square tilting recursively
A neat animation of recursion (no source code) here.
The animated M.C. Escher's Ascending Descending Staircase may also be viewed as a representation of recursion. It was retrieved from the site, M.C. Escher work (c) Cordon Art B.V. - Baarn - the Netherlands. Incidentally, the initials M.C. in Escher's name stand for "Maurtis Cornelis". Click here to see what Escher's actual Ascending Descending Staircase looked like. Now check out the beauty of the java code implementing recursion at The Animation of Recursion" |
Towers of Hanoi is the most famous recursion exercise in Computer Science. Virtually every book that covers recursion uses the Towers of Hanoi as either a demonstration or an exercise.
Assignment for Programming Exercises To Be Graded
First: Read and do the recursive examples in Fran Trees' presentation, How TO teach and NOT TO teach Recursion (opinions from the experts?) [pdf].
Read and study the Kjell Java Tutorials on recursion: 70, 71, 72, 73, and 74
Do the eleven Kjell exercises that correspond to the Kjell Java Tutorials on recursion: 70 (no exercises), 71 (1 exercise), 72 (2 exercises), 73 (5 exercises), and 74 (3 exercises).
Do two Horstmann exercises in BIG JAVA, chapter 18 (pp 695-700): P18.2 and P18.4.
Implement in Eclipse's JDT recursive source code that solves the Towers of Hanoi puzzle. You may obtain the source code from any source.
For each exercise, submit a printed copy of a wordprocessing document containing:
Roedy Green's
Canadian Mind Products
Duane Jarc's Interactive Visualizations
AVI clips of Students Sorting Cups
Eck: Arrays, Searching, Sorting
Videotape: Sorting Out Sorting
[Baeker, 1981, ISBN: 1558600302]
|
BIG JAVA Chapter 19 Demo Source Code Measuring Selection Sort in Milliseconds: ArrayUtil.java SelectionSorter.java SelectionSortTester.java SelectionSortTimer.java StopWatch.java Measuring Selection Sort in Nanoseconds: ArrayUtil.java SelectionSorter.java SelectionSortTester.java SelectionSortTimer.java StopWatch.java Insertion Sort: ArrayUtil.java InsertionSorter.java InsertionSortTester.java Measuring Merge Sort in Milliseconds: ArrayUtil.java MergeSorter.java MergeSortTester.java MergeSortTimer.java StopWatch.java Measuring Merge Sort in Nanoseconds: ArrayUtil.java MergeSorter.java MergeSortTester.java MergeSortTimer.java StopWatch.java Quick Sort (Uses Recursion): ArrayUtil.java QuickSorter.java QuickSortTester.java Linear Search: ArrayUtil.java LinearSearcher.java LinearSearchTester.java Binary Search: ArrayUtil.java BinarySearcher.java BinarySearchTester.java Read about Measuring Time In Java by Roedy Green. |
View Horstmann 19 Sorting and Searching Powerpoint Slide Show.
Get an intuitive feeling for sorting generally and then the Insertion Sort and Quick Sort at Sorting Bricks and Sticks on the Berkley MathSite.
View Measuring the Difficulty/Complexity of a Problem web page by Gerry Donaldson
View Tradeoffs, Intuition Analysis, Understanding Big-Oh aka O-Notation Powerpoint Slide Show by Owen Astrachan. Also view the Java source code examples associated with this PowerPoint slide show.
From the 2003 text Data Structures and Abstractions With Java by Frank M. Carrano and Walter Savitch [ISBN 0-13-017489-0], view the following Powerpoint slide shows.
Read the brief Sedgewick 4 Fundamental Abstract Data Types
Read the text and review all examples from Sedgewick 4.1 Analysis of Algorithms
Read the text and review all examples from Sedgewick 4.2 Sorting
A super reference (really an entire university course) is Data Structures and Algorithms by John Morris at the University of Western Australia! The course includes great coloured diagrams and algorithmic animations of sorting and searching algorithms.
| Read Eck's Explanation of Arrays |
| Read Chapter 8: Arrays from the 4th edition of David Eck's book Introduction to Programming Using Java. |
You want to know how to trace and implement the searching and sorting algorithms.
Read about the four sorting algorithm's required by IB's 2000 syllabus by viewing Raksha Vasudevan's Kyell-style tutorial, The 4 Array Sorts Required by IB.
Ask Mr. Donaldson to let you view the 30 minute videotape entitled, "Sorting Out Sorting".
[Baeker, Ronald M., published by Morgan Kaufman, 1981, ISBN: 1558600302]
Check out xSortLab Lab: Sorting and the Analysis of Algorithms from David Eck's book, The Most Complex Machine: A Survey of Computers and Computing.
Learn to demonstrate each of the six sorting algorithms with the stacking cups. Its fun and, incidentally, an excellent way to visualize and internalize each of the sorting algorithms, and that is our objective! First study the visualization of an algorithm. Then, once you have the hang of it, implement it using a dozen stacking cups.
In the last term of 2002 the first eight students to take Computer Science 201 in Java were examined in their application of sorting algorithms using stacking measuring cups. Judge for yourself as you watch AVI clips of their final tests .. a physical demonstration of each of four different sorting algorithms using a dozen toddler stacking cups.
Students must generate and/or complete trace tables of searching and sorting algorithms.
Hint To Automatically Generate A Trace Table:
Place an output statement with the heading before the first call to the loop or recursive method that generates the next "pass" of the sorting algorithm.
Place an output statement in the body of the loop or recursive method which generates the next "pass" of the sorting algorithm so it will output the values of each of the variables.
Check out an example of how to do this taken from an answer key by Gerry Donaldson to Question 16 of Paper 1 of the May, 2002 IB Higher Level final examinations: [WordPerfect file] [pdf file] [WORD file]
Programming Exercises To Be Graded (pp 738-739): P19.2, P19.4, P19.8, P19.10, P19.12, P19.14.
For each exercise, submit a printed copy of a wordprocessing document containing:
There will be three tests for this chapter.
There will be the usual brief 20 question quiz.
The quick sort must be reproduced without reference to resources other than the student's mind. Hint: Understand it thoroughly and you will be able to think your way through it.
Students will physically demonstrate all of the following searching and sorting algorithms using 12 stacking cups.
|