0% found this document useful (0 votes)
32 views8 pages

Unit 4 Summative Assessment Review (2023-2024) (Part 1)

This document provides a review of concepts related to references, inheritance, polymorphism, abstract classes and instance variables. It contains multiple coding examples and questions about class relationships and valid code. Key topics covered include inheritance hierarchies, reference assignment, polymorphic method calls, abstract method implementations, and instance variable usage.

Uploaded by

treehouse52906
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views8 pages

Unit 4 Summative Assessment Review (2023-2024) (Part 1)

This document provides a review of concepts related to references, inheritance, polymorphism, abstract classes and instance variables. It contains multiple coding examples and questions about class relationships and valid code. Key topics covered include inheritance hierarchies, reference assignment, polymorphic method calls, abstract method implementations, and instance variable usage.

Uploaded by

treehouse52906
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Name: __________________________________ Date: __________________ Period: _________

AP Computer Science A
Unit 4 Summative Review
References, Assignment, Polymorphism, Abstract Classes, and Instance Variables

1. Trace the following program and determine which corners end


up with beepers. (Assume all imports)

public class Runner1


{
public static void main(String[] args)
{
UrRobot beast;
UrRobot storm;
UrRobot cyclops;

beast = new UrRobot(1, 1, Directions.East, 5);


storm = new UrRobot(2, 1, Directions.East, 5);
cyclops = new UrRobot(3, 1, Directions.East, 5);

storm = cyclops;

beast.move();
beast.putBeeper(); // St: __________ Ave: __________
storm.move();
storm.putBeeper(); // St: __________ Ave: __________
cyclops.move();
cyclops.putBeeper(); // St: __________ Ave: __________

cyclops = beast;
beast = storm;

beast.move();
beast.putBeeper(); // St: __________ Ave: __________
storm.move();
storm.putBeeper(); // St: __________ Ave: __________
cyclops.move();
cyclops.putBeeper(); // St: __________ Ave: __________

beast.turnOff();
storm.turnOff();
cyclops.turnOff();
}
}
2. Refer to Runner2.java given below. (Assume all imports)
1 public class Runner2
2 {
3 public static void main(String[] args)
4 {
5 World.setVisible(true);
6 World.setDelay(10);
7
8 UrRobot amy = new UrRobot(3, 2, Directions.East, 0);
9 amy = null;
10
11 amy.move();
12 amy.putBeeper();
13 }
14 }

2a. Identify the line where an error first appears. 2a. ______________________

2b. What type of error can this error be classified as? 2b. ___________________________

3. Refer to Runner3.java given below. (Assume all imports)


1 public class Runner3
2 {
3 public static void main(String[] args)
4 {
5 UrRobot sean, bruce, brenda, ellen;
6 sean = new UrRobot(1, 1, Directions.North, 10);
7 brenda = new UrRobot(5, 2, Directions.East, 9);
8
9 ellen = brenda;
10 brenda = new UrRobot(2, 3, Directions.South, 8);
11 sean = ellen;
12 ellen = new UrRobot(4, 7, Directions.West, 7);
13 brenda = sean;
14 }
15 }

a. Identify every line where a reference is being declared. 3a. ______________________

b. Identify every line where an object is being instantiated. 3b. ______________________

c. Identify every line where a reference is being initialized. 3c. ______________________

d. Identify a reference that is never initialized. 3d. ______________________

e. After being initialized, how many times does the reference 3e. ______________________
brenda get reassigned?
4. Given the following code, change the assignment of the reference below three times to a robot
and increase the street and avenue by one for each change in assignment.

public class Runner4


{
public static void main(String[] args)
{
World.setVisible(true);

UrRobot buddy = new UrRobot(1, 1, North, infinity);

__________________________________________________________________

__________________________________________________________________

__________________________________________________________________
}
}

5. Refer to the following simplified UML (Unified Modeling Language) Class Diagram.

BeeperLayer
+putBeepers() : void
+layBeepers() : void
+putAndMove() : void

TwoRowLayer ThreeRowLayer FourRowLayer


+putBeepers() : void +putBeepers() : void +putBeepers() : void

a. What do you think the "+" sign signifies in front of the method names?

b. What benefits are provided by creating a common superclass for a set of closely related
classes?

c. How could the concept of polymorphism be illustrated using these classes?


6. Refer to the following class headers to determine whether each statement is true or false.

public class Harvester extends UrRobot {…}


public class StairSweeper extends UrRobot {…}

public class MileWalker extends UrRobot {…}


public class SuperMileWalker extends MileWalker {…}

a. A Harvester IS-A UrRobot true false

b. A UrRobot IS-A Harvester true false

c. A MileWalker IS-A UrRobot true false

d. A SuperMileWalker IS-A MileWalker true false

e. A SuperMileWalker IS-A UrRobot true false

7. Refer to the following class headers to determine which of the following are valid instantiations.
(Assume each class has a constructor that accepts four parameters: int, int, Direction, int)

