0% found this document useful (0 votes)
18 views

Object-Oriented-Programming-22-23-Resources

The document outlines a curriculum for an Object-Oriented Programming course, focusing on software engineering characteristics, Java syntax, and the development of classes and methods. It includes lessons on defining blueprints, managing objects, and debugging strategies, along with reflections and exercises for students. The course emphasizes collaboration, creativity, and problem-solving skills in software engineering.

Uploaded by

henryszuster
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Object-Oriented-Programming-22-23-Resources

The document outlines a curriculum for an Object-Oriented Programming course, focusing on software engineering characteristics, Java syntax, and the development of classes and methods. It includes lessons on defining blueprints, managing objects, and debugging strategies, along with reflections and exercises for students. The course emphasizes collaboration, creativity, and problem-solving skills in software engineering.

Uploaded by

henryszuster
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 117

Object-Oriented Programming ('22-'23)

Welcome to CSA
Resources
Unit 1 Lesson 1

Software Engineering Characteristics

Name: ____________________________________________________ Period ______ Date ___________________

Software Engineering Characteristics


Which of the software engineering characteristics is your strongest?

Which one has the most room for you to grow? Why?

Name: ____________________________________________________ Period ______ Date ___________________

Software Engineering Characteristics


Which of the software engineering characteristics is your strongest?

Which one has the most room for you to grow? Why?
Object-Oriented Programming ('22-'23)
Java Lab
Resources
CSA Unit 1 Guide

Lesson 2: Java Lab


Java Syntax
Now that you have learned about syntax, what do you think it means to have a syntax error?

Term Definition Example / Picture / Code

syntax error

Reflection
What did you learn from your classmates today?

How do the ideas and thoughts shared in class contribute to your identity as a software engineer?
CSA Unit 1 Guide

Lesson 3: The Neighborhood


