Skip to main content

Section 1.27 Unit 1A Projects

90 minutes
These projects were created by Leigh Anne Fitz and Lisa Ferran to support student learning in AP Computer Science A. They are intended to promote curiosity, creativity, collaboration, and confidence as students begin their journey into computer science.
We hope these projects 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:
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.

Subsection 1.27.1 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:
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();

Subsection 1.27.2 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));

Subsection 1.27.3 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.

Activity 1.27.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

Subsection 1.27.4 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.

Activity 1.27.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
You have attempted of activities on this page.