public class Harvester extends UrRobot {…}


public class StairSweeper extends UrRobot {…}

public class MileWalker extends UrRobot {…}


public class SuperMileWalker extends MileWalker {…}

a. UrRobot harsh = new StairSweeper(1, 1, Directions.North, 0);

b. MileWalker sam = new Harvester(1, 1, Directions.North, 0);

c. Harvester caden = new UrRobot(1, 1, Directions.North, 0);

d. UrRobot jaleel = new SuperMileWalker(1, 1, Directions.North, 0);

e. SuperMileWalker bennett = new MileWalker(1, 1, Directions.North, 0);

f. MileWalker james = new SuperMileWalker(1, 1, Directions.North, 0);


8. Refer to the following class headers to determine which of the following are valid instantiations.
Circle your choice.

public class AnimalBot extends UrRobot {…}


public class MammalBot extends AnimalBot {…}
public class BearBot extends MamamalBot {…}
public class TigerBot extends MammalBot {…}
public class GrizzlyBearBot extends BearBot {…}

8a. UrRobot mango = new AnimalBot(…); 8a. valid invalid

8b. BearBot winnie = new MammalBot(…); 8b. valid invalid

8c. GrizzlyBearBot blackie = new BearBot(…); 8c. valid invalid

8d. UrRobot ariel = new TigerBot(…); 8d. valid invalid

8e. MammalBot mum = new UrRobot(…); 8e. valid invalid

8f. MammalBot dud = new GrizzlyBearBot(…); 8f. valid invalid

8g. AnimalBot bruh = new TigerBot(…); 8g. valid invalid


public class BackwardWalker extends UrRobot
public class MileWalker extends UrRobot {
{ // constructor omitted
// constructor omitted
public void move()
public void moveHalfMile() {
{ turnAround();
super.move(); super.move();
super.move(); turnAround();
super.move(); }
super.move();
} public void turnAround()
{
public void move() turnLeft();
{ turnLeft();
moveHalfMile(); }
moveHalfMile(); }
}
} public class DropBeeperWalker extends UrRobot
{
// constructor omitted

public void move()


{
putBeeper();
super.move();
}
}

10. Explain how the following code demonstrates polymorphism?

public static void main(String[] args)


{
UrRobot morph;

morph = new MileWalker(1, 1, Directions.East, 10);


morph.move();
morph = new BackwardWalker(5, 5, Directions.South, 10);
morph.move();
morph = new DropBeeperWalker(3, 3, Directions.West, 10);
morph.move();
morph.turnOff();
}

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________
For 11-12, refer to the simplified UML (Unified Modeling Language) Class Diagram
shown below. Assume the ShapeBot class extends the UrRobot class.

ShapeBot
+getArea() : double
+getPerimeter() : double
+createShape() : void
-putAndMove() : void
-turnRight() : void
-turnAround() : void

TriangleBot CircleBot HexagonBot


+getArea() : double +getArea() : double +getArea() : double
+getPerimeter() : double +getPerimeter() : double +getPerimeter() : double
+getCentroid() : Point +getDiameter() : int +getCircumCenter() : double
-findMid(Segment s) : Point +getCenter() : Point -getApothemLength() : double

11. Determine whether each of the following statements are valid or not valid. Circle your answer.

1 public static void main(String[] args)


2 {
3 TriangleBot tri = new TriangleBot(…);
4
5 System.out.println(tri.getPerimeter()); Valid Invalid
6
7 tri.turnRight(); Valid Invalid
8
9 System.out.println(tri.getCentroid()); Valid Invalid
10 }

12. Determine whether each of the following statements are valid or not valid. Circle your answer.

1 public static void main(String[] args)


2 {
3 ShapeBot myShape = new CircleBot(…);
4
5 System.out.println(myShape.getArea()); Valid Invalid
6
7 myShape.putAndMove(); Valid Invalid
8
9 System.out.println(myShape.getDiameter()); Valid Invalid
10 }
Rate yourself on a scale of 1 – 5 (least to most) confident on your understanding of each of the
following vocabulary terms.

Vocabulary Term Confidence Rating


(No Confidence) --------> (Very Confident)

Class: 1 2 3 4 5

Method: 1 2 3 4 5

Object: 1 2 3 4 5

Reference: 1 2 3 4 5

Assignment: 1 2 3 4 5

Inheritance: 1 2 3 4 5

extends: 1 2 3 4 5

Superclass: 1 2 3 4 5

Subclass: 1 2 3 4 5

IS-A Relationship: 1 2 3 4 5

Polymorphism: 1 2 3 4 5

private: 1 2 3 4 5

public: 1 2 3 4 5

constructor: 1 2 3 4 5

Parameter: 1 2 3 4 5

Argument: 1 2 3 4 5

Abstract Class: 1 2 3 4 5

Instance Variable: 1 2 3 4 5

Initialize: 1 2 3 4 5

Local Variable: 1 2 3 4 5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy