AP Computer Science Assignments

Learn Java Programming
Supplemental, free, online textbook called Introduction to Programming Using Java
Java Cheat Sheet
Classes, Objects, & Constructors
AP Quick Reference Guide
Online Java Compiler
Java Examples
Arithmetic Operators
Digital Textbook
Visualize Java code execution

Feb 7

We're going to write 3 programs, and then write them again with changes. For Birthday1 you will need to enter your birthday as digits in this format-- 00/00/0000. For StringChecker1 you will need to write a complete sentence when prompted to enter a string. For ArrayCopier1 you will need to enter a starting number, an increment to jump, and the number of elements in the array.





Save your files in a folder called Changes. You will turn in your programs and a screenshot of the output to our Google Classroom.



Feb 6

ThreeSum

You are going to write a java program that when given an array of integers and a value, determine if there are any three integers in the array whose sum equals the given value. Write the ThreeSum code, javac it, and run it. Make a screen shot of the output and put it on a Google Doc. You will turn in ThreeSum java file and the screenshot to our Google Classroom





Feb 5

for Loops

A for loop provides a more concrete framework for common loop use cases. One kind of loop is no better or worse than another, but the type of loop you choose can affect the readability of your program.
In the previous activity, you used variables to track how many times a loop had executed. In a for loop, the variable that does this is called a “control variable” and is explicitly included in the syntax of the loop. In the loop shown below, the loop control variable is i.

The two programs below create identical output. The one on the left uses a while loop, and the one on the right uses a for loop.



Experiment with the code below. Modify the for loop header by changing the initialization, condition, and/or modifier so that the loop prints the values from 0 to positive infinity.



Here is a program that prompts for user input using the Boolean expression of the for loop header. Note how the loop control variable i is not used in there or in the loop body. As you review the program, think about how the programmer could have chosen a better algorithm.





The decrement operator is --. The statement i--; results in i getting the value i-1. Modify the code that follows so that it prints the integers from 10 down to 1 inclusive, in strictly decreasing order.





Save your files in a folder called 2.4.2. You will turn in your programs and a screenshot of the output to our Google Classroom.



Feb 4

We're going to work with 3 files that will track a robot on Mars

MarsRobot is a class files and will not run, but the MarsApplication and the MarsApp files will run after you javac all the files.





Save your files in a folder called MarsRobot. You will turn in your programs and a screenshot of the output to our Google Classroom.



Jan 29

Iteration (Looping)

In a previous lesson, you learned how control can be disrupted through the use of conditional statements. The second way in which the flow of control can be disrupted is through iteration. Iteration is another building block of algorithms and allows for the repetition of a statement or block of statements for a set number of times or until the desired state is reached.

Building off of the knowledge you gained as you explored conditionals and Boolean logic, this unit covers two ways of accomplishing iteration using while and for loops. In addition, standard algorithms that use iteration are introduced. As with conditional statements, iterative statements can be nested to form more complex blocks of code to solve more difficult problems. In this unit, you will begin to analyze the run-times of various algorithms to compare them.





Save your files in a folder called 2.4.1. You will turn in your programs and a screenshot of the output to our Google Classroom.



Jan 27

In this lesson, you will learn about arithmetic calculations in Java. There are 4 coding exercises.



Save your files in a folder called U1_L4. You will turn in your programs and a screenshot of the output to our Google Classroom.



Jan 24

Escape Room

You are going to make an escape room game. Download the Escape Room zip file to your java folder, open it and it will become your EscapeRoom Folder. Write the Escape Room code and save it in the EscapeRoom folder, javac it, and run it. Play the game, Make some screen shots and put them on a Google Doc. You will turn in EscapeRoom java file and a screenshot of the output to our Google Classroom





Jan 22

Let Them Eat Cake. Part 2

We'll continue the cake theme, but these must go into a folder called Cake2. Some of them have the same name as other files you have written, but they do different things, so they must be in a seperate folder.





Jan 21

Let Them Eat Cake

Throughout this chapter, you may have noticed some discussions and comments related to objects. We'll watch a video to learn about what they are and how object-oriented programming works.

Origami Cake

To further explore the difference between a class (a design) and an object (the instance), you will create a cake by following a recipe, but not a flour and egg cake, an origami cake. As you create your cake, think about how you are instantiating a cake from the instructions. Let's try an Origami Cake!







Now type these 4 programs, compile and run them, and screenshot the results. Save them in a folder called Cake.You will only be able to run the CakeRunner files, as the othes are just classes that the CakeRunner files use, but javac all but the origamiCake file.



You will turn in your programs and a screenshot of the output to our Google Classroom.



Jan 15

This lesson introduces new data types, spends more time with variables, and teaches how to store numbers instead of Strings.



Data Types Video



Now type these 3 programs, compile and run them, and screenshot the results.

Save your files in a folder called DataTypes. You will turn in your programs and a screenshot of the output to our Google Classroom.



Jan 14

Getting started with java. You will first need to create a folder inside your documents folder called java and then another folder called inside the java folder. Next, open Terminal and a new document and type in the following code:



The name of the java file must match the class name. When saving the file, save it using the class name and add .java to the end of the filename.

Save your file as HelloWorld.java in your HelloWorld folder

type in cd Documents/java/HelloWorld

Now type ls

You should see your HelloWorld.java file

Every line of code that runs in Java must be inside a class. In our example, we named the class HelloWorld. A class should always start with an uppercase first letter.

Note: Java is case-sensitive: MyClass and myclass have different meanings.

The main Method

The main method is required and you will see this in every Java program:

public static void main (String[] args)

Any code inside the main method will be executed.

Java files need to be compiled before they will run, so type in javac HelloWorld.java

If there are no errors, you should see this



Next, type java HelloWorld

You should see this



You've just created your first java program!

System.out.println()

The println() method, short for "print line", is used to print a value to the screen and then adds a line break. print() also prints whatever is inside the () to the screen but does not add a line break.

You should note that the contents of the () are also in " " . This means that what is inside the quotes will print exactly to the screen.

This is called String literal, and we will see that we can put other things inside the () that will do math, call functions and more.

Each code statement must end with a semicolon ;

The /* and // signify comments. This is code that does not run, but it lets others who read your code know what you had in mind when you wrote it.

The curly braces {} mark the beginning and the end of a block of code and they always come in pairs.


Now do the same with these 3 programs



You will turn in your programs and a screenshot of the output to our Google Classroom.



Jan 13

Open your Documents folder and create a new folder called java. You will be making a new folder for every assignment. You will need get into that folder to compile a run your files. Open your text editing program and pin it to the dock or taskbar. Open the terminal and pin it to the dock or taskbar. Open Chrome and pin it to the dock or taskbar.


What is Java?

Java is a popular programming language, created in 1995.

It is owned by Oracle, and more than 3 billion devices run Java.

It is used for:


Why Use Java?


What is Java technology and why do I need it?

Java is a programming language and computing platform first released by Sun Microsystems in 1995. It has evolved from humble beginnings to power a large share of today’s digital world, by providing the reliable platform upon which many services and applications are built. New, innovative products and digital services designed for the future continue to rely on Java, as well.

While most modern Java applications combine the Java runtime and application together, there are still many applications and even some websites that will not function unless you have a desktop Java installed. Java.com, this website, is intended for consumers who may still require Java for their desktop applications – specifically applications targeting Java 8. Developers as well as users that would like to learn Java programming should visit the dev.java website instead and business users should visit oracle.com/java for more information.


Top 10 Reasons to Learn Java in 2025

You will turn in your programs and a screenshot of the output to our Google Classroom.

Click here for the course syllabus. Save it in your Documents folder.

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.