Defining a Blueprint
Draw a house in the space provided below. (Don't worry about making it perfect!)

Video: Object-Oriented Programming

In your own words describe object-oriented Follow along with the video, and write your own
programming. class here.

Term Definition Example / Picture / Code

class

package
CSA Unit 1 Guide

Video: Welcome to The Neighborhood

What are things a Painter object can do?


P
A
I
N
T
E
R
What is one thing they cannot do?

U
M
L

D Painter Class UML Diagram


I
A Painter
G
R xLocation
yLocation
A
direction
M remainingPaint

void turnLeft() boolean isFacingNorth()


void move() boolean isFacingEast()
void paint(String color) boolean isFacingSouth()
void scrapePaint() boolean isFacingWest()
int getMyPaint() String getColor()
void takePaint() int getX()
boolean isOnPaint() int getY()
boolean isOnBucket() String getDirection()
boolean hasPaint() void setPaint(int paint)
boolean canMove()
boolean canMove(String direction)
CSA Unit 1 Guide

Video: Creating Objects

How is memory in a computer like the land a What is the relationship between a Painter object
house is built on? and the Painter class?

Term Definition Example / Picture / Code

state

Finding and fixing problems in an algorithm


or program.

Reflection
Curiosity is one of our four qualities of a software engineer. How did you engage your curiosity throughout
this class period?
CSA Unit 1 Guide

Lesson 4: Navigating and Painting


Giving Instructions

Write your instructions for the delivery driver here. Write your instructions for the bus driver here.

Video: Calling Methods

Three Things You Learned: Two Interesting Ideas:

● ●

● ●

● One Question or Wonder:

Term Definition Example / Picture / Code

public void move() {

// code to make a Painter object move


void method
}
CSA Unit 1 Guide

Painter Class UML Diagram


Look at these methods in the UML diagram for the Painter class. What keyword is in front
of the method name? Where have you seen this word before?

What do you think would happen if we tried to call one of these methods without first instantiating a Painter
object?

Reflection
How is giving directions to a computer similar to giving directions to a person? How is it different?
CSA Unit 1 Guide

Lesson 5: One-Way Selection Statements


Video: Conditional Statements

Write a scenario that you could check using a


Follow along with the video, and write your own
conditional statement.
conditional statement here.

Term Definition Example / Picture / Code

boolean

To exit a method and go back to the point in


the program that called it with the requested
value or information

Painter Class UML Diagram


Look at these methods in the UML diagram for the Painter class. What keyword is in front of the method
name? What do you think this word means?
CSA Unit 1 Guide

Finding and Fixing Logic Errors

Term Definition Example / Picture / Code

A call to turnLeft() was missing, so


logic error the painter did not turn when the
programmer expected them to.

● Think about what might be wrong and form a _________________ or two


________________ looking at the code.

● ________________ what the suspicious line should do.

● Check your ______________ and think about your _______________.

Reflection
What parts of this lesson made you feel confident in your work? What would you like to practice some more?
CSA Unit 1 Guide

Lesson 6: PainterPlus
Managing Social Media Apps
You are designing a program to keep track of the different social media services that you use. You create a
class called SocialMedia to represent all service media accounts with the attributes username and followers
as well as a method to postMessage.

Does this SocialMedia class represent all the types of social media accounts you use?

What other types of social media services are there? What are the similarities and differences between these
types of social media services?
CSA Unit 1 Guide

Video: Inheritance P
A
What is the relationship between Annotate this code segment using the vocabulary from this I
ClubOfficer and ClubMember? video. N
T
public class ClubOfficer extends ClubMember {
E
R
P
L
U
Painter and PainterPlus UML Diagram S
Draw your UML diagram for the PainterPlus class below.

PainterPlus Painter U
M
xLocation L
yLocation
direction D
remainingPaint I
A
void turnLeft() boolean isFacingNorth() G
void move() boolean isFacingEast() R
void paint(String color) boolean isFacingSouth() A
void scrapePaint() boolean isFacingWest() M
int getMyPaint() String getColor()
void takePaint() int getX()
boolean isOnPaint() int getY()
boolean isOnBucket() String getDirection()
boolean hasPaint() void setPaint(int paint)

boolean canMove()
boolean canMove(String direction)

Reflection
Think of a board game, card game, or video game that you play. How could an element of your game be
represented by a class? What elements could be represented with subclasses?
CSA Unit 1 Guide

Lesson 7: Writing Methods


Birds with Special Behaviors
Do all birds have the same attributes and behaviors as a Bird?

Do these birds have additional attributes and behaviors?

Should these additional attributes and behaviors be accessible by the Bird class?

Video: Writing a Method

Term Definition Write the method signature for


startMeeting() here.

method signature

Writing a Method

What does it mean for a method to be a void method?

What are the similarities and differences between calling methods and writing methods?
CSA Unit 1 Guide

Why would we write a new method in the subclass instead of in the superclass?

What does a PainterPlus object need to do to turn right? What would we write in the body of the
turnRight() method?

Painter and PainterPlus UML Diagram


Return to the PainterPlus UML diagram from Lesson 6 and add your new method.

Reflection
What errors did you encounter while writing your code today?

How did you find and fix the error?


CSA Unit 1 Guide

Lesson 8: Code Reviews


Video: Commits and the Backpack
Why would we want to commit code?

Video: Software Engineering – Code Reviews

Three Things You Learned: Two Interesting Ideas:

● ●

● ●

● One Question or Wonder:

What would be some examples of bad feedback?


CSA Unit 1 Guide

TAG

Reflection
What is a skill you are currently practicing that you would like feedback on?
CSA Unit 1 Guide

Lesson 9: Loops
Components of an Algorithm

What do you know or remember about algorithms?

Revisiting the Painter

How could we use while loops with these new methods?

boolean hasPaint()
boolean isFacingNorth()
boolean isFacingEast()
boolean isFacingSouth()
boolean isFacingWest()

What new behaviors could we add to the PainterPlus class using while loops and these new methods?
CSA Unit 1 Guide

Video: While Loops


Complete the following definitions while watching the video.

Term Definition Example / Picture / Code

control structure

iteration statement

a control structure which executes a


block of code repeatedly as long as a
condition is true
TRUE!

Debugging a while loop

Why does this code segment not execute?

while (myPainterPlus.isFacingWest()) {
myPainterPlus.move();
}

What is causing this outcome?


CSA Unit 1 Guide

Algorithms

Term Definition Example / Picture / Code

algorithm

efficient Getting the best outcome with the least


amount of waste.

Reflection
What errors did you encounter while writing your code?

How did you find and fix the error?


CSA Unit 1 Guide

Lesson 10: Two-Way Selection Statements


Selection and Logic

What is the purpose of the if-else statement? How does the ! operator influence the boolean
statement?

Video: Two-Way Selection and NOT


Revise your thoughts above based on the definitions in the video.

Term Definition Example / Picture / Code

two way selection

Painter and PainterPlus UML Diagrams


Return to the PainterPlus UML diagram from Lesson 6 and add your new method.

Reflection
Based on the feedback you received in your code review, what is one goal you have for yourself as you write
code in the future?
CSA Unit 1 Guide

Lesson 11: Debugging Strategies


Finding Errors

When have you encountered How did you find and fix these What tools or strategies would
logic errors in your programs? errors? help find and fix logic errors?

Methods That Return

What do these methods return?

int getMyPaint()
What do you think these methods do? int getX()
int getY()
String getDirection()

Why would this information be useful?

Video: Printing in Java

How can printing to the console be Write a sample print statement that prints: "Fido's age:"
used as a debugging technique? followed by the age stored in the fido object.
CSA Unit 1 Guide

Printing PainterPlus Information


What would the method signature be for this
new method?

What would we write in the body of this


method?

Painter and PainterPlus UML Diagrams


Return to the PainterPlus UML diagram from Lesson 6 and add your new method.

Reflection
How were you able to use System.out.println() to find and fix errors in your code?
CSA Unit 1 Guide

Lesson 12: Decomposition and Design


Algorithmic Design
Scenario:

Algorithm:

Solving Problems

Term Definition Example / Picture / Code

decomposition

A software engineer must decide what to do


when someone enters a String that is not
a color into a Painter's paint parameter.

Code that is unnecessary.


CSA Unit 1 Guide

Software Engineering Skills


One of the problem solving strategies that I have focused on developing is ______________________. This
strategy has improved my skills as a software engineer because…

My creativity shows in this course when I …

One example of collaboration from this course is…

My growth as a learner is visible when…

Reflection
What parts of this lesson were similar to things you have encountered in your life?

What were you confident about? What would you like to practice more?
CSA Unit 1 Guide

Lesson 13: PatternPainter


Term Definition Example / Picture / Code

A situation in which a class serves as a


superclass for more than one subclass.

Why should we make a new type of Painter instead of adding methods for
this problem to PainterPlus?

Which should this new class extend – Painter or PainterPlus?

Reflection
What stands out to you about how class hierarchies are used in programs? What makes you wonder?
CSA Unit 1 Guide

Lesson 14: BackgroundPainter


How could we paint the background first?

Should we create a new class or add it to an existing class?

Which class should this new class extend?

Reflection
You are now almost done with your first unit of AP CSA. How has your perspective or understanding of Java
been changed, challenged, reinforced, or deepened as a result of this course?
CSA Unit 1 Guide

Lesson 15: Open Source Code

public class Pyramid { What parts of this open source code look familiar?
public static void main(String args[]) {
int i = 0;
while (i <= 5) {
int r = 0;

while (r < i) {
System.out.print("*");
System.out.println();
}
}
}
}

Reflection
What three big ideas are you most confident in explaining?

What two ideas might you want to revisit in more depth while working on your Asphalt Art Project?
Name(s)__________________________________________ Period ______ Date ___________________

U1L2 Extra Practice - Java Lab

Check for Understanding

Question: Which of the following is TRUE about the main method?


A. It does NOT need to follow syntax rules.
B. It comes before the class header.
C. It is where the program starts running.
D. There is no purpose because the main method is not required.

Response:

AP Exam Prep

Question: Which of the following are syntax errors?


A. Capitalizing letters that should be lowercase
B. Lowercasing letters that should be capitalized
C. Forgetting a semicolon at the end of a line of code
D. Name of class is different than the name of the file
E. All of the above

Response:

Extra Practice

Do This: Fix the syntax errors by writing the correct code in the "Correct" column.

Incorrect Correct

public class MyNeighborhood


public static void MAIN(String[] args)

Painter myPainter = new Painter()

myPainter.move();

CSA 1
Object-Oriented Programming ('22-'23)
The Neighborhood
Resources
Name(s)__________________________________________ Period ______ Date ___________________

U1L3 Extra Practice - The Neighborhood

Check for Understanding

Question: Which of the following are attributes that a Student object might have?

I. name
II. grade
III. goToSleep

A. I only
B. II only
C. I and II
D. II and III
E. I, II, and III

Response:

AP Exam Prep

Question: A student creates a Painter class. The object art will be declared as a type Painter. Which of
the following statements is true?

a) art is an instance of the Painter class


b) Painter is an instance of the art object

Response:

Extra Practice

Give your own example of a class and identify what attributes and behaviors the class would have. Then give
some examples of objects that you could create from the class.

CSA 1
Object-Oriented Programming ('22-'23)
Navigating and Painting
Resources
Name(s)__________________________________________ Period ______ Date ___________________

U1L4 Extra Practice - Navigating and Painting

Check for Understanding

Question: What lines of code should replace /* missing code */ to produce the final state of the Painter
object and The Neighborhood shown here?

Start End

public class MyNeighborhood {


public static void main(String[] args) {
Painter myPainter = new Painter();

myPainter.turnLeft();
myPainter.turnLeft();
myPainter.turnLeft();

myPainter.move();

myPainter.takePaint();
myPainter.takePaint();
myPainter.takePaint();
myPainter.paint("white");
myPainter.move();

/* missing code*/

myPainter.paint("white");
myPainter.turnLeft();
myPainter.turnLeft();
myPainter.turnLeft();
myPainter.move();

}
}
CSA 1
a. myPainter.paint("white");

b. myPainter.paint("white");
myPainter.turnLeft();

c. myPainter.turnLeft();
myPainter.paint("white");

d. myPainter.paint("white");
myPainter.turnLeft();
myPainter.move();

e. No code is needed.

Response:

AP Exam Prep

Question: Given a Painter named jackie, which of the following lines of code will cause a syntax error?

I. jackie.move();
II. jackie.turnleft();
III. jackie.paint("red");

a. I only
b. II only
c. III only
d. I and II only
e. II and III only

Response:

Extra Practice

Do This: For each line of code, identify the name of the Painter and the name of the method.

Name of Painter Name of Method

picasso.takePaint();

basquiat.move();

dali.turnLeft();

frida.paint("red");

CSA 2
Object-Oriented Programming ('22-'23)
One-Way Selection Statements
Resources
Name(s)__________________________________________ Period ______ Date ___________________

U1L5 Extra Practice - One-Way Selection Statements

Check for Understanding

Question: What line of code should replace /* missing code */ so that the code compiles?

Painter jes = new Painter();


if ( /* missing code */ ) {
jes.move();
}

I. canMove()
II. jes.canMove()
III. canMove(jes)

A. I only
B. II only
C. III only
D. II and III
E. I, II, and III

Response:

AP Exam Prep

Do This: The code snippet below has five syntax errors. Identify and fix these errors by:
● Circling or highlighting the error in the original code.
● Rewriting the code with all errors debugged in the Debugged Code column.

Response:
Original Code Debugged Code

deshaun = new Painter();


deshan.move();

if (deshaun.isOnPaint) {
deshaun.scrapePaint;
deshaun.move();
}

deshaun.Move();

CSA 1
Extra Practice

Do This: Create a diagram to identify the similarities and differences between the methods you learned today
that returned a boolean value (isOnPaint(), isOnBucket(), and canMove()) and the methods you learned
yesterday that allowed you to move and work with paint (move(), turnLeft(), paint(), and takePaint()).

CSA 2
Object-Oriented Programming ('22-'23)
PainterPlus
Resources
Name(s)__________________________________________ Period ______ Date ___________________

U1L6 Extra Practice - PainterPlus

Check for Understanding

Question: Which of the following combinations of superclass and subclass are correct examples of
inheritance?

I. Plant is the superclass, Flower is the subclass


II. Car is the superclass, Wheel is the subclass
III. Book is the superclass, GraphicNovel is the subclass

a. I only
b. II only
c. III only
d. I and II only
e. I and III only

Response:

AP Exam Prep

Question: Think of an example of inheritance in your own life. What is the superclass? What is the subclass?

Response:

Extra Practice

Do This: Building off of your superclass and subclass from the above AP Exam Prep question:

1. Write the header (which starts with public class…) for your superclass.

2. Write the header for your subclass.

CSA 1
Object-Oriented Programming ('22-'23)
Writing Methods
Resources
Name(s)__________________________________________ Period ______ Date ___________________

U1L7 Extra Practice - Writing Methods

Check for Understanding

Question: Consider the following class:

public class ClubMember {

public ClubMember() {

Which of the following correctly implements the subclass ClubSponsor with a method called donate()?

A. public class ClubSponsor is-a ClubMember {

public ClubSponsor {
super();
}

public donate {
}

B. public class ClubSponsor is-a ClubMember {

public donate {
}
}

C. public class ClubSponsor extends ClubMember {

public ClubSponsor() {
super();
}

public void donate() {


}

CSA 1
D. public class ClubSponsor extends ClubMember {

public ClubSponsor() {
super();
}

public donate() {
}

E. public class ClubSponsor extends ClubMember {

public ClubSponsor() {
donate();
}

Response:

AP Exam Prep

Question: The PainterPlus class is shown below. You will write one method of the PainterPlus class.

public class PainterPlus extends Painter {


public PainterPlus() {
}

// turnRight
public void turnRight() {
turnLeft();
turnLeft();
turnLeft();
}
}

Write a new method called moveBackwards() that instructs PainterPlus to:


1. Turn by 180 degrees, in order to face the opposite direction.
2. Move forward one space.
3. Turn by 180 degrees, in order to face the initial direction.

Response:

CSA 2
Extra Practice

Do This: Adding more methods to our classes allows us to add more functionality and behaviors to objects.
Let’s add more functionality to the PainterPlus class:

1. Make a list of three methods that would be useful to add to the PainterPlus class.
2. For each method in your list, do the following:
a. Give it a name.
b. Write a description.
3. Write a method in Java for one of the three methods you described.

CSA 3
Object-Oriented Programming ('22-'23)
Code Reviews
Resources
Name(s)__________________________________________ Period ______ Date ___________________

U1L8 Extra Practice - Code Reviews

Check for Understanding

Question: Consider the following code segment. Which of the following would be the best example of good
feedback to give the programmer?

public class MyNeighborhood {


public static void main(String[] args) {
PainterPlus a = new PainterPlus();
if (a.canMove()) {
a.move();
}
}
}

A. "Please indent."
B. "Nice job!"
C. "Nice job! I wonder if the code would be easier to read if there was indentation."
D. "Please indent and use better variable names."
E. "Nice job! I wonder if the code would be easier to read if there was indentation. Also better variable
names might make the code more readable."

Response:

AP Exam Prep

Question: What does TAG stand for, and how can it be used to improve code reviews?

Response:

CSA 1
Extra Practice

Do This: Write a note to your group about how you like to receive feedback. You may choose to share:

● The type of feedback you find most useful


● What you’d like to focus on over the next few weeks that they can help with
● A concept that you’ve learned this year that you feel really confident about

CSA 2
How to Conduct a Code Review

What is a code review?


A code review is a development process to obtain peer feedback to identify bugs, share knowledge, and improve the
quality and performance of a program.

Why are code reviews important?


Software engineers use code reviews to obtain feedback on their solutions and implementation. A reviewer looks for
bugs, logic errors, and edge cases to help the developer improve the quality and performance of their program. Code
reviews benefit the developer and the project:

● Fewer bugs. Code reviews decrease the amount of bugs in a program before it reaches the user.

● Knowledge sharing. Software development teams learn from each other by reviewing each other's code.

● Code quality. Code reviews ensure the readability, efficiency, and maintainability of the program.

● Better performance. Code reviews help identify any performance issues in the program.

You will use code reviews in this course to strengthen your programming and collaboration skills. You will receive many
opportunities throughout the curriculum to review your peers' code and give meaningful feedback.
How to Request Feedback
To request feedback on their code from a group, select the Start Code Review button in the Review tab. This initiates
a code review and makes your project visible to your peers

You are unable to edit their code while it is open for review. Once you are finished receiving feedback, you can
select the Close Review button and resume editing your code.

When requesting feedback, it is also helpful to provide a description of the goals and intended outcome of the program
and include any additional relevant information. You can ask the reviewer to perform specific tasks or answer specific
questions, such as:

● Does the program do everything it is supposed to do?

● Is there any irrelevant or repetitive code?

● Is the program easy to understand and navigate?

2
How to Give Feedback
In the Review tab, choose a peer from the Review a classmate’s project… dropdown. If a peer has requested
feedback, their name will appear in the dropdown. You can only review peers that are within your code review group.

When you are finished providing feedback, select the Return to my project button. The requesting student can then
review the feedback and make any updates to their code.

Feedback should be helpful for the developer and focused on the program itself rather than the developer or their
abilities. When giving feedback:

● Be kind.

● Explain your reasoning.

● Make sure your feedback is linked to the goals and intended outcome of the program.

● If possible, include an example of how to improve the code.

● Balance giving explicit instructions with simply pointing out problems you find and letting the developer decide
how to address them.

● Encourage the developer to simplify code or add comments instead of just explaining it to you.

3
Guiding Questions
The following guiding questions are helpful questions to ask yourself while reviewing code. Not all questions will be
relevant for every type of project.

● Is the code well-designed and appropriate for the problem?

● Does the code behave as the developer intended?

● Could the code be made simpler?

● Would another developer be able to easily understand and use this code when they come across it in the
future?

● Did the developer choose clear names for variables, classes, methods, etc.?

● Are the comments clear and useful?

● Does the code follow good programming style?

4
Using TAG to Give Feedback
The following sentence starters will help you structure feedback. Not all sentence starters will be relevant for every type
of project.

● The best part of your code is . . . because . . .

T
● I really like this part of your code because . . .
● This is a high-quality program because . . .
● One thing you did really well is . . . because . . .
Tell them something you
like about their code ● You put a lot of thought and effort into . . .
● I'm really impressed with . . . because . . .

● One thing that is not clear to me is . . .


● What is the purpose of . . .
● Why is . . . ?

A
● How will you . . . ?
● I am wondering . . .
● I don't understand how . . . does / addresses . . .
Ask them something
about the code ● Did you consider . . . ?
● What is the program supposed to do if . . . happens?
● Where is . . . ?
● When does . . . ?

● One thing to improve on is . . .


● You need more / less . . . because . . .
● I think your next steps should be . . .
● Your program will be higher quality if you . . .

G ●

Perhaps you should add / remove / replace . . .
To make your program better, I would suggest . . .
Give a suggestion for ● I am confused by . . .
improvement
● You might consider . . .
● Do you think you should . . . ?
● Don't forget to . . .
● One minor mistake is . . .

5
Object-Oriented Programming ('22-'23)
Loops
Resources
Unit 1 Lesson 9

Name(s)_______________________________________________ Period ______ Date ___________________

Writing Algorithms

An algorithm is a set of instructions to solve a problem or accomplish a task. Algorithms are often written in
pseudocode, a plain language description of the steps in an algorithm.

Example: Navigate a PainterPlus object to an obstacle and paint the space in front of the obstacle white.

Step 1: Identify the problem.


What is the problem to be solved?

move a PainterPlus object to an obstacle paint the space in front of it

What are the constraints of the problem?

don't move into obstacles

What is the input to the problem?

None

What is the output or expected behavior?

the PainterPlus object is in front of an obstacle and has painted the space in front
of it

Step 2: Design the algorithm.


Create a PainterPlus object
While the PainterPlus object can move, move forward
Paint the square white

Step 3: Test the algorithm by implementing it in Java.

PainterPlus myPainterPlus = new PainterPlus();

while (myPainterPlus.canMove()) {
myPainterPlus.move();
}

myPainterPlus.paint(“white”);
takeAllPaint()
The takeAllPaint() method should take all paint from a paint bucket while it still has paint.

Start State End State

Painter is on a bucket with 5 units of paint. There is no more paint in the bucket.

Step 1: Identify the problem.


What is the problem to be solved?

What are the constraints of the problem?

What is the input to the problem?

What is the output or expected behavior?

2
Step 2: Design the algorithm.
Write your algorithm in pseudocode for the takeAllPaint() method.

Step 3: Test the algorithm by implementing it in Java.


Implement your algorithm in Java on Level 3.

3
paintLine()
The paintLine() method should paint in a horizontal or vertical line using a specified color as long as there are no
obstacles.

Start State End State

Step 1: Identify the problem.


What is the problem to be solved?

What are the constraints of the problem?

What is the input to the problem?

What is the output or expected behavior?

4
Step 2: Design the algorithm.
Write your algorithm in pseudocode for the paintLine() method.

Step 3: Test the algorithm by implementing it in Java.


Implement your algorithm in Java on Level 4.

5
Name(s)__________________________________________ Period ______ Date ___________________

U1L9 Extra Practice - Loops

Check for Understanding

Question: Which of the following is ALWAYS true for BOTH while loops and if statements?

A. Make decisions about whether or not to run code


B. Code inside the body runs forever
C. Code inside the body runs multiple times
D. Code inside the body runs only once
E. Code inside the body never runs

Response:

AP Exam Prep

Question: Consider the code below. How many times will the line labeled // move run?

PainterPlus myPainterPlus = new PainterPlus();

while (myPainterPlus.canMove()) {
myPainterPlus.move(); // move
}

a) 0 times
b) 1 times
c) 3 times
d) 8 times

Response:

CSA 1
Extra Practice

Do This: You’ve learned a lot of code and vocabulary so far. How are you feeling about AP Computer Science
A? What strategies did you use so far to be successful with the material? How can you continue to use these
strategies throughout the course of the class?

CSA 2
Object-Oriented Programming ('22-'23)
Two-Way Selection Statements
Resources
Unit 1 Lesson 10

Name(s)_______________________________________________ Period ______ Date ___________________

Using Two-Way Selection and NOT

moveOrTakePaint()
While a PainterPlus object can move forward, the moveOrTakePaint() method should move forward if a
PainterPlus object is not on a paint bucket. Otherwise, it takes all of the paint from the paint bucket.

Start State End State

Step 1: Identify the problem.


What is the problem to be solved?

What are the constraints of the problem?

What is the input to the problem?


What is the output or expected behavior?

Step 2: Design the algorithm.


Write your algorithm in pseudocode for the moveOrTakePaint() method.

Step 3: Test the algorithm by implementing it in Java.


Implement your algorithm in Java on Level 3.

2
moveSouth()
The moveSouth() method should move forward while a PainterPlus object can move south. If the PainterPlus
object is not facing south, it should turn right. Otherwise, it moves forward.

Start State End State

Step 1: Identify the problem.


What is the problem to be solved?

What are the constraints of the problem?

What is the input to the problem?

What is the output or expected behavior?

3
Step 2: Design the algorithm.
Write your algorithm in pseudocode for the moveSouth() method.

Step 3: Test the algorithm by implementing it in Java.


Implement your algorithm in Java on Level 4.

4
Name(s)__________________________________________ Period ______ Date ___________________

U1L10 Extra Practice - Two-Way Selection


Statements

Check for Understanding

Question: Where will the Painter be located after this code segment executes?

Painter myPainter = new Painter();

if (myPainter.canMove()) {
myPainter.move();
myPainter.turnLeft();
}
else {
myPainter.turnLeft();
}

A. B. C.

D. E. Does not compile

Response:

CSA 1
AP Exam Prep

Question: Improve the code segment below by simplifying the two if statements into an if-else statement.

Original Code Improved Code

Painter myPainter = new Painter();

if (myPainter.isOnPaint()) {
myPainter.turnLeft();
}

if (!myPainter.isOnPaint()) {
myPainter.move();
}

CSA 2
Extra Practice

Do This: Using while loops and if-else statements, navigate the Painter to the end state shown below.

Start End

CSA 3
Object-Oriented Programming ('22-'23)
Debugging Strategies
Resources
Name(s)__________________________________________ Period ______ Date ___________________

U1L11 Extra Practice - Debugging Strategies

Check for Understanding

Question: The following code segment has a logic error, but the programmer is having trouble finding the
error. The programmer wanted the Painter object to paint a line to the east, but it keeps going west.

Start Goal Result

1 PainterPlus myPainterPlus = new PainterPlus();

2 myPainterPlus.move();

3 myPainterPlus.move();

4 myPainterPlus.move();

5 myPainterPlus.move();

6 myPainterPlus.turnRight();

7 myPainterPlus.move();

8 myPainterPlus.takeAllPaint();

9 myPainterPlus.turnRight();

10 myPainterPlus.paintLine("green");

What information would be MOST helpful to print?

A. myPainterPlus.canMove("east");
B. myPainterPlus.getX();
C. myPainterPlus.getMyPaint();
D. myPainterPlus.isOnBucket();
E. myPainterPlus.getDirection();

Response:

CSA 1
AP Exam Prep

Question: Given a Painter object named myPainter, what is printed when the following code is run?

System.out.print(myPainter.getX() + ", " + myPainter.getY());

A. Does not compile


B. 2, 0
C. (2, 0)
D. 2 ", " 0
E. myPainter.getX, myPainter.getY

Response:

Extra Practice

Do This: Think of the error messages and unexpected results we've put on the Debugging Wall. How could
printing help in those situations?

CSA 2
Object-Oriented Programming ('22-'23)
Decomposition and Design
Resources
Unit 1 Lesson 12

Name(s)_______________________________________________ Period ______ Date ___________________

Decomposition

Sometimes, problems are so big that we need to break them down into manageable tasks first. This process is called
decomposition. Consider the following problem to paint an alternating checkerboard pattern in The Neighborhood.

Start State End State

To solve this problem, two different programmers wrote the following pseudocode.

Pseudocode A Pseudocode B

while the Painter can move south while the Painter can move
while the Painter can move east if the Painter is facing east
paint white paint white
move forward twice
if the Painter cannot move forward
move to the next row and face west turn right
move forward
while the Painter can move west turn right
paint red else
move forward twice move forward

move to the next row and face east if the Painter is facing west
paint red

if the Painter cannot move forward


turn left
move forward
turn left
Using Decomposition: Choice A
You have been asked to paint a square in The Neighborhood to mark off a safe play area for the children.

Start State End State

Decompose the problem to write algorithms for:

● moveFast() – move forward and collect paint as long as there are no obstacles

● paintSquare() – painting a square

You may also write additional algorithms for components of the problem as needed.

Pseudocode for moveFast() Pseudocode for paintSquare()

2
Using Decomposition: Choice B
You have been asked to paint dashed lines between the lanes of traffic.

Start State End State

Decompose the problem to write algorithms for:

● moveFast() – move forward and collect paint as long as there are no obstacles

● paintDashes() – paint lines that are two spaces long with an empty space in between from one end to the
other as long as there are no obstacles

You may also write additional algorithms for components of the problem as needed.

Pseudocode for moveFast() Pseudocode for paintDashes()

3
Using Decomposition: Choice C
You have been asked to paint a border around the food truck so it has a designated parking space. But someone left
paint buckets all over The Neighborhood, and you need to collect all of the paint as well.

Start State End State

Decompose the problem to write algorithms for:

● paintFast() – move forward, paint, and collect paint as long as there are no obstacles

● paintTruckBorder() – paint a border around the food truck

You may also write additional algorithms for components of the problem as needed.

Pseudocode for paintFast() Pseudocode for paintTruckBorder()

4
Using Decomposition: Choice D
Navigate and paint the path to the traffic cone.

Start State End State

Decompose the problem to write algorithms for:

● paintFastAndTurn() – move forward, paint, and collect paint as long as there are no obstacles and turn if
unable to move in the direction it is facing

● makeTurn() – turn left or right based on which direction a PainterPlus object is able to move

You may also write additional algorithms for components of the problem as needed.

Pseudocode for paintFastAndTurn() Pseudocode for makeTurn()

5
Name(s)__________________________________________ Period ______ Date ___________________

U1L12 Extra Practice - Decomposition and Design

Check for Understanding

Question: Describe how you helped the Painter break down a big problem into a smaller problem today.
How did that affect how you wrote your code?

Response:

AP Exam Prep

Question: You have been asked to paint a crosswalk to make The Neighborhood safer for pedestrians.

Start State End State

Which algorithms make the MOST sense to write in order to decompose the problem?

I. paintDiagonal
II. paintFast
III. turnAround

A. I only
B. II only
C. III only
D. I and II
E. I, II, and III

Response:

CSA 1
Extra Practice

Do This: Write the pseudocode for paintDiagonal to decompose the AP Exam Prep problem.

CSA 2
Object-Oriented Programming ('22-'23)
PatternPainter
Resources
Name(s)__________________________________________ Period ______ Date ___________________

U1L13 Extra Practice - PatternPainter

Check for Understanding

Question: Consider the following superclass and subclass. Which of the following new subclasses would be
appropriate to add to the hierarchy? Select two answers.

A. Mexico
B. Canada
C. Texas
D. California
E. Asia

Response:

AP Exam Prep

Question: When designing classes, what are some of the reasons to use inheritance?

Response:

CSA 1
Extra Practice

Do This: Adding more methods to our classes allows us to add more functionality and behaviors to objects.
Let’s add more functionality to the PatternPainter class:

1. Make a list of three pattern designs that would be useful to add to the PatternPainter class.
2. For each method in your list, do the following:
a. Give it a name.
b. Give it a description.
3. Write a method in Java for one of the three methods you described. Before writing the method, use
the blank grid below to design your pattern.

Pattern 1:

Pattern 2:

Pattern 3:

Design Method Code

CSA 2
Object-Oriented Programming ('22-'23)
BackgroundPainter
Resources
Name(s)__________________________________________ Period ______ Date ___________________

U1L14 Extra Practice - BackgroundPainter

Check for Understanding

Question: Which of the following class headers represents the most appropriate inheritance relationship?

A. public class Taco extends Food


B. public class Door extends House
C. public class Animal extends Monkey
D. public class Flower extends Stem
E. public class Quadrilateral extends Triangle

Response:

AP Exam Prep

Question: Consider the following statement:

Extending a subclass from a superclass creates an "is-a" relationship between a subclass and a superclass.

Explain this statement in your own words. Use enough detail that someone unfamiliar with the concept would
be able to understand.

Response:

CSA 1
Extra Practice

Just like the PatternPainter and BackgroundPainter working together to paint an entire scene, programs
often work together to accomplish parts of a larger task. Think of a task that you do often that requires at
least three different but related objects to complete. Once you have an idea, create an inheritance hierarchy
flowchart. Next, describe the job done by each object and how they work together to complete the task.

Inheritance Hierarchy

Task Description

CSA 2
Object-Oriented Programming ('22-'23)
Open Source Code
Resources
Unit 1 Lesson 15

Name(s)_______________________________________________ Period ______ Date ___________________

Exploring Open Source Code

Directions
Choose one of the open source code examples to review.

Begin by reading through and tracing the code, then answer the questions and write a short summary of what you think
the code does. As you trace the code, be sure to add notes.

Be sure to identify the line or lines you are describing when responding to the prompts.

Each group should have at least one recorder and one speaker who will share the results.
Harmonica App
The open source code sample below was written for the Harmonica app. This code snippet is used to translate
notations to numerical Harmonica notations.

Describe how each line of code works.

Code Notes

1 private void toggle() {

2 if (mVisible) {

3 hide();

4 }

5 else {

6 show();

7 }

8 }

9 private void hide() {

10 ActionBar actionBar = getSupportActionBar();

11 if (actionBar != null) {

12 actionBar.hide();

13 }

14 mControlsView.setVisibility(View.GONE);

15 mVisible = false;

2
Evernote App
The open source code sample below was written for the Evernote app. This code snippet is used to write notes.

Describe how each line of code works.

Code Notes

1 public class App extends Application {

2 private AppComponent mAppComponent;

3 public void onCreate() {

4 super.onCreate();

5 initializeInjector();

6 buildEverNoteSession();

7 }

8 private void buildEverNoteSession() {

9 EvernoteSession.EvernoteService service;

10 if (BuildConfig.DEBUG)

service =
11
EvernoteSession.EvernoteService.SANDBOX;

12 else

service = new
13
EvernoteSession.Builder(this)

14 .setEvernoteService(service)

15 .setSupportAppLinkedNotebooks(false)

.build(BuildConfig.EVER_NOTE_KEY,
16
BuildConfig.EVER_NOTE_SECRET)

17 .asSingleton();

18 }

3
Minecraft's Brigadier
The open source code sample below was written for Minecraft’s Brigadier. This code snippet is used to allow single
quotes in strings for the Brigadier command parser and dispatcher.

Describe how each line of code works.

Code Notes

public String readStringUntil(char terminator)


1
throws CommandSyntaxException {

final StringBuilder result =


2
new StringBuilder();

3 boolean escaped = false;

4 while (canRead()) {

5 final char c = read();

6 if (escaped) {

if (c == SYNTAX_QUOTE ||
7
c == SYNTAX_ESCAPE) {

if (c == terminator ||
8
c == SYNTAX_ESCAPE) {

9 result.append(c);

10 escaped = false;

11 }

12 else {

13 }

14 else if (c == SYNTAX_ESCAPE) {

15 escaped = true;

16 }

17 else if (c == SYNTAX_QUOTE) {

4
18 }

19 else if (c == terminator) {

20 return result.toString();

21 }

22 else {

23 result.append(c)

24 }

5
Java 2D API
The open source code sample below was written for Java 2D API, which is an advanced graphics package added to
Java. This code snippet shows how Graphics2D adds more uniform support for manipulations of text, line, and
two-dimensional shapes.

Describe how each line of code works.

Code Notes

1 public class Example01 extends Frame {

2 public static void main(String args[]) {

3 new Example01();

4 }

5 public Example01() {

6 super("Java 2D Example01");

7 setSize(400,300);

8 setVisible(true);

9 addWindowListener(new WindowAdapter()

10 { public void windowClosing(WindowEvent e)

11 { dispose(); System.exit(0); }

12 }

13 );

14 }

15 public void paint(Graphics g) {

16 g.setColor(Color.red);

17 g.drawRect(50,50,200,200);

6
18 Graphics2D g2d = (Graphics2D)g;

19 g2d.setColor(Color.blue);

g2d.drawRect(75,75,300,200);
20

21 }

22 }

23 result.append(c)

24 }

7
Exploring Open Source Code
Answer the following prompts about the open source code you chose to review.

List the vocabulary words or concepts you recognize.

Write a short summary of what you think is happening in the program.

If this was your code and you were sending it for a code review, what would you say?

8
Name(s)__________________________________________ Period ______ Date ___________________

U1L15 Extra Practice - Open Source Code

Check for Understanding

Question: Which one of the characteristics of software engineers do you most identify with? Why do you
connect most with that characteristic?

Response:

AP Exam Prep

Question: Someone left a bunch of paint buckets in The Neighborhood and we need the Painter to remove
all the paint in the quickest manner. What control structure do you need to use?

I. if statement
II. if-else statement
III. while loop

a. I only
b. II only
c. III only
d. I and III only
e. I, III, III

Response:

CSA 1
Extra Practice

Do This: Write the definition or draw a picture that best describes the following vocabulary term: conditional,
method, inheritance, and code review.

CSA 2
CSA Unit 1 Study Guide

Unit 1: Object-Oriented Programming


This unit exposes students to object-oriented programming principles as they explore The Neighborhood.
Students learn fundamental Java concepts as they navigate and interact with The Neighborhood with Painter
objects and create new types of Painters to expand the capabilities of their programs. Students practice
predicting the outcome of program code and use their Painter objects with conditional statements, while
loops, and Boolean expressions to navigate mazes and create drawings. While students work with the
Painter, they practice identifying syntax and logic errors to explain why code segments will not compile or
work as intended. Additionally, students learn to document program code using comments to describe the
behavior of specific code segments. Throughout this unit, students discover their identity as software engineers
and use debugging strategies and code reviews to improve their programming skills.

Objectives
By the end of this unit, students will be able to . . .

● Relate characteristics of a software engineer to personal skills and identity

● Use correct Java syntax

● Explain the relationship between a class and an object

● Explain the purpose and functionality of inheritance

● Write subclasses that extend an existing class

● Differentiate between calling and writing a method

● Implement algorithms using if and if-else statements and while loops

● Write clear and readable code using methods, control structures, and comments

● Improve a program through iterative development based on feedback

Java Concepts
In this unit, students learn about the following concepts . . .

● Java syntax and program formatting ● Using an integrated development environment (IDE)

● Classes and objects ● Inheritance

● Calling and writing methods ● Identifying syntax and logic errors

● Debugging strategies ● Boolean values

● Methods that return Boolean values ● Selection (if and if-else) and iteration (while)

● NOT ( ! ) logical operator ● Decomposition and pseudocode

● Edge cases ● Open source code


CSA Unit 1 Study Guide

Syntax
The following outlines the new syntax that is introduced in each lesson.

Lesson 2: Java Lab

public class MyNeighborhood {


. . .
}

public static void main(String[] args) {


. . .
}

myPainter.move();

Lesson 3: The Neighborhood

Painter myPainter = new Painter();

Lesson 4: Navigating and Painting


Painter Class Methods

move()

turnLeft()

takePaint()

paint(String color)
CSA Unit 1 Study Guide

Lesson 5: One-Way Selection Statements

if (condition) {
. . .
}

Painter Class Methods

isOnPaint()

isOnBucket()

canMove()

Lesson 6: PainterPlus

public class PainterPlus extends Painter {


. . .
}

public PainterPlus() {
. . .
}

super();

Lesson 7: Writing Methods

public void turnRight() {


. . .
}

Lesson 8: Code Reviews

// A single-line comment

/*
* A multi-line comment
*/
CSA Unit 1 Study Guide

Lesson 9: Loops

while (condition) {
. . .
}

Painter Class Methods

takeAllPaint()

hasPaint()

Lesson 10: Two-Way Selection Statements

if (condition) {
. . .
}
else {
. . .
}

!condition

Painter Class Methods

isFacingNorth()

isFacingEast()

isFacingWest()

isFacingSouth()
CSA Unit 1 Study Guide

Lesson 11: Debugging Strategies

System.out.print();

System.out.println();

Painter Class Methods

getMyPaint()

getDirection()

getX()

getY()
Object-Oriented Programming ('22-'23)
Asphalt Art Project – Day 1
Resources
Name(s)_______________________________________________ Period ______ Date ___________________

Asphalt Art Project Planning Guide

Project Description
You have been chosen to create asphalt art to revitalize The Neighborhood and bring the community together. Cities
implement asphalt art to improve public safety, inspire their residents and visitors, and brighten communities. Your goal
is to improve The Neighborhood using asphalt art with the help of the Painter.

Program Requirements

Use your knowledge of object-oriented programming, algorithms, and decomposition to create asphalt art:

● Create a new subclass – Develop a new class that extends PainterPlus with a one or more additional
behaviors

● Use an existing class – Use PainterPlus, PatternPainter, and/or BackgroundPainter and add additional
behaviors to the class as needed

Project Steps

Day 1 Steps

● Brainstorm ideas for your asphalt art design

● Draw a quick sketch of your asphalt art design

● Decompose the problem to identify the classes and methods you will need to implement

Day 2 Steps

● Develop your program using the pseudocode you wrote and sketch you created

● Participate in a code review to give and receive feedback

Day 3 Steps

● Self-assess your work using the program requirements and rubric

● Finalize your program using the feedback you received and your self-assessment

● Showcase your work!


Step 1: Sketch your asphalt art design.
Choose one of the available grid sizes for your design.

8 x 8 Grid

2
12 x 12 Grid

3
16 x 16 Grid

4
32 x 32 Grid

5
Step 2: Create a UML diagram for your new subclass.

6
Step 3: Write pseudocode for the methods you will write.

Pseudocode for __________________________________________ method

Pseudocode for __________________________________________ method

7
Day 1 Reflection
What did you accomplish today?

What do you need to do next?

What obstacles are in your way?

Software Engineers
How are you being a problem-solver while you are working on your project?

How are you being creative while you are working on your project?

8
Day 2 Reflection
What did you accomplish today?

What do you need to do next?

What obstacles are in your way?

9
End of Project Reflection
Describe your project.

What are two things about your project that you are proud of?

Describe something you would improve or do differently if you had an opportunity to change something about
your project.

On a scale of 1 to 4 (4 being the highest), how would you rate your project?

Why do you give it that rating?

10
Rubric

Category Extensive Evidence Convincing Evidence Limited Evidence No Evidence

Existing Class Uses one of the existing Uses one of the existing Uses one of the existing Does not use one of the
classes and its methods to classes and its methods to classes and its methods to existing classes.
create one or more create one or more create one component of
components of their asphalt components of their asphalt their asphalt art design.
art design. art design.

AND

Adds a new method to one of


the existing classes and uses
it to create one or more
components of their asphalt
art design.

New Subclass Develops a new subclass Develops a new subclass Develops a new subclass Does not develop a new
that extends PainterPlus to that extends PainterPlus in that extends PainterPlus subclass.
provide more than one a new way that provides one but does not create a new
additional behavior that the additional behavior that the behavior for this subclass.
other classes do not have. other classes do not have.
OR
AND AND
Develops a new subclass
Uses the new subclass and Uses the new subclass and that extends PainterPlus to
methods to create one or method to create one or provide a new behavior that
more components of their more components of their the other classes do not
asphalt art design. asphalt art design. have. Does not use the new
subclass and method to
create one or more
components of their asphalt
art design.

11
Object-Oriented Programming ('22-'23)
FRQ Practice
Resources
Unit 1 Lesson 19

Name(s)_______________________________________________ Period ______ Date ___________________

SpiralPainter FRQ

Planning
Do This: Annotate the question below using the following format. If you have highlighters or colored pencils, use those
to highlight different sections. If you only have a pencil or pen, follow the instructions to circle, star, box, and underline.

*blue or star* methods that will need to be implemented

orange or box parameters or information needed to perform an action to produce a result

pink or underline words or concepts you are not sure of

This question involves the implementation of a painter that draws spirals


represented by the SpiralPainter class, a subclass of PainterPlus.

The SpiralPainter class provides a constructor and the following methods:

● paintL, which draws an L-shape pattern in the color of the parameter

● paintSpiral, which draws a spiral pattern in the color of the parameter

Write the complete SpiralPainter class, including the constructor and any
required methods. Your implementation must meet all specifications and
conform to the example.

Wait for instructions from your teacher before continuing to the next step.

1
Around the World
Travel from station to station. You do not need to complete them in order. At Stations B and C, use the pseudocode table below to create your plan before
writing the actual code on the following page.

Pseudocode

At Stations B and C, follow the instructions and use the manipulatives to create the requested shape. Use the space provided below to write out in pseudocode
the steps you used to create the shape.

SAMPLE: drawSquare(String color) Station B: paintL(String color) Station C: paintSpiral(String color)

Pseudocode Pseudocode Pseudocode

draw a square:
paint
move
turn left
paint
move
turn left
paint
move
turn left
paint
move
turn left

2
FRQ Written Response
Write the complete SpiralPainter class here.

STATION A

_____________________

Station A – Peer Signature

STATION B

_____________________

Station B – Peer Signature

STATION C

_____________________

Station C – Peer Signature

3
Reflection
Assess your solution using the Scoring Guidelines and provide brief responses (1-2 sentences each) to the following:

1. For which rows on the Scoring Guidelines did you get the full point?

2. What information did you highlight and/or annotate in the original Free Response Question that helped you get
the full point for these rows?

3. Which rows on the Scoring Guidelines are you still confused about?

4. If you were giving tips to other students completing this FRQ, what advice would you give them?

Rate your experience answering this Free Response Question by coloring in the stars.

I understood what the Free Response Question was asking me to do. ☆☆☆☆☆
I am confident I can tackle similar Free Response Questions. ☆☆☆☆☆
The materials covered in this unit prepared me for this Free Response Question. ☆☆☆☆☆
I'm looking forward to answering more Free Response Questions throughout the course. ☆☆☆☆☆

You might also like