0% found this document useful (0 votes)
16 views36 pages

00 - Unit 1 Guide

Uploaded by

Agrima Singh
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)
16 views36 pages

00 - Unit 1 Guide

Uploaded by

Agrima Singh
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/ 36

CSA Unit 1 Guide

Lesson 2: Java Lab


Components of a Java File

Term Definition Example / Picture / Code

It’s just a collection of programming


source code
commands

Syntax and Syntax Errors

Term Definition Example / Picture / Code

Syntax is the rules for how a


syntax programmer must write code for a
computer to understand.

Consists of the class (keyword) and


class header
the name of the class

Fill in the missing components of the main method.

public static Void main ( String [ ] args)


1
CSA Unit 1 Guide

Term Definition Example / Picture / Code

A text note to explain or annotate the


comment code and is ignored when the
program is run.

What do you think it means for a program to have a syntax error?

When something doesn’t follow the language or pattern that the rest of the code follows.

Term Definition Example / Picture / Code

A syntax error is a mistake in the


syntax error code that doesn’t follow a
programming language’s syntax.

2
CSA Unit 1 Guide

Reflection
Question of the Day: What are some of the primary components of a Java program?

A class, a class header, and the rest of the source code.

How did you use your software engineering skills and characteristics to find and fix syntax errors today?

I used my problem solving skills to find syntax errors as it was hard at first, but I didn’t give up and was
able to fix multiple syntax errors.

3
CSA Unit 1 Guide
Lesson 3: Classes and Objects
Defining a Blueprint
Draw a house in the space provided below. Don't worry about making it perfect!

Video Notes: Object-Oriented Programming


In your own words, describe object-oriented programming.

An approach to creating and using models of physical or imagined objects

Follow along with the video and write your own class here.

Public class MyFirstClass {


}

4
CSA Unit 1 Guide

Term Definition Example / Picture / Code

An approach to creating and using


object-oriented
models of physical or imagined
programming
objects.

A program defined blueprint from


class
which objects are created.

object An object is an instance of a class

Consider your own neighborhood and the things that are in it. If you were to represent your neighborhood as a
collection of classes, what classes would your neighborhood consist of?

A painter that can paint stuff, a store where you can buy things, trees, parks. The house could be a class
too.

The Painter Class

Painter the name of the class

xLocation
yLocation These represent the Painter's
direction Characteristics of an object
remainingPaint ____________________________

5
CSA Unit 1 Guide
turnLeft()
move() These represent the Painter's
paint("color") The actions that an object can perform
takePaint() ____________________________

Term Definition Example / Picture / Code

Attribute is the characteristics of an


attribute
object

behavior Represent what an object can do.

Reflection
Question of the Day: What is object-oriented programming?

An approach to creating and using models of physical or imagined objects.

Learner is one of our four characteristics of a software engineer. How did you engage your curiosity as a
learner throughout this class period?

6
CSA Unit 1 Guide

I was able to absorb the new information I’d learned to help me finish the lesson.

7
CSA Unit 1 Guide
Lesson 4: Instantiating Objects
Video Notes: Creating Objects
How is memory in a computer like the land a house is built on?

To build a house we need land, to build an object we need memory.

What is the relationship between a Painter object and the Painter class?

Painter object is instantiated in the painter class.

Investigating the Painter


Fill in the missing components to instantiate a Painter object.

Painter alice = new Painter ();

8
CSA Unit 1 Guide

Term Definition Example / Picture / Code

To call the constructor to create an


instantiate
object

A block of code that has the same


constructor name as the class and tells the
computer how to create a new object

Reflection
Question of the Day: How do I create objects from a class?

By instantiating them and calling a constructor to build them

Now that you know about classes and objects in Java, what type of program are you looking forward to
creating? What objects would you represent in your program?

I want to create a program where you can paint many different things. I would have a painter in it, and the
objects I’d like to paint such as a house and more.

9
CSA Unit 1 Guide
Lesson 5: Methods
Giving Instructions
Write your instructions for the delivery driver here.

Move 4 squares to the right, turn right, move 4 squares down

Write your instructions for the bus driver here.

