Unit 1A Projects
From CS Awesome 2CC BY-NC-SA 4.0Original page
Java2 class periods2 exercises20 graded tests
Files
Unit 1A Projects
Each coding exercise has its own folder. Open its .java file and press Run to try it. Run Tests checks every graded exercise in this lesson at once.
These projects were created by Leigh Anne Fitz and Lisa Ferran to provide engaging, standards-aligned learning experiences for AP Computer Science A students. The autograding tests were designed by Kate McDonnell.
These projects are intended to promote curiosity, creativity, collaboration, and confidence as students begin their journey into computer science. We hope they make learning Java both challenging and enjoyable, and that they provide a strong foundation for the exciting topics that follow throughout the AP Computer Science A course.
Learning to program is much like learning a new language—you develop fluency by reading, writing, practicing, and creating. These projects are designed to help you move beyond simply memorizing Java syntax and instead develop the problem-solving and computational thinking skills that are essential to becoming a successful programmer.
Remember that mistakes are a natural part of programming. Every error message, failed test, and debugging session is an opportunity to deepen your understanding. Success in computer science comes not from writing perfect code the first time, but from learning how to analyze problems, experiment with solutions, and improve your work through persistence.
Throughout these projects, you will explore the foundational concepts introduced in Unit 1, including:
- Writing, compiling, and running Java programs
- Using primitive data types (int, double, and boolean)
- Declaring, initializing, and updating variables
- Evaluating arithmetic expressions and assignment statements
- Using Java operators correctly
- Calling methods and using parameters
- Working with the Java API and standard library classes such as Math and String
Each project is designed to reinforce these concepts through engaging, authentic programming experiences. Rather than completing isolated coding exercises, you will apply your knowledge to solve meaningful problems, debug code, and create programs that demonstrate your understanding. As the projects progress, you'll be encouraged to think critically, test your ideas, and refine your solutions—just as professional software developers do.
Scanner Reminders
The Scanner class is used to read input from the user.
To use the Scanner class, you must first import it at the top of your program with the following line of code. We have included it for you:
import java.util.Scanner;
First, you must create a Scanner object and direct it to look for input from the user (System.in). This is done by writing the following line of code in your main method:
Scanner input = new Scanner(System.in);
The Scanner class has several methods that allow you to read different types of input. The most commonly used methods are:
input.nextInt()- reads an integer from the userinput.nextDouble()- reads a double from the userinput.nextBoolean()- reads a boolean from the userinput.nextLine()- reads a line of text from the userinput.next()- reads a single word from the user
You can use these methods to read input from the user and store it in variables for later use in your program. For example, to read an integer from the user and store it in a variable called age, you would write:
int age = input.nextInt();
You will need to have a .next method for each input you want to read from the user. For example, if you want to read three integers from the user, you will need to have three separate .nextInt() methods.
At the end of each program that you use the Scanner class, it is good practice to close the Scanner object to free up system resources. This is done by writing the following line of code at the end of your main method:
input.close();
Formatting Reminders
The String class has a method called format() that allows you to format output in a specific way.
The format method takes two arguments: a format string and the values to be formatted. This will format the double value to two decimal places and return a string representation of the value:
String.format("%.02f", doubleValue)
You can then use this string in your output statements to display the formatted value.
System.out.println("$" + String.format("%.02f", doubleValue));
Unit 1A - Project 1 - Coins
This project will give you practice using the Scanner class to read user input, performing calculations with variables, and formatting output. You will write a program that calculates the total value of coins in a jar based on user input for the number of quarters, dimes, nickels, and pennies.
Exercise 1
In the main method, you should allow the user to input the number of coins in a jar. You should have separate inputs for quarters, dimes, nickels, and pennies. Be sure to write an appropriate prompt before each input so that the user knows what value they should be entering. The program should then display the values that represent the amount of each type of coin entered and then display the total value of all of the coins. Be sure the output is pleasing to the eye, and be sure all money totals are properly formatted to two decimal places and include a dollar sign.
Example output for inputs 15 5 2 4 (15 quarters, 5 dimes, 2 nickels, and 4 pennies) should look like this:
The total amount in the jar is $4.39
The breakdown is as follows:
There are 15 quarters worth $3.75
There are 5 dimes worth $0.50
There are 2 nickels worth $0.10
There are 4 pennies worth $0.04
Open the
01-unit1a-project1-coinsfolder and editCoins.java. Press Run to try it; Run Tests checks it (10 tests). Run feeds it the input ininput.txt; change that file to try other input.
Unit 1A - Project 2 - Dooflingies
This project will give you practice using the Scanner class to read user input, performing calculations with variables, and formatting output. You will write a program that calculates the number of containers needed to ship a given number of dooflingies, using the fewest containers possible.
Exercise 2
The shipping clerk at the Rinky Dooflingy Company is faced with the following problem: Dooflingies are very delicate and must be shipped in special containers. These containers are available in four sizes: huge, large, medium, and small, which can hold 50, 20, 5, and 1 dooflingy, respectively. Your program should allow a user to input any total number of dooflingies to be shipped and then display the number of huge, large, medium, and small containers needed to send the shipment in the minimum number of containers, and with the minimum amount of wasted space.
The output should look similar to the following (This example is for just one value. Be sure to write your program to work for any input.):
Number of Dooflingies: 1098
Container Number
Huge 21
Large 2
Medium 1
Small 3
Open the
02-unit1a-project2-dooflingiesfolder and editDooflingies.java. Press Run to try it; Run Tests checks it (10 tests). Run feeds it the input ininput.txt; change that file to try other input.
For teachers
Unit 1A Projects
Students read CSAwesome2's “Unit 1A Projects” in CS Room and work through its 2 Java coding exercises.
- Time: 2 class periods
- Tests: 20 in 2 graded exercises, set up for you when you import the lesson
Goals
- Practice for Unit 1: Using Objects and Methods.
Before class
- Import the lesson into your class from the Lessons page, or with New assignment → Use a lesson. It arrives as a draft with its tests already set up.
- Publish it.
- The original page is on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/unit1a-projects.html
- CS Awesome's own teacher materials: the CS Awesome teacher site
In class
- Students read
README.md. - Students do exercises 01–02, each in its own folder, pressing Run to try their code.
- Run Tests checks every graded exercise at once; scores appear in the Gradebook. Grading uses your copy of the tests, so a student who edits theirs does not change the grade.
Exercises
| Folder | File | Grading | Tests |
|---|---|---|---|
01-unit1a-project1-coins | Coins.java | Autograded | 10 |
02-unit1a-project2-dooflingies | Dooflingies.java | Autograded | 10 |
Teachers can download a reference solution after signing in.