COMPUTER SCIENCE Summer 2007
Review for Unit 1 Quiz 2, Labs04-08
- Look over the review for
Quiz1 Units00-04
- Lab04 Take the Field, p. 16
- instance methods - known for all instances of an object. All Robots know how to turnLeft(), move(), pickBeeper().
- class methods - known only for a particular class. Lab04 class knows how to takeTheField.
- class methods usually use static as part of their definition
- The class method takeTheField() passes an object as an argument - takeTheField(maria) ... not maria.takeTheField()
- Lab04 Exercises Part 1, p. 17
- karel is a(n) ___ and josie is a(n) ____
- What commands can karel understand? josie?
- maria and gary (from Lab04) are ___ What commands can maria and gary understand?
- None of the statements on this page are correct.
- 1-3: Why can't karel turn right? Why can't karel put down a beeper? In class NewLab, why can't the call to maria to pick up a beeper be executed?
- 4: Why do these two commands to josie cause a runtime problem?
- How can class NewLab access takeTheField from Lab04? Which has the correct syntax? What is wrong with each of 5-9?
- Lab04 Exercises Part 2, p. 18
- What changes are needed to have the Athletes pass around this new section of wall?
- We only needed to change part of takeTheField(). The rest of the program code for Lab04 stayed the same.
- Go the Java API for the Math class and find the method that takes no arguments, 2 arguments?
- Math methods are more conveniently static because ______
- Class Hierarchy, p. 19
- If Athletes have green feet what subclasses would too?
- How about blue scales for Climbers, curly tails for Robots, and sharp teeth for Racers?
- Find the legal commands in each column for karel (Robot), gary (Athlete), lisa (Climber), and mary (Racer)
- Discussion - Loops, p. 20
- "for" loops are definite loops
- The move()/putBeeper() loop runs ___ times
- The pickBeeper() loop runs ___ times
- The increment operator is ___
- Understand the table of values for k and the test k <= 6
- Declaring the loop control variable within the loop
- Lab05 Shuttle Run, p. 21
- Understand how to define sprint() n positions, put() n beepers, and pick() n beepers for Racer, using "for" loops.
- Discussion - Loops and if, p. 22
- boolean method calls: karel.nextToABeeper() used in while loops and if statements.
- a while loop can repeat itself 0 or more times (even infinite). An if statement runs 0 (if false) or 1 time (if true) only.
- Exercises - Boolean methods, p. 23
- Look at the
API for Robot. Which methods are boolean (return true/false)?
- Use while loops and the boolean methods for 1-3
- #3 - determine if the return value is true or false. Note that !true is false and !false is true.
- Evaluate the && (and) and || (or) chart
- We'll do the truth table in class
- Lab06 Half a Dozen Tasks, using while loops and boolean method calls, p. 24
- For this quiz, review how you used while loops and boolean methods in Lab06
- Exercises Lab 06, p. 25
- Use while loops (indefinite loops), if statements, or for loops (definite loops)
- Lab07 Exploration, polymorphism, p. 26
- Look at Mountain.java. explore(), explore_west(), and explore_east() are static methods (class methods).
- From Lab07, explore() is called using the syntax Mountain.explore() and arguments of either Climber, HillClimber, or StepClimber.
- Polymorphism: the behavior of climbUpLeft(), climbUpRight(), etc. depends upon the object that is sent to arg.
- Exercises Lab07, p. 27
- Understand these questions in detail
- Discussion - Polymorphism, p. 28
- You can have a more general arg (superclass) be sent a more specific arg (subclass), i.e. a Climber arg can be sent a HillClimber, not an Athlete.
- Lab08 Hurdle Racing, 3 types of hurdles and 2 Racer subclasses
- Racer jumps hurdles only one unit high
- SteepleChaseRacer jumps hurdles any number of units high
- BoxTopRacer jumps hurdles any units high and any units wide.
- Exercises Lab08, p. 30
- Robot karel = new Knight(...) is okay, you Robot (on the left) is superclass to Knight (on the right)
- To downcast to a more specific class:
Athlete maria = (Atlete) karel