Head down on 1st street until you reach 5th street, turn left, move 4 squares until u reach 5th street and 5th
avenue and move 5 units Move 2 squares to the left, turn right, and move 3 up

Calling Methods in Java

Term Definition Example / Picture / Code

A method is a named set of turnLeft ()


method
instructions to perform a task. move ()

Think of an object you might represent in a program, like a pet or a song. What behaviors would this object
have? What methods would the class have to represent these behaviors?

10
CSA Unit 1 Guide

I would probably use turnLeft and move and paint a lot because id want to create a painting.

Video Notes: Calling Methods

Three Things You Learned Two Interesting Ideas

1 Argument is a value passed to the method when 1 U can make things other than a painter
the method is called

2 Parameter is like the quantitive amount of 2 We have so many methods to do amazing


times an object does something things

3 Dot operator is used to call a method One Question or Wonder

Term Definition Example / Picture / Code

It’s the dot in the code “Alice.move


dot operator Used to call a method in a class
();”

11
CSA Unit 1 Guide

Reflection
Question of the Day: How do I give instructions to an object in Java?

You use the dot

How is giving instructions to a computer similar to giving instructions to a person? How is it different?

It’s similar because both of them have to deal with someone who needs guidance

12
CSA Unit 1 Guide
Lesson 6: Methods with Parameters
Instructions with Inputs
Consider our delivery driver from earlier. Before we could give our instructions for how to reach the destination,
what information did we need to know first?

The name of the delivery driver, which class it was in (public or private), the location ur at initially, and the
place you need to go to.

Methods with Parameters

Term Definition Example / Picture / Code

Defines the type of value to receive


parameter when a method or constructor is
called.

An argument is the specific value


argument provided when a method or
constructor is called.

The value we give when we call the


paint () method is a string literal,
string literal
which is a sequence of characters
enclosed in quotation marks (“ “).

13
CSA Unit 1 Guide

Reflection
Question of the Day: How can I give a specific value for a method to use?

By adding “” and parentheses and a dot.

Based on what you now know about the Painter class, what are some things you might want to do or create
in The Neighborhood?

I want to make a painter move all over the space provided

14
CSA Unit 1 Guide
Lesson 7: Loops
Components of an Algorithm
What do you know or remember about algorithms?

It’s like a quantitive number of rules that have a specific motive

Term Definition Example / Picture / Code

A finite set of instructions that


algorithm
accomplish a task.

Sequencing

____________________________________

putting steps in order

Selection

____________________________________

deciding which steps to do next

Iteration

____________________________________

doing some steps over and over

15
CSA Unit 1 Guide
What are some scenarios that you can think of where you would want to know if something is either true or
false? Why might you need to know that?

Someone’s age (something’s are illegal), if someone’s sick (they might be pretending so they don’t have to
go to school), the weather.

Video Notes: while Loops


Follow along with the video and label the following while loop.

while (checkForPlate()) {
putAwayPlate();
}

Term Definition Example / Picture / Code

A control structure that repeatedly


iteration statement
executes a block of code

16
CSA Unit 1 Guide

The condition of a while loop results


in a Boolean value (either true or
condition
false) and determines whether or not
to execute the block of code.

Reflection
Question of the Day: How can the problem-solving process help me plan and implement an algorithm?

It helps you understand what you’re supposed to do, helps you plan, and make sure that you’re fully
confident in your code

What parts of this lesson made you feel confident in your work? What would you like to practice some more?

The while loop was really fun to use and made it so much simpler to just finish all the work. I had to put
less effort.

17
CSA Unit 1 Guide
Lesson 8: Inheritance
Object-Oriented Programming Concept Map
What is object-oriented programming?

Create a concept map that illustrates the concepts and their relationships in response to this prompt.

18
CSA Unit 1 Guide

Video Notes: Inheritance


What is the relationship between ClubOfficer and ClubMember?

ClubMember class is a superclass and a ClubOfficer class is a subclass.

Annotate this line of code using the vocabulary from the video.

public class ClubOfficer extends ClubMember

Inheritance

Term Definition Example / Picture / Code

A programming principle where a


inheritance subclass inherits the attributes and
behaviors of a superclass.

A class that can be extended to


superclass
create subclasses.

A class that extends a super class


subclass and inherits its attributes and
behaviors.

19
CSA Unit 1 Guide

Writing a Subclass
Our Java programs now consist of two types of classes.

Dog.java The class that

public class Dog extends Pet { represents_____________________

} an object and contains its

Attributes_______________ and

________behaviors________.

Runner.java The _______________tester class, which is

public class Runner { the class that contains the


public static void main(String[] args) {
____________________________main
}
} method and from where the program starts

________________running.

What happened when you called Painter class methods? Why do you think this happened?

It didn’t work because I believe it needed the painter plus object rather than the painter object.

20
CSA Unit 1 Guide

Reflection
Question of the Day: Why would I use inheritance?

It makes our code more organized.

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?

We could represent snakes and ladders through creating a subclass for the snakes, a subclass for the
ladder and a subclass for the board.

21
CSA Unit 1 Guide
Lesson 9: Writing Methods
Video Notes: Writing a Method
Annotate this method using the vocabulary from the video.

public void square() {


forward();
turnLeft();
forward();
turnLeft();
forward();
turnLeft();
forward();
turnLeft();
}

Term Definition Example / Picture / Code

Consists of a name and parameter


method signature
list

Can be a number, Boolean and


more returned by a function or the
return type
result of the evaluation of an
expression.,

22
CSA Unit 1 Guide

The return value can be a number,


return
Boolean or a string.

Term Definition Example / Picture / Code

Indicates that a method has no


void
return value

Reflection
Question of the Day: How do I write methods for the behaviors I want an object to have?

You can write public void *command you want* and then write the methods that will allow you to use that
command.

What other methods would you want to add to the PainterPlus class?

Probably coloring everything all at once.

23
CSA Unit 1 Guide
Lesson 10: Programming Style and Feedback
Software Engineers
How have you grown as a software engineer so far in this unit?

I’ve become more collaborative and love to bounce ideas off my fellow classmates as it helps us get the
best results in a productive time frame.

Style and Documentation

Term Definition Example / Picture / Code

Use consistent and clear indentation


A set of guidelines and best Use names that explain themselves
programming style practices for formatting program ‘Add comments to explain the
code. purpose of a method and to clarify
code that needs explanation

Documentation refers to written


documentation descriptions of the purpose and
functionality of code.

A commit is an operation which


saves the latest changes of the code
commit
and represents a snapshot of a
project.

Why would we want to commit our code?

24
CSA Unit 1 Guide

So that we don’t waste time rewriting code we already know and can use our time efficiently.

Guidelines for Programming Style and Comments

TAG:

T: tell them something you like about their code

A: Ask them something about the code

G: Give a suggestion for improvement.

Video Notes: Software Engineering – Code Reviews

Three Things You Learned Two Interesting Ideas

1 Code reviews are important because they ensure 1 They make the person writing the code a better
the success of your code and your products. person as well

2 Look for common errors 2 Code review helps bring in many different
perspectives.

3 Learn more about the algorithm One Question or Wonder


How do you work well with people who share a
completely different perspective than you

Term Definition Example / Picture / Code

25
CSA Unit 1 Guide

The process of examining code and


providing feedback to improve the
code review
quality and functionality of the
program.

Reflection
Question of the Day: How do software engineers use feedback from peers?

They use it to make their code neater, faster, and to just get a different perspective from their coworkers.

What is a skill you are currently practicing that you would like feedback on?

Writing subclasses and creating algorithms.

26
CSA Unit 1 Guide
Lesson 11: Selection Statements
Components of an Algorithm
How do you think we would implement selection in Java?

There are certain codes that provide the same results, we might implement selection in terms of what
keeps our code looking clean and not messy.

Video Notes: Conditional Statements


Write a scenario that you could check using a conditional statement.

U get a driver’s license if you’re of age.

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

If (age>= 16) {
Obtain license ();
}

Term Definition Example / Picture / Code

A selection statement is a statement


selection statement that only executes when a condition
is true.

27
CSA Unit 1 Guide

Reflection
Question of the Day: How can I write algorithms using sequencing, selection, and iteration in Java?

U can use the if function

What parts of this lesson made you feel confident in your work? What would you like to practice some more?

Probably being able to review my work and using selection made me confident in my work. I’d like to
practice more of subclasses tho.

28
CSA Unit 1 Guide
Lesson 12: Debugging Strategies
Bugs and Debugging
What do you know or remember about bugs and debugging?

I think bugs are like problems with your code and debugging is probably trying to fix that problem.

Variables and Printing

Term Definition Example / Picture / Code

A variable is a container that stores


variable
a value in memory

A data type is the format of the data


data type
that can be assigned to a variable

Declaration is giving a name and


declaration
data type to a variable.

29
CSA Unit 1 Guide

Video Notes: Printing in Java


How can printing to the console be used as a debugging technique?

Whatever is inside the parenthesis is printed to the console, so we can see what we’re doing wrong if it
doesn’t come out the way it’s supposed to.

Write a sample print statement that prints "Fido's age: " followed by the age stored in the fido object.

Dog fido = new Dog(true)


Fido’s age: 16(true)

System.out.print(); The cursor stays on the current line after printing.

System.out.println(); The cursor moves to the next line after printing.

How might variables, the methods that return information about a Painter object, and printing be helpful when
we are writing our code?

They can tell us what’s true and what’s false and help us decide what methods to use in order to get the
results that we’re working towards.

30
CSA Unit 1 Guide
Reflection
Question of the Day: How can I use the problem solving process to debug a program?

We can reflect on our code and look for common syntax errors in order to debug a program.

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

They provided me the information I needed on where my object was and it helped me write a code that
achieved the goals we wanted to accomplish.

31
CSA Unit 1 Guide

Lesson 13: Decomposition and Design


Solving Problems
Write an algorithm for the following scenario with your group.

Given a package of M&M's, how many of each color do you have?

Choose a color to start

Sort through the M&Ms and remove the selected color

And 1 to a variable associated with that color when removing the M&Ms

Developing Efficient Solutions

Term Definition Example / Picture / Code

decomposition The process of breaking a

What does it mean to you for something to be efficient?

I think it means when something is done FAST without wasting any time.

Term Definition Example / Picture / Code

32
CSA Unit 1 Guide

Redundant code is code that is


redundant code
unnecessary.

Getting the best outcome with the


efficient
least amount of waste

How can we make sure we are writing efficient code?

When something is repeated over and over, it’s not organized. So we can use methods to make
something do something over and over again.

Term Definition Example / Picture / Code

A plain language description of the


pseudocode
steps in an algorithm

33
CSA Unit 1 Guide
Reflection
Question of the Day: How can I write efficient code?

We can create a code for it in a subclass so we don’t have to repeat things over and over again.

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

In a school, there’s classes, and several of them but when you look at it from a bigger perspective the
school is also a subclass of a district which is a subclass of the education system.

34
CSA Unit 1 Guide

Lesson 14: Two-Way Selection Statements


Selection and Logic

Term Definition Example / Picture / Code

A logical operator is an operator that


logical operator
returns a Boolean value.

A two-way selection statement


specifies a block of code to execute
two-way selection
when the condition is true and a
statement
block of code to execute when the
condition is false.

Video Notes: Two-Way Selection and NOT

Three Things You Learned Two Interesting Ideas

1 “If-else statement” 1 The logical operator and the else branch perform
the same task.

2 Anatomy of an if-else statement 2 If-else statements give us options.

3 We can use a logical operator that returns a One Question or Wonder


Boolean value to get the same thing as an “if- How do we choose which one is more productive
else statement”

How can two-way selection statements and the NOT ( ! ) operator be useful in the algorithms we have
developed so far?

35
CSA Unit 1 Guide

When something is untrue, it provides an alternative statement rather than having to write long lines of
code that will make the Boolean value to be correct. It’s just really effective.

Reflection
Question of the Day: How can I check if a condition is NOT true or execute a separate block of code if the
condition is false?

You can use the exclamation mark as it will return to you a Boolean value which will tell you whether or not
a statement is true.

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?

I want to be more independent and rely on the slides a little bit less.

36

You might also like