Section 1: Java Basics
- Unit 1: Introduction and Variables (Week 1). Sept 6-13. Graded assignment - Test 1 p. 16
- Introduction; Computer Hardware, Software, Systems, Ethical and Responsible Use; Integers; Doubles; and Casting.
- Exercises 1 - 6. Quick Reference 1.
Week 1: Sept 6 - Sept 13
- Integers
- Exercise 1, p. 7, largest integer
- Exercise 2, p. 9, assignment statements, what value is assigned to variable a
- Exercise 3, p. 10, number systems, decimal -> binary, binary -> decimal, binary -> octal (groups of 3), binaary -> hexadecimal (groups of 4)
- Doubles
- Exercise 4, p. 11, internal representation of floating point values
- Exercise 5, p. 12, scientific notation
- Casting
- Exercise 6, p. 13, casting floating point to int, (int)x
- p. 14, error: int = double;
- Quick Refeernce 1, p. 15
- Test 1, p. 16
- Sept 13: Finish Unit 1, Introduction and Variables
- Unit 2: Expressions (Weeks 2 - 4) Tests 2-5, Activities 1-5. Sept 13 - Oct 4.
Graded assignments: Activities 1 Rounding (p. 30), 2 Circle and spheres (p. 33), 3 Strings (p. 43), 4 Booleans (p. 57), and 5 Arrays (p. 68).
Tests 2 (p. 32), 3 (p. 45), 4 (p. 59), and 5 (p. 70)
- Arithmetic Expressions; Declaring and Assigning Values to Variables; Programming Shortcuts; Strings; Concatenation; String Methods; System.out Methods; Converting Between Numbers and Strings; Booleans; Relational Operators; Comparing Strings; Logical Operators; and Arrays.
- Exercises 7-50
- Activities 1 - 5.
- Quick References 2 - 5.
- Tests 2 - 5.
Week 2: Sept 13 - Sept 20
- Arithmetic Expressions
- Exer 7, p. 17 : using the operators +, -, *, /, % (remainder, mod)
- Exer 8, p. 19 : precedence of operators
- Exer 9, p. 20 : precedence of operators and parenthesis
- Exer 10, p. 21 : / and %, (div and mod), with doubles,
Infinity and NaN (0.0/0.0)
- Exer 11, 12 p. 22 : (int) casting with doubles in expressions
- Exer 13, 14, 15, p. 23: arithmetic mean, floor, and rounding
- Pitfalls and surprises, p. 24-25
- Declaring and assigning values to variables, p. 26
- Programming shortcuts
- Exer 16, p. 27 : assigning values to variables
- Exer 17, p. 28 : +=, -=, *=, /=
- Exer 18, p. 29 : ++, --
- Activities 1.1, 1.2, 1.3, p. 30 - rounding, (int)(x + 0.5) and forms such as (int)(10 * x + 0.5) / 10.0; rounds to tenths place
- Quick reference, p. 31
- Test 2, p. 32
- Activity 2.1, 2.2, 2.3, 2.4 Circles and Spheres, p. 33
- diameter, cirumference, area of circle, volume of sphere
- Strings
- Exer 19, p. 34 : length of strings, index of characters in strings
- Exer 20, p. 35 : special characters, \", \n, \\
- Concatenation
- Exer 21, p. 36 : concatenation of ints and strings, using += with strings
- Exer 22, p. 37 : concatenating with more than one +, mixing int expressions and strings
- String Methods
- Exer 23, p. 38 : a.length()
- Exer 24, 25, p. 39 : a.substring(m,n), a.substring(m)
- Exer 26, p. 27 : a.indexOf(), mixing combinations of .substring().indexOf().length()
- Displaying messages
- Exer 28, p. 41 : System.out.print, System.out.println()
- Converting between numbers and strings
- Exer 29, p. 42 : using the methods Integer.toString(), Double.toString(), Integer.parseInt(), Double.parseDouble()
- Activity 3 - Strings 1, p. 43
- Activity 3.1, Double.parseDouble()
- Activity 3.2, x.length()
- Activity 3.3, p.substring(p.indexOf())
- Activity 3.4, "<" + h + ">" + ...
- Activity 3.5, y.substring( 1, y.length() ... );
- Activity 3.6, d.substring( d.length() / 2 ) + d.substring( 0, ...)
- Quick reference 3, p. 44
- Test 3, p. 45
Week 3: Sept 20 - Sept 27
- Booleans, p. 46
- Relational Operators
- Exer 30, 31, p. 47, 48, <, <=, >, >=, ==, !=
- Comparing Strings
- Exer 32, p. 49, a.equals()
- Exer 33, p. 51, a.compareTo(), value is -, 0 (equal), or +
- Logical Operators
- Exer 34, p. 52, true false expressions
- Exer 35, 36, p. 53, 54, && and
- Exer 37, 38, p. 55, or ||
- Exer 39, p. 56, truth tables
- Exer 40, p. 56, deMorgans laws
- Activity 4 Booleans, p. 57
- 4.1 : ( p1 + p2 > 120 || p1 > 85 || ...
- 4.2 : d = ( r >= 8 || ...
- 4.3 : ( ( raining || floodwarning ) && ...
- Quick Reference 4, p. 58
- Test 4, p. 59
Week 4: Sept 27 - Oct 4
- Arrays
- Exercise 41, p. 60, length of array, index of value in array
- Exercise 42, 43, p. 62, declaring and using arrays
- Exercise 44, p. 63, using arrays, length of arrays x.length
- Exercise 45, 46, p. 64, array exercises
- Exercise 47, p. 65, two dimensional array, row by col
- Exercise 48, p. 66, two dimensional array, lengths, t.length (rows) and t[0].length (cols)
- Exercise 49, 50, p. 67
- Activity 5, p. 68 arrays
- 5.1 : b[ 0 ] = a[ 0 ]; ...
- 5.2 : s[ 3 ] + " " + s[ 2 ] + ...
- 5.3 : int tmp = a[ 0 ]; a[ 0 ] = a[ a.length - 1 ];...
- 5.4 : p[ 0 ] = a[ 0 ].length(); ...
- 5.5 : a[ 0 ].compareTo( a[ 1 ] ) < 0 ...
- 5.6 : ( b[ 0 ] && !b[ 1 ] && !b[ 2 ] && !b[ 3 ] ) ||
- Quick Reference p. 69
- Test 5, p. 70
- Oct 4: Finish Unit 2, Expressions
- Unit 3: Program Control (Weeks 5-7) Tests 6,7,8,9 Activities 6, 7, 8, 9, 10. Oct 4 - Oct 25
Graded assignments: Activities 6 Airline Meals (p. 30), 7 Checksums (p. 97), 8 Luhn Algorithm (p. 98), 9 Statistics (p. 99), and 10 Ordinal numbers (p. 100).
Tests 6 conditionals and blocks (p. 79), 7 while loops (p. 85), 8 for loops (p. 93), and 9 loops (p. 102)
- Conditional Statements; Blocks; Iteration; While Loops; For Loops; and For-each Loops.
- Exercises 51 - 74.
- Quick References 6 - 9.
- Activities 6 - 10.
- Tests 6 - 9.
Week 5: Oct 4 - Oct 11
- Conditional Statements
- Exercise 51, p. 71, writing an if else statement
- Exercise 52, p. 72, tracing if else if else ..., cascading if else statements
- Exercise 53, p. 73, writing if else if else... and System.out.println
- Exercises 54, 55, p. 74, more if else and cascading if else
- Blocks
- Exercise 56, p. 75, writing blocks { .. } for if statements
- Exercise 57, p. 76, variable declarations in a block, scope of variables
- Activity 6, Airline meals, p. 77
- 6.1, String[] names = { "Chicken-based adult", ...} and mealname = names[ mealcode - 1 ];
- 6.2, if ( ( request.indexOf( "no beef" ) >= 0 || request.indexOf( "chicken" ) >= 0 ) ...
- 6.3, int extrabeef = meals[ 0 ] / 2; int extrachicken = meals[ 0 ] - extrabeef; ...
- Quick reference p. 78
- Test 6 p. 79, conditionals and blocks
- Iteration
- While Loops
- Exercise 58, p. 81, stepping through while loops
- Exercise 59, 60, p. 82, writing while loops
- Exercise 61, p. 83, prime numbers with while loop
- Exercise 62, p. 83, factorials with while loops
- Exercise 63, p. 83, Fibonacci numbers with while loops
- Quick Reference, p. 84
- Test 7, p. 85, while loops
Week 6: Oct 11 - Oct 18
- For loops
- Exercise 64, p. 86, stepping through for loops
- Exercise 65, p. 88, scope and values of variabes in for loops
- Exercise 66, p. 89, writing for loops
- Exercise 67, p. 90, find the average of values in an array
- Exercise 68, p. 90, largest number in a two dimensional array
- Exercise 69, p. 91, factorial of a number
- Quick Reference 8, p. 92
- Test 8, p. 93, for loops
- For-each loops
- Exercise 70, p. 93, replace for loop with for each loop
- Exercise 71, p. 95, replace for each loop with for loop
- Exercise 72, p. 95, part a: calculate sum of elements in an array, part b: debugging why some of the loops do not work
- Exercise 73 a-f, p. 96, choose whether to replace for loop with for each loop
- Exercise 74, p. 96, fix the syntax errors of the for each loops
- Activity 7, p. 97, Checksums
- 7.1, find a working example
- 7.2, write code for checksum using the algorithm
- 7.3, write code for checkdigit on a UPC code
- 7.4, write code for 'good' for ten digit ISBN
Week 7: Oct 18 - Oct 25
- Install Netbeans for Java SE onto your computer.
- Netbeans download Java SE
- For school Macs, use the 'self service" link
- You need this for programming Labs coming up
- For-each loops - continued from Week 6
- Activity 8, p. 98, Luhn algorithm - extra credit?
- 8.1, find and example
- 8.2, write code for 'valid' in a check for Luhn algorithm
- 8.3, write checkdigit for array of digits
- Activity 9, p. 99, Statistics
- 9.1 write code to sum data in an array
- 9.2, find the largest value, max, in an array
- 9.3, find standard deviation of the values in an array
- Activity 10, p. 100 Ordinal numbers
- 10.1, output the number in words - String inwords
- 10.2, write each number with its ordinal abbreviation - 1st, 2nd etc
- 10.3, output the value of the number given ordinal value
- Quick Reference 9, p. 101
- Test 9, p. 102, loops
- Oct 25: Finish Unit 3, Program Control
- Unit 4: Methods (Weeks 8-11) Test 10,11, Activities 11, 12, 13, Lab 1. Oct 25 - Nov 22
Graded assignments: Activities 11 Strings (p. 114), 12 Optional arguments (p. 135), 13 Recursion (p. 98)
Tests 10 static methods (p. 116), 11 Methods (p. 142)
Lab 1, programming. Chatter, string processing, p. 119
- Static Methods; Defining New Static Methods; The main Method; Java Comments; Multiple Variable Declarations; Overloaded Methods; and Recursive Methods.
- Exercises 75 - 92.
- Quick References 10 and 11.
- Activities 11 - 13.
- Lab 1
- Tests 10 and 11.
Week 8: Oct 25 - Nov 1
- Install Netbeans for Java SE onto your computer.
- Netbeans download Java SE
- For school Macs, use the 'self service" link
- You need this for programming Labs coming up
- Static Methods
- Exercise 75, p. 103, what is the black box doing, based on input/output
- Exercise 76, p. 105, evaluate sample Math static methods, Math.abs(), Math.pow()
- Defining new static methods
- p. 106: public static int doubleMe( double x )
- Exercise 77, p. 107, modify public static int doubleMe( double x )
- Exercise 78, p. 107, public static boolean findWally( String s ) find substring "Wally"
- Exercise 79, p. 109, public static void mySqrt( double d )
- Exercise 80, p. 109, public static int ordinalToInt( String s )
- Exercise 81, p. 110, public static String[] guillotine( String[] inArray )
- Exercise 82, p. 110. public static int[] cycle( int[] inArray )
- Exercise 83, p. 112. public static boolean findInArray( int[] a, int x )
- Exercise 84, p. 113. public static String toggleStem( String stem, String str )
- Exercise 85, p. 113. public static String cutItOut( String s, int a, int b )
- Activity 11 Strings 2, p. 114
- 11.1 public static boolean startsWith( String a, String b )
- 11.2 public static boolean endsWith( String a, String b )
- 11.3 public static String bothStart( String a, String b )
- 11.4 public static String[] stringHeads( int[] p, String s )
- Quick reference 10 p. 115
- Test 10, p. 116 static methods
Weeks 9, 10: Nov 1 - Nov 15
- Install Netbeans for Java SE onto your computer.
- Netbeans download Java SE
- For school Macs, use the 'self service" link
- You need this for programming Labs coming up
- Methods
- the main method, p 117
- comments, p. 118
- Lab 1 Chatter, string processing, dialoger, chatbot
- Task 1.1 p. 119
public static String getResponse( String statement )
- Task 1.2 p. 120 public static boolean containsAnyOf( String s, String[] sArr )
- Task 1.3 p. 120 rewrite public static String getResponse( String statement )
- Task 1.4 p. 121 public static String getRandomResponse()
- p. 122 Getting NetBeans (or Eclipse) set up with correct Java Platform
- p. 123 Download lab01_nb.zip (for NetBeans), run the Lab01 package
- p. 124 Run the project Lab01, check out the conversation
- p. 125 using:
- public int indexOf(String str, int fromIndex)
- public String toLowerCase()
- public String trim()
- Task 1.5, p. 126, complete public static int indexOfKeyword( String s, String keyword )
- p. 127, insert additional statements to indexOfKeyword. Verify that the chatbot no longer reacts inappropriately to embedded occurrences of keywords.
- p. 128 Lab01 Checker, export your project to a ZIP archive and Submit for verification
- p. 129 extra credit
- Task 1.6 p. 130, extra credit
- Task 1.7 p. 131 extra credit
Weeks 10, 11: Nov 8 - Nov 22
- Methods (cont.)
- p. 132 Multiple Variable Declarations
- p. 133, 134 Overloaded Methods
- Exercise 86, p. 134, complete overloaded public static String money( int n )
- Activity 12 Optional Arguments, p. 135
- 12.1 public static String writeDate( int year, int month, int day, int hours, int minutes, int seconds )
- 12.2 public static String writeDate( int year, int month, int day, int hours ) and variations
- Recursive Methods
- Exercise 87, p. 136 public static void mystery( int n )
- Exercise 88, p. 137 reverseString
- Exercise 89, p. 137 working with reverseString
- Exercise 90, p. 138 working with reverseString
- Exercise 91, p. 139, recursive factorial: public static int factorial( int n )
- Exercise 92, p. 139, non-recursive factorial with for loop: public static int factorial( int n ) // non-recursive!
- Activity 13 Recursion, p. 140
- 13.1 public static int nWheels( int cars )
- 13.2 public static int countVowels( String s )
- 13.3 public static int nTriangle( int n )
- Quick Reference 11, p. 141
- Test 11, p. 142, Methods
- Nov 22: Finish Unit 4, Methods, and finish Section 1 Java Basics
Section 2: Object-Oriented Programming
This section introduces students to object-oriented programming. The remaining hidden code that is being added automatically by the web service is revealed.
- Unit 5: Object-Oriented Programming Concepts (Weeks 12-16) Tests 12, 13, Activities 14, 15, 16. Labs 2 (Points and Rectangles) and 3 (Poker) Nov 22 (Thanksgiving break) - Dec 27 (Winter break)
Graded assignments: Activities 14 (Address objects) (p. 164), 15 Check please (p. 180), 16 On the Menu (p. 193)
Tests 12 simple objects (p. 176), 13 simple objects (p. 212)
Labs 2 Points and Rectangles (p. 165), 3 Poker (p. 194)
- An introduction to OOP in the context of Java; an overview of Classes and Instances; Simple Objects; A Person Class; A Point Class; Public Classes and the Java Compiler; The Java Compiler and the Virtual Machine; Errors, Exceptions, and Garbage Collection; Arrays and Objects; and ArrayLists.
- Exercises 93 - 115.
- Quick References 12 and 13
- Activities 14 - 16.
- Labs 2 and 3.
- Tests 12 and 13.
- Object Oriented Programming Concepts, Simple Objects
Weeks 12, 13: Nov 22 - Nov 29, Nov 29 - Dec 6
- Classes and Instances, p. 144-146
- Simple Objects
- Person class
- p. 147 public class Person
- p. 148 constructors, more than one, for Person
- Exerise 93, p. 149 signatures for Person objects: eat() and walk(int meters)
- Exercise 94, p. 151, create instance jenny
- Exercise 95, p. 152, adding an accessor method myWeight()
- Exercise 96, p. 153, complete methods eat() and walk(int meters)
- Exercise 97, p. 154 add method feast() and accessor getHeight() definitions
- A Point Class
- Exercise 98, p. 155 declare two points a, and b
- Exercise 99, p. 156 define instance method public void move( double x, double y )
- Exercise 100. p. 157 modifier method public void setY( double y )
- Exercise 101, p. 158 static method public static double ptDistance( APPoint p, APPoint q )
- Exercise 102. p. 159 instance method public double distanceTo( APPoint p )
- Exercise 103, p. 160 instance method public APPoint[] compassPoints()
- Public classes and the Java compiler, p. 161
- Java compiler and virtual machine, p. 162
- Errors, Exceptions, and Garbage Collection, p. 163
- Activity 14 Address objects, p. 164
- 14.1 public class StreetAddress with constructors, modifiers, accessors
- Lab 2 Points and Rectangles
- Task 2.1 p. 165, working with APPoint class, write public static String printAPPoint( APPoint p )
- Task 2.2 p. 165, APRectangle, constructor, accessors, modifiers
- Task 2.3 p. 166, accessor getTopRight() ...
- NetBeans: p. 167, download lab02_nb.zip and load the project
- p. 168 Run the project in NetBeans (or Eclipse)
- p. 169, copy paste import statements for Canvas class to draw the graphics
- Task 2.4, p. 170, add drawling statements
- p. 171, make the drawing with variable rectangle pattern. Submit your project after archiving to ZIP archive
- Task 2.5, p. 171-172 extra credit
- p. 174, Spiral shape pattern with rectangles, extra credit
- Quick Reference 12, p. 175
- Test 12, Simple Objects
Weeks 14, 15, 16: Dec 6 - Dec 13, Dec 13 - Dec 20, Dec 20 - Dec 27
- Arrays and Objects
- Exercise 104, p. 177, tracing the Card class, using pip values
- Exercise 105, p. 179, adding code: deck[ ( 13 * i ) + k - 2 ] = .. using pip values
- Exercise 106, p. 179 public class Book
- Activity 15, Check Please, p. 180
- 15.1, write method public double lineItemTotal()
- 15.2, public static void setQuantities( CheckItem[] items, int[] quantities)
- 15.3, public static double[] lineItemTotals( CheckItem[] items )
- ArrayLists
- p. 182 ArrayList aList;
- p. 183 ArrayList attributes of ArrayLists
- Exercise 107, p. 183, quesions about ArrayList cardss
- Exercise 108, p. 184, deleting a block of items from an ArrayList, public static void deleteBlock( ArrayList strings, int n)
- Exercise 109, p. 185, public static void removeLongStrings( ArrayList a )
- Exercise 110, p. 186, static method transplantBlock()
- Exercise 111, p. 187, public static ArrayList makeDeck()
- Exercise 112, p. 188, using Random() class and Math.random()
- Exercise 113, p. 189, using for-each loops wit an ArrayList for cards
- Exercise 114, p. 190, ArrayList and ArrayList, ints and doubles are not allowed for ArrayLists
- Exercise 115,p. 192, create an ArrayList for class Animal
- Activity 16, On The Menu, p. 193
- 16.1, public String menuString()
- 16.2, public static double[] profits( ArrayList
- Lab 3 Poker, p. 194
- Task 3.1, public class Card, with imageFileName()
- Task 3.2, p. 195, complete public class Deck
- Task 3.3, p. 196, complete public class Hand
- p. 197, NetBeans, download lab03_nb.zip, and set up project for Lab03 on NetBeans
- p. 198 graphically displaying the hand of cards
- p. 199, Lab03Runner, displayin a hand of cards,
if the card images do not display, you need to copy the image files into the same directory/folder as your project.
- Task 3.4, p. 200, public int getCardValue( int i ) in public class Hand
- p. 201, displaying 4 hands of 5 cards each. Create a ZIP archive and submit your Lab to the Lab checker
- Task 3.5, p. 205 Extra Credit
- Task 3.6, p. 206 Extra Credit, ranks the various hands
- Programming Strategies, top down, down up
- Quick Reference 13, p. 211
- Test 13, Simple Objects, p. 212
- Dec 27: Finish Unit 5, Object Oriented Programmming Concepts
- Unit 6: Inheritance and Polymorphism (Weeks 17 - 19) Tests 14, 15, Activities 17, 18, 19, Lab 4 (Inventory Tracking). Dec 27 (Winter break) - Jan 17
Graded assignments: Activities 17 Airplanes - extended objects (p. 217), 18 Components (p. 180), 19 Inheriting from Object (p. 241)
Tests 14 (p. 233), 15 Ineritance and Polymorphism (p. 258)
Labs 4 Inventory Tracking (p. 242)
- Extending Classes; Class Hierarchies; Polymorphism; and Overriding Methods.
- Exercises 116 - 137.
- Activities 17 - 19.
- Lab 4.
- Quick References 14 and 15.
- Tests 14 and 15.
Week 17 : Dec 27- Jan 3
- Inheritance and Polymorphism
- Extending Classes
- Exercise 116, p. 213, HospitalWorker and Military classes
- Exercise 117, p. 214, Employee class that will be extended
- Exercise 118, p. 215, extend Employee - public class SalesAssistant extends Employee
- Exercise 119, p. 216, public class Teacher extends Employee
- Exercise 120, p. 216, public class Military extends Employee
- Activity 17 Airplanes
- 17.1, public class PassengerJet extends Airplane
- 17.2, public class MilitaryJet extends Airplane
- 17.3, public class BusinessPlane extends Airplane
- Class hierarchies, p. 218, learn the terms: extends, superclass, direct subclass, derived from. Also is-a and has-a
- Exercise 121, p. 219, modify public class SalesSupervisor extends SalesAssistant
- Exercise 122, p. 219, complete public class SalesPartTime
- p. 220, Hierarhy diagram for Employee class
- Exercise 123, p. 221, fix the error in public class SalesAssistant extends Employee
- p. 222, the Object class is super to Employee and all classes
- p. 223, complete code for SalesAssistant, SalesSupervisor, and Employee, outputs the class names of the objects stored in the variables a, b and c:
- Exercise 125, p. 224, complete public static String getClassName( Object obj ), use toString() and substring()
- Activity 18 Components, p. 225
- 18.1, public class Component and public class ElectricalComponent extends Component
- 18.2, public class HighvoltageComponent
- 18.3, public class MysteryComponent
- 18.4, which hierarchy diagram fits
- Polymorphism
- Exercise 126, p. 227, answer poymorphism questions about Employee, SalesAssistant, Teacher, ...
- Exercise 127, p. 228, static void printEmployeeDetails( Employee e ), does it work with Teacher, SalesAssistant
- Exercise 128. p. 229, using expression such as: ((SalesAssistant)f).getSecureCode()
- Exercise 129, p. 230, using a database of Employee objects
- Exercise 130, p. 231, output the rank followed by the name of each Military object in the database.
- Quick Reference 14, p. 232
- Test 14, p. 233
Weeks 18, 19 : Jan 3 - Jan 10, Jan 10 - Jan 17
- Overiding Methods
- Exercise 131, p. 234, overide public String toString() in public class School
- Exercise 132, p. 235, verify that if the School class has no customized toString method, then the toString method of the Object class is used.
- Exercise 133, p. 236, Modify the definition of Employee by adding a toString method
- Exercise 134, p. 237, polymorphism, Customer c1 = new Customer( "Fred" ); Customer c2 = new TradePerson( "Joe" ); and total: System.out.println( "Fred pays $" + c1.price( total ) );
- Exercise 135, p. 237, public class Distributor extends TradePerson
- Exercise 136, p. 238, public class Dealer extends TradePerson
- p. 239, public class Complex
- Exercise 137, p. 240, public class Car,
public boolean equals( Object obj )
- Activity 19, Inheriting from Object, p. 241
- 19.1, public class Component, public class ElectricalComponent extends Component, Override the toString method of Object for Component
- 19.2, Override the toString method of Object for ElectricalComponent
- 19.3, Override the toString method of Component for MysteryComponent so that it outputs the description
- Lab 4 Inventory Tracking, p. 242
- Task 4.1, p. 243, complete a definition of the Footwear class, public class Footwear
- Task 4.2, p. 244, Add definitions of the printSize and toString methods to the Footwear class
- Task 4.3, p. 245, Adjust the definition of the toString method in the Footwear class and define the Boot, Shoe, DressShoe, and CasualShoe
- p. 246 Download lab04_nb.zip and set up project in NetBeans
- p. 247, run Lab04Runner
- Task 4.4, p. 249, Define the BinItem class in such a way that its constructor takes two inputs, a String sku and an int quantity
- Task 4.5, p. 250, Define the Bin class in accordance with the given description.
- p. 251, insert import java.util.ArrayList; to use ArrayList
- Task 4.6, Modify the definition of the Bin class by adding the remove and totalQuantity methods described
- Task 4.7, p. 253, define the Warehouse class
- define a receive method that performs the first of these tasks
- To test your receive definition, replace all the uncommented statements in the main method of your Lab04Runner class.
- Create a ZIP archive and submit Lab 0 4
- Task 4.8 extra credit
- Quick Reference 15, p. 258
- Test 15 Inheritance and Polymorphism
- Jan 17: Finish Unit 6, Inheritance and Polymorphism
- Unit 7: Class Definitions Revisited (Week 20) Test 16,
Activities 20, 21, 22, 23. Jan 17 - Jan 24
Graded assignments: Activities 20 Volume calculator class (p. 267), 21 Flower arrangements (p. 273), 22 Integer and Double (p. 275), 23 This and That, (p. 283)
Test 16 Class definitions revisited (p. 285)
- Class Methods; Class Variables and Constants; final Block Variables; Multiple Constructors; Overloaded Instance Methods; Wrapper Classes; Access Modifiers; this; and Object Aliasing.
- Exercises 138 - 151.
- Activities 20 - 23.
- Quick Reference 16.
- Test 16.
Week 20 : Jan 17 - Jan 24
- Class Methods
- Static methods are also called class methods
- Exercise 138, p. 260, write public static double circum( double r )
- Exercie 139, p. 261, add to the Color class a class method, isRainbow: public static boolean isRainbow( String colorName ), and System.out.println( Color.isRainbow( b.getColorName() ) );
- How can a class method call an instance method in the same class
- Exercise 140, p. 262, public static IntClass abs( IntClass i ) and IntClass i1 = new IntClass( 5 ); ...
-
- Class variables and constants
- Using static with a variable: private static String today = "Monday";
- Both instances, t1 and t2, are accessing the same class variable, testN.
- Exercise 141, p. 263, class variables as counters. private static int n = 0;
- Modifier keyword final. An unchangeable class variable is referred to as a class constant.
- Exercise 142, trying to modify a static final class vairiable, error caused
- public class variables
- Exercise 143, p. 265, The Java Math class contains two public constants, PI and E., System.out.println( "Math.PI = " + Math.PI );
- Final block variables: final int FAMILY_SIZE = myMembers.size();
- Activity 20, p. 267, Volume Calculator class
- 20.1, Complete the definition for the Volume class, calculate volumes of cube, sphere,...
- 20.2, Write a definition for a static method houseVolume
- 20.3, Write a definition for a static method speakerVolume
- Multiple Constructors
- Exercise 144, p. 268, using APRectangle constructors
- Exercise 145, p. 269, Complete and test the definition of the Contact class, "Friend", "Colleague" or "Relative"
- public and private
- looking at private instance variables,
- private constructors
- Overloaded instance methods
- Exercise 145, p. 272, output of System.out.println( t.pick( 5 ) + t.pick() + t.pick( 3, 9 ) );
- Activity 21, Flower Arrangements, p. 273
- 21.1, Complete the definition for the BunchOfFlowers class.
- 21.2, Complete the definition for the FlowerWarehouse class
- Integer and Double
- Exercise 147, p. 274, using ArrayList with Double, Integer : ArrayList d = new ArrayList();
- Activiy 22, Integer and Double, p. 275
- 22.1, static method makeNumber()
- 22.2, public static method interval inputs two ints m and n: interval( 3, 12 ) returns [3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
- 22.3, public static method primes : output an ArrayList of Integers representing the prime numbers from 2 through its argument, the int t (greater than 2), using an algorithm called the Sieve of Eratosthenes
- Using 'this'
- Exercise 148, p. 277, APPoint, add distance() and circleCircumference(), public double distance( APPoint p ) ...
- Exercise 149, p. 278, public void includeMeIn( ArrayList a )
- Object aliasing
- mutability and aliasing
- Exercise 150, p. 282, use the written abs method to calculate the absolute value of an integer
- Exercise 151, p. 282, modified the IntClass again, removing the abs method and adding toString and addToList methods. Predict the output
- Activity 23, p. 283, This and That
- 23.1, Complete the definition of the Currency class by supplying the missing code in the toString method
- 23.2, Fix the clone method, and check that the numberOfChanges method now returns the number of Currency objects that are changed by the absoluteCurrency method.
- Quick Reference 16, p. 284
- Test 16, Class definitions revisited
- Jan 24: Finish Unit 7, Class Definitions Revisited
- Unit 8: Abstractions (Weeks 21 - 23) Test 17, Lab 5 (Turtle Geometry),
Activities 24, 25, 26. Jan 24 - Feb 14
Graded assignments: Activities 24 More on transactions from a bank (p. 289), 25 Startable objects (p. 297), 26 Weather report (p. 306), 23 This and That, (p. 283)
Test 17 (p. 331)
Lab 5 Turtle Geoometry, (p. 308)
- Abstract Classes; Interfaces; and, in particular, the List and Comparable Interfaces.
- Exercises 152 - 166.
- Activities 24 - 26.
- Lab 5.
- Quick Reference 17.
- Test 17.
Week 21 : Jan 24 - Jan 31
- Abstract classes
- public abstract class Shape, abstract class, that is designed never to be instantiated. Any subclass of an abstract class that is not itself marked as abstract may be instantiated.
- Exercise 152, p. 286, public class Line extends Shape
- abstract methods - The only classes that may contain an abstract method are abstract classes; if a class contains an abstract method, it must itself be abstract.
- Exercise 153, p. 288 write a program that simulates (in greatly simplified form) the activities of a bank.
- Activity 24, p. 289, More on Transactions - from a bank
- 24.1, Write a concrete class Adjustment that extends the abstract class Transaction
- 24.2, Write a concrete class ZeroBalance that extends the abstract class Transaction, and whose adjustAccount method causes the Account's balance to be set to zero.
- 24.3, Complete the definition for TransactionHistory class by providing the body of the toString method
- Interfaces
- Interface: The role of an interface is to describe to Java the methods that one or more classes will implement without specifying how the implementations will actually be carried out, and without requiring any relationship to a class hierarchy.
- public interface Incrementable
- every method that is declared in an interface definition is considered to be implicitly both public and abstract.
- public abstract void increment(); .. use: void increment();
- Use the keyword 'implements': public class StringIndex extends MyTestClass implements Incrementable
- Exercise 155, p. 291, public class IntClass implements Incrementable
- Exercise 156, p. 292, classes BrassAlloy and SilverAlloy (defined below) implements the Stampable interface, write public interface Stampable
- How interfaces and abstract classes differ
- Exercise 157, p. 293, which would compile?
- Exercise 158, p. 294, Interface and abstract example, questions about the example, public interface Identifiable , public interface Punishable , public abstract class Person, public class ExCon extends Person implements Identifiable ...
- List interface
- Activity 25, p. 297, Startable Objects
- public interface Startable
- The Car class implements the Startable interface.
- 25.1, complete Car class, public class Car implements Startable
- 25.2, complete Truck class, public class Truck extends Car
- 25.3, complete public class Counter implements Startable
- 25.4, public static method runForAWhile inputs a Startable object and an int n, complete runForAWhile. public static void runForAWhile( Startable s, int n )
- Abstractions
- Comparable interface
- Exercise 159, p. 298, DateTime class
- Exercise 160, Item class that implements the Comparable
- interface.
- Exercise 161, p. 299, define the compareTo methods
- Exercise 162, p. 300, output for expressions such as: (new String( "a" )).compareTo( new String( "a" ) );
- Exercise 163, p. 301, output for expressions such as:
(new Integer( 5 )).compareTo( new Integer( 1 ) );
- Exercise 164, p. 302, TestClass, compareTo. return myName.compareTo( t.getName() );
- In the Advanced Placement examination, you will not be tested on the Comparable interface. Instead, examination questions will use a simplification of this interface called "the raw Comparable interface": public interface Comparable
- Exercise 165, p. 303, public class TestClass implements Comparable
- For the Advanced Placement examination, you need to be able to answer questions that involve the raw Comparable interface.
- The raw Comparable interface is now what is known as a deprecated feature of Java.
- Java provides the Comparable interface so as to make it possible for Java programmers to sort objects into order.
- Exercise 166, p. 305 define an equals method that overrides the equals method of Object in such a way that the compareTo method is consistent with equals.
- Activity 26, p. 306, Weather Report
- 26.1 Complete the program by writing the compareTo method for the WeatherReport class
- 26.2 Redefine the compareTo method so that the reports appear in reverse order of duration:
- 26.3, Complete definition for score method of WeatherReport
- EventListener interface, in Swing constants
Week 22 : Jan 31 - Feb 7
- Lab 5 Turtle Geometry, p. 308
- Task 5.1, p. 309, Define the four subclasses of the Action class; public abstract class Action. MoveForward, MoveBack, ...
- Task 5.2, p. 310, Define the TurtleProgram class
- Download lab05_nb.zip, create Lab05 project
- p. 312, Run Lab05Runner
- TurtleController class
- p. 314, Verify you see the turtle window: theTurtleWindow = new TurtleWindow();
- p. 315, modify TurtleController's actionPerformed . Modify the actionPerformed method of the TurtleController. Test your code with Forward 15 etc
- p. 316, code for Back, Left, and Right. Code for Reset.
- p. 317. copy APPoint.java file from lab02 to lab05
- Task 5.3, define the Turtle class
- p. 318, Enter Turtle in the Class Name box on the "New Java Class" dialog, and press the Finish button. Copy and paste the body of a correct definition (including the lineTo method) of the Turtle class from Task 5.3
- p. 319, define execute methods for the MoveForward, MoveBack, TurnLeft, and TurnRight classes, insert: import com.eimacs.lab05gui.Turtle; import java.awt.Graphics; public void execute( Turtle t, Graphics g ) { ... }
- p. 320. Create a new Java class called TurtlePlane in the com.eimacs.lab05gui package in your Lab05 project
- p. 321: Give the TurtleController class a myTurtlePlane instance variable. Change the signature of the TurtleController class constructor so that it takes one argument, a TurtlePlane object. Give the TurtleWindow class a myTurtlePlane instance variable. ...
- p. 322: add to the TurtleController class the following method: public void executeProgram()
- p. 323. more adjustments: Give the TurtleProgram class a boolean isValid instance variable and a corresponding setIsValid modifier method, Make the TurtleProgram constructor and the class's addAction method both set the value of the isValid variable to false, Change the execute method of the TurtleProgram class so that it does nothing unless the value of the isValid variable to true, etc
- p. 324 export to a ZIP archive. Submit Lab05
- Task 5.4 and rest of Turtle Lab are extra credit
Week 23 : Feb 7 - Feb 14
- Finish up working on Lab05 Turtle
- Quick reference 17, p. 330
- Test 17
- Feb 14: Finish Unit 8, Abstractions, and finish Section 2 Object Oriented Programming
Section 3: Algorithms
This section introduces students to basic algorithms in the context of arrays, and includes a variety of standard searching and sorting algorithms.
- Unit 9: Introduction to Algorithms (Week 24) Activities 27-28, Lab 6 (Image Processing). Feb 14 - Feb 21
Graded assignments: Activities 27 Phone extensions (p. 342), 28 Phone Extensions 2 (p. 342)
Lab 6 Image Processing (p. 343)
- Algorithms; Traversals; Replacements; Insertions; and Deletions.
- Exercises 167 - 171.
- Activities 27 and 28.
- Lab 6.
Week 24 : Feb 14 - Feb 21
- Introduction
- p 333. Compare algorithms for the sum of an interval of numbers. Use a loop vs a statement: sum = [(n – m + 1) * (m + n)] / 2
- Exercise 167, p. 334. Compare and complete two algorithms for Fibonacci, recursive definition and iterative
- Traversals, p. 335, Exercise 168: Traverse an array of Item, count how many elements myN instance of an even number
- Replacements, p. 336, replace an myN instance of an Item with another value
- Activity 27, Phone Extensions, p. 336.
- 27.1: complete the definition for find, find a person given a name or an extension
- 27.2: Complete the definition for updateExtension - public static void updateExtension( String name, String extension )
- Insertions, p. 338, insert an element into an array
- Exercise 169, p. 339 In the code fragment, complete the for-loop so that the insertion works correctly with a variety of array sizes
- Exercise 170, p. 340, Write a new class method, insert, for the Item class that takes three arguments an Item[] array, an Item newItem, and an int k and inserts newItem into array at index k, discarding the last item of the array (that is, the item originally at index array.length - 1): public static void insert( Item[] array, Item newItem, int k )
- Deletions - delete an element from an array
- Exercise 341, p. 171, public static void delete( Item[] array, int k )
- Activity 28, Phone Extensions 2, p. 342
- 28.1: The newExtension method is designed to input a name, a 3-digit extension number, and an index. Complete newExtension
- 28.2: The removeExtension method is designed to input a name or 3-digit extension number (presented in the form of a String), and remove from the extensions array the first entry it finds that matches either the name or the extension (or both). If such a removal takes place, the size of the extensions array is reduced by 1. public static void removeExtension( String t )
- Lab 6 Image Processing, p. 343
- p. 343, Download lab06_nb.zip and create Project Lab06 in NetBeans
- p. 344, Review roles of these methods: DigitalPicture.java, SimplePicture.java, Picture.java, and Pixel.java.
- p. 344, Review roles of these methods: PictureExplorer.java, PictureFrame.java, and ImageDisplay.java.
- p. 345. Run project Lab06. If no picture appears, you need to change the path in the code, or put all the images in the folder with the main project
- You should see a beach image and be able to find the RGB values for particular mouse locations
- Task 6.1, p. 346. At the end of the definition of the Picture class add the definition of a negate method. This has a similar structure to the zeroBlue method, but for each pixel it sets each color component to 255 minus its current value.
- The Pixel class provides a getAverage method that returns a double equal to the average of a pixel's red, green, and blue component values. With the help of this method, add the definition of a grayscale method to the Picture class definition. This method sets each color component of each pixel to the average of the color component values.
- Add the definition of a fixUnderwater method to the Picture class that boosts the red component of each pixel by some factor
- p. 347: public void mirrorLeftOntoRight using: The Pixel class also has getColor and setColor methods.
- Task 6.2, p. 348, add a mirrorTopOntoBottom method to the Picture class. Add a flipLeftAndRight method to the Picture class
- Lab Checker 6.1, p. 348, check Tasks 6.1 and 6.2
- Task 6.3, p. 349, add a repairTemple method to the Picture class. The body of this method can be modeled on that of the mirrorLeftOntoRight method,
- Task 6.4, p. 350, Add a cloneSeagull method to your Picture class that copies all the pixels in the rectangular region you have identified to locations that are offset to the right and down in such a way that there is no discernible break in the water's edge and the copied region reaches exactly to the right edge of the overall image. Insert a call to the cloneSeagull method in your main method and run the project repeatedly as you adjust the values of the two offsets until the copy lands in exactly the right place.
- Lab Checker 6.2, p. 351
- Task 6.5: Edge detection. Add an edgeDetect method to your Picture class. This method takes one input, an int minColorDistance whose value specifies the threshold above which the method will detect the presence of an edge
- Lab Checker 6.3
- Extra credit: Steganography, Task 6.6 hiding a message
- Extra credit: Chroma key compositing, Task 6.7
- Feb 21: Finish Unit 9, Introduction to Algorithms
- Unit 10: Searching and Sorting, and Program Analysis (Weeks 25 - 29) Tests 18, 19, Activities 29, 30, Labs 7 (Searching and Sorting), 8 (Elevens card game). Feb 21 - March 28
- Sequential search; Binary search; Selection sort; Insertion sort; Merge sort; Assertions and Exceptions.
- Exercises 172 - 204.
- Activities 29 and 30.
- Labs 7 and 8.
- Quick References 18 and 19.
- Tests 18 and 19.
Week 25 : Feb 21 - Feb 28
- Sequential search
- Exercise 172, p. 357, complete public static Item sequentialSearch( Item[] array, int intTarget ). unsorted
- Exercise 173, p. 358, sorted values. Implement a new class method, findItem, that takes two arguments, Item[] array and int target, where it is known that the Items in the input array are sorted into ascending order according to the values of their myN instance variables.
- Binary Search
- p. 360. Exercises 174, 175 Stepping through binary search
- p. 360 Exercise 176: Implement and test a static method binarySearch that takes as its arguments int[] array (presumed to be an ordered array of ints) and int target
- p. 361, Exercise 177: complete the compareTo and equals methods of the Item class, complete and test the definition of the class method binarySearch.
- p. 362, Exercise 178: comparing number of iterations for sequential and binary search
- p. 362, Exercise 179: counting number of iterations for sequential and binary searches on different size arrays
- p. 363 Exercise 180: a different algorithm for binarySearch: public static int binarySearch( int[] array, int target )
- p.e 363 Exersise 181: a recursive binarySearch
- Quick Reference 18, p. 364
- Test 18, Searching
Week 26 : Feb 28 - March 7
- Selection Sort
- Exercise 182, p. 367, tracing the selection sort
- Exercise 183, p. 368, fix the inner loop's terminating condition, also adapt to arrays of any length
- Exercise 184, p. 369, fix the loops so i=0 is not iterated over
- p. 370, Exercise 185, rewrite to sort in descending order
- Exercise 186, rewrite code to selection sort an array of String
- Exercise 187, p. 371, use the stepper to trace through and count number of comparisons made
- Exercise 188, p. 372, write the code for selectionsort: public static void selectionSort( Item[] array )
- Exercise 189, p. 372, write the code for selectionsort in descending order: public static void selectionSort( Item[] array )
- Insertion Sort
- Exercise 190, p. 373, trace through insertion sort with given arrays
- Exercise 191, p. 374, rewrite code for insertion sort in descending order
- Exercise 192, p. 375, use the tracer to count how many times a comparison is made
- Exercise 193, p. 376, calculate time if array is initially sorted
- Exercise 194, p. 377, rewrite insertion sort with only one argument: public static Item[] insertionSort( Item[] source )
- Exercise 195, p. 377 write insertion sort with ArrayLists: public static <T extends Comparable <T>> ArrayList<T> sortArrayList( ArrayList<T> source ) - use the Comparable interface
- Exercise 196, p. 378, write Insertion 'in place
so that a temp extra array is not used. insertion is done on the same original array
- Activity 29 A Selection of Sorts, p. 379
- 29.1, Complete the definition of numDivisors: public static int numDivisors( int x )
- 29.2, Complete the definition of SelectFrom: public static int[] selectFrom( int[] inArray, int startIndex, int endIndex )
- 29.3, Debug the code for ssort: public static int[] ssort( int[] array )
- 29.4, Debug the code for isort: public static int[] isort( int[] source )
- Merge Sort - recursive
- Exercise 197, p. 380, complete the definition of merge: public static void merge( int[] a, int[] b, int[] result )
- Exercise 198, p. 381, complete the code for mergeSortVariation, p. 382, code for selectionSort and merge
- Exercise 199, p. 382, change merge code to sort in descending order
- Exercise 200, p. 384, complete the implementation of merge sort
- p. 385, merge sort is nlogn sort, see table with average times for selection, insertion, merge sorts
Week 27 : March 7 - March 14
- Lab 7 A Comparison of Sorts, p. 386
- Task 7.1, p. 386, Define APTimer class: public class APTimer
- Task 7.2, p. 387, Define the methods randomArrayList and arrayListOfArrayLists.
public static ArrayList<Integer> randomArrayList( int n)
public static ArrayList<ArrayList<Integer>> arrayListOfArrayLists( int m, int n )
- Task 7.3, p. 388, Complete the following definition of the SelectionSort class so that its sortList method is simply an ArrayList version of the selectionSort method given in Exercise 185.
public abstract class Sort { public abstract <T extends Comparable<T>> void sortList( ArrayList<T> arr ); }
public class SelectionSort extends Sort
{ public <T extends Comparable<T>> void sortList( ArrayList<T> arr ) ...
- Task 7.4, p. 389, Complete the following definition of the InsertionSort class so that its sortList method is simply an ArrayList version of the definition given in the model answer to Exercise 196(b).
public class InsertionSort extends Sort {
public <T extends Comparable<T>> void sortList( ArrayList<T> arr ) ...
- Task 7.5, p. 390, Complete the following definition of the MergeSort class, basing your work on an ArrayList version of the model answer to Exercise 200.
public class MergeSort extends Sort {
public <T extends Comparable<T>> void sortList( ArrayList<T> arr ) {
mergeSort( arr, 0, arr.size() - 1 );}
public <T extends Comparable<T>> void mergeSort( ArrayList<T> a, int low, int high ) { ...
public <T extends Comparable<T>> void merge( ArrayList<T> a, int low, int mid, int high ) ...
- p. 391, download lab07_nb.zip for NetBeans and create Project Lab07
- p. 392
- open the com.eimacs.lab07 package node to reveal the nodes for the provided Java files that are concerned with timing and sorting.
- Open each of the files APTimer.java, SelectionSort.java, InsertionSort.java, and MergeSort.java in turn, and copy and paste the body of the corresponding definition from Tasks 7.1, 7.3, 7.4, and 7.5
- Open the file Lab07Runner.java and copy and paste the definitions of the random, randomArrayList, and arrayListOfArrayLists methods from Task 7.2 into the Lab07Runner class definition before the main method.
- Run the project
- p. 393, In preparation for filling out tables, replace the uncommented code in the main method of the Lab07Runner class by the following given code
- p. 393, Task 7.6, By repeatedly running your project after changing the value assigned to ARRSIZE in the main method of the Lab07Runner class and commenting or uncommenting the declarations of the Sort s, fill out the following table of average execution times for the three sorting algorithms when applied to ArrayLists of size 10, 100, 200, 500, 1000, and 10000.
- p. 394, Task 7.7: Timing insertionSort on ordered lists to see the effect on the total time
- p. 394: Add this to the top of Lab07Runner: import java.util.Collections;
Then replace the definition of the randomArrayList method by the new 2-input version from the above task 7.7
After making suitable adjustments to your main method and saving your work, verify that you can now create ArrayLists of ArrayLists of random Integers, in random order, in increasing order, and in decreasing order.
- p. 395: Replace the uncommented statements in the main method of your Lab07Runner class by the following given code.
- p. 395, Task 7.8: By repeatedly running your project after changing the values assigned to ARRSIZE and/or DIR in the main method of the Lab07Runner class, fill out the following table of average execution times for the insertion sort algorithm when applied to ArrayLists of size 10, 100, 200, 500, 1000, and 10000 that are initially in increasing, random, or decreasing order
- p. 396 Lab Checker 7.. End of the required portion
- The rest of this Lab 7 is extra credit, including Task 7.9
- Quick Reference 19, p. 406
- Test 19, p. 407, Searching and Sorting
- March 14: Finish Searching and Sorting
- Week 28 : March 14 - March 21
- p. 407:
- Java is an object-oriented programming language. Object-orientation encourages programmers to encapsulate related variables and methods into classes.
- Java uses automatic memory management
- The analysis of program performance is often based on order of growth analysis or on the closely related big-O analysis.
- Assertions and Exceptions
- Exercise 201, p. 408, The RuntimeException class has an alternative constructor that takes a single String argument. Modify the above code so that it tests the behavior when this second constructor is used,
In the following code, identify the boundary conditions for the input to the method chk. Modify the code so that an exception is thrown when boundary conditions are not met
- Exercise 202, p. 410, By modifying the code above, verify that the exception is not thrown when the length of the input array is greater than zero.
- Exercise 203, p. 410, Exceptions will be thrown by the following code unless the arguments to the method chain have certain qualities. Suggest suitable preconditions for chain, and then modify the code so that an informative exception is thrown when those preconditions are not met.
- Exercise 204, p. 411:
For each of the following, write one or more Java statements that will cause the Java runtime to automatically throw the given exception.
- ArithmeticException
- ArrayIndexOutOfBoundsException
- ClassCastException
- Activity 30 Argument Checking, p. 412
- 30.1: the definition of the static method averageGrade, which takes an array of doubles as its input.
Modify this method so that it throws an exception when either:
the input array of doubles is empty; or any of the grades is outside the range of 0 to 100 (inclusive).
- 30.2, The static method mystery takes a double as its input and performs a short sequence of arithmetic operations in order to output a real number in the form of a double.
Modify the definition below so that an exception is thrown if the input is one of these values. Infinity or NaN
Week 29 : March 21 - March 28
- Lab 8: Elevens
- Task 8.1, p. 413, Define the Card class in accordance with the description, public class Card
- Task 8.2, p. 415, Define the Deck class in accordance with the description given on the previous page.
- Task 8.3, p. 416, Define the shuffle method of the Deck class in accordance with the description given above.
- p. 417, Download lab08_nb.zip and create Project Lab 08.
- Task 8.4, p. 421, Complete the definition of the ElevensBoard class by implementing the two abstract methods (isLegal and anotherPlayIsPossible) specified in the superclass Board and the two methods (containsPairSum11 and containsJQK) that are specific to the Elevens game.
- Lab Checker 8, p. 422
- The rest of Lab 8 is extra credit
- March 28: Finish Unit 7, Searching, Sorting, and Program Analysis. Finish Section 3 Algorithms
Section 4: Epilogue and Review
The final section emphasizes the importance of review and practice in preparation for the Advanced Placement Exam.
- Unit 11: Review and Practice (Week 30 - 34) March 28 (Spring Break Apr 10-14) - May 2 (Level A Exam Tuesday May 2 8am)
- Free-response Question Sets 1 - 3
- Week 30 : March 28 - April 4
- Introduction, p. 426-429
- Question Set 1
- Pt 1, p. 429, public class Employee, public class Message, A large electronics manufacturing company runs a "social networking" website accessible to its employees
- Complete the override for the equals method of Employee, use getID(). Complete public int compareTo( Employee b ).
- public boolean canViewMessage( Message m )
- Pt 2, p. 430, A company runs a web farm consisting of a number of computers called servers.
- public class WebFarm with ArrayList
- Write a definition for the needsAttention() method of WebFarm that returns an ArrayList containing the servers that are not functioning normally. Use ping()
- Add a constructor for the Quad class that inputs a String representing an IP address and that stores the four components of the IP address in the corresponding elements of the ipComponents array.
- The Server class is modified to implement the Comparable interface. Complete the Quad class by writing a definition for the compareTo method based on the above rule
- Pt 3. p. 431, A government department is creating a computer program to calculate the nutritional value of various meals depending on the ingredients and the methods used to combine the ingredients.
- public interface Ingredient. public class Recipe
- Complete a definition for the getMaxCalorie() method of Recipe that returns the Ingredient that provides the greatest number of calories in this Recipe
- Complete a definition for the removeZeroCalorie method of Recipe that removes from the ingredients list each item that provides zero calories.
- Complete the following definition for primaryIngredients. public ArrayList primaryIngredients( double v )
- Pt 4, p. 432, HTML (HyperText Markup Language) is a coding system
- public class TextFormatter
- Complete the definition of private int firstIsolatedMark(String segment )
- Complete the definition of private int matchingIsolatedMark( String segment, int start )
- Complete the definition of private String process( String segment )
- Week 31 : April 4 - April 11
- Question set 2
- Pt 1, p. 433, Fast food company
- public class Product. public class MItem extends Product. public class Combo extends Product
- Complete the definition for the total method of Combo. public double total()
- Complete the following definition for the static method calcComboPrice that inputs a Combo and returns its discounted price. public static double calcComboPrice( Combo c )
- Complete the following definition for the static highestPricedCombo method that inputs an ArrayList of Combos and returns the Combo with the highest price. public static Combo highestPricedCombo ( ArrayList c )
- Pt 2, p. 434, IT Dept
- IT Dept. public class Domain, public class EmailAddress ,
- Complete the following definition of the static method emailRoot that inputs an email address and outputs a String consisting of the domain root of that email address.
- Complete the following definition for filter that takes an ArrayList emails of email addresses and an ArrayList rootsAllowed of domain roots, and removes every email address from emails whose root is not in rootsAllowed.
- The static method rootTally inputs an ArrayList of email addresses and returns an ArrayList of RootCounts, where the RootCount class is defined as ...
- public static ArrayList rootTally( ArrayListemails ) . Complete this definition
- Pt 3 p. 435, Capsule Hotel
- public class Floor. public class Hotel
- Complete the following definition for the isFull() method of Hotel which returns true if the hotel is completely full, otherwise it returns false. public class Hotel()
- Complete the following definition for placeOccupant:
public boolean placeOccupant( Occupant c )
- Implement the removeOccupant method of Hotel that inputs an Occupant and, if the occupant currently occupies one of the hotel's capsules, removes him/her from that capsule, leaving it unoccupied.
- Pt 4 p. 436, The Game of Life
- The inBounds method takes two int inputs and returns true if they are valid row and column indexes (in that order) of an LED in the grid or false if not. Complete the definition. private boolean inBounds( int row, int col )
- Complete the neighbors definition
private ArrayList neighbors( int row, int col )
- The play method takes no inputs and causes all the game rules to be applied once. Complete this definition
- Week 32 : April 11 - April 18
- Question set 3
- Pt 1, p. 437, A local sports league divides teams into divisions
- A team is represented by the Team class. Complete the following definition for the getPoints method of Team.. public int getPoints()
- The reassignTeams() method switches the least successful team from each division with the most successful team from the next lowest division below. Complete this definition.
public void reassignTeams()
- Complete the following definition of the addTeam method of League by writing a definition for findUndersizedDivision that returns a division that is undersized, or any one of the divisions if they all contain the same number of teams. public Division findUndersizedDivision()
- Pt 2, p. 438, A number card is a card on which is printed a number from 1 through 10. These cards are grouped in card sets consisting of collections of number cards with no duplicates.
- Complete the following definition for contains. public boolean contains(int value)
- Complete the following definition for split:. public void split( int pivot, ArrayListlower, ArrayList higher )
- Complete the following definition for intersect. public CardCollection intersect( CardCollection b )
- Part 3, p. 439. A corporation's shipping department accepts products on a conveyor belt from the manufacturing plant.
- The constructor for PQueue must assign to the variable products an empty ArrayList. Complete the following definition. public PQueue()
- Complete the following definition for addProduct. public void addProduct( double weight, String id )
- Complete the following definition for productsExceeding. public int productsExceeding( double weight )
- Complete the following definition for nextProduct. public Label nextProduct()
- Part 4, p. 440, Consider the following class that creates a list of compound words
- The method findMaxLength should find and return the length of the longest word in wordList. Complete the following definition. private int findMaxLength(). The list, wordList, consists of a collection (without duplicates) of words that can be found in the dictionary. The addCompoundWords method creates two new words for each pair of words in wordList whose lengths add up to letterSum. Complete the definition: private void addCompoundWords( ArrayList compoundWords, int letterSum )
- The buildWords method builds a list of new words. It finds these new words by considering all pairs of distinct words from wordList. Complete the following definition.. public ArrayList buildWords() you may use any of the methods found in the CompoundWordCreator class declaration.
- Week 33, 34 : April 18 - May 2
- Two APCS Level A Review books to consider getting:
- The eIMACS online edition of Be Prepared for the AP Computer Science Exam in Java, 6th ed., by Maria Litvin and Gary Litvin.
- May 2: Finish Section 3, Review, APCS Level A Exam Tuesday May 2, 8am
- After the APCS Exam, May 2 - end of school:
- Advanced Topics
- Searching and Sorting
- Program Analysis
- Data Structures
- Making Android Apps