Please enable JavaScript to use CodeHS

AP Computer Science A (Mocha)

Description

In this lesson, we learn about methods in Java. Methods allow us to break down our code into reusable parts, avoid using repeated code, and simplify our code.

Objective

Students will be able to…

  • Explain the purpose of methods
  • Create their own methods
  • Utilize their methods to solve simple problems
Description

In this lesson, we continue to build our understanding of methods and introduced to parameters. Parameter are inputs to methods.

If methods are boxes, then parameters are inputs to our boxes (what goes inside the box).

Parameters allow us to generalize our methods so that they can solve more than one specific instance of a problem, and instead can solve different versions of the same problem (for example, add 10 to any given number).

Objective

Students will be able to…

  • Write general methods that take parameters as inputs.
  • Use parameters to generalize their methods to solve general problems.
  • Identify and fix improper parameter names in Java.
Description

Think of a method like assigning a task. A return value is giving you the completed work.
This allows you to write methods that do some work for you and send back the result.
Parameters are like inputs into the function, and the return value is output.

Objective

Students will be able to…

  • Explain the purpose of returning a value from a method.
  • Create methods that return values.
  • Create programs that call methods with return values and store the result for later use.
Description

Comments are an important part of programming style. Programs are usually written by teams of people and maintained for many years. Others need to be able to read your code and understand what is going on.

This lesson introduces Javadocs, which are a standard, agreed upon way of commenting Java code. There is a tool, also called Javadoc, that is able to read Javadoc comments and create clean, clear documentation for your Java programs. Javadoc refers to both the tool and the style of commenting Java code.

From now on, we will be writing Javadoc comments in our programs.

Objective

Students will be able to…

  • Explain why commenting your code is important
  • Identify Javadoc style comments
  • Analyze a given program for proper documentation
  • Compare and contrast programs with good documentation against programs with poor documentation
  • Create Javadoc comments to document their methods
Description

Strings come prepackaged with several methods that we can use to help us do cool things! In this lesson we learn how to find and read documentation about how to use the String methods, and we’ll write several programs that call methods on Strings in order to get information about them and manipulate them to form new Strings.

Objective

Students will be able to…

  • Read documentation for how to use the methods of the String class
    • Either in the DOCS tab in the CodeHS editor, or elsewhere online
  • Call methods on String objects to get information about the String, such as length or characters at given indices
  • Utilize String methods to create programs that manipulate Strings in interesting ways
Description

In this lesson, we’ll examine the similarities and differences between the String class and the char primitive type. Strings are simply sequences of chars.

We also learn that all char values have a corresponding int value. chars are actually stored as numbers! For example, 65 corresponds to ‘A’, 66 corresponds to ‘B’, and so on. We’ll learn about special characters like tabs, quotes, and new lines, and how to store and print these special characters using escape sequences like ‘\n’

Lastly, we learn about the Character class. The Character class provides several useful methods that allow us to manipulate and get information about char values.

Objective

Students will be able to…

  • Explain the relationship between Strings and chars
  • Explain the difference between the primitive type char and the class Character
  • Convert char values to int values using casting
  • Convert int values to char values using casting
  • Print out special characters like quotes and new lines using escape sequence chars (such as ‘\n’ and ‘\”’)
  • Utilize the static methods of the Character class to manipulate get information about char values
Description

All programs have bugs at some point in the development process. Bugs are ok! They show us exactly where the problems are in our code and give us helpful information so that we can fix these problems.

When there is a bug in your program, Java will actually provide helpful information about where the bug is and what kind of bug is occurring by throwing an Exception. In this lesson we’ll learn about the different kinds of exceptions and what they mean. That way, when we try running our programs and see exceptions, we’ll know how to use that information to debug our programs!

Objective

Students will be able to…

  • Explain the difference between a compile time error and a runtime error
  • Explain when exceptions are thrown
  • Explain the purpose of exceptions
  • Utilize exceptions to find and fix bugs in programs
Description

We’ve learned about writing our own methods that take in parameters and return return values. We’ve learned about the relationship between Strings and characters. We’ve learned about using the methods of the String class and the Character class. We’ve learned about looping through the characters of a String using a for loop. It’s time to put that all together to write some methods that perform some advanced manipulation of Strings.

Objective

Students will be able to…

  • Synthesize the skills and concepts from learned in this unit to write methods that perform advanced manipulations on Strings and chars
  • Write out a pseudocode algorithm for a solution before diving in and writing Java code
  • Implement pseudocode solutions in Java
  • Debug their code
  • Explain the common idiom for manipulating a String:
    • Looping over each character
    • Perform some action based on each character
    • Append the resulting character to a result String that starts off as an empty String
    • Return the result String
Description

This lesson is a summative assessment of the unit’s learning objectives.

Objective

Assess student achievement of the learning goals of the unit