APCS Unit 3: Control Structures

Using if, if-else, else-if, while, and for


Control Structures are programming tools that let us force parts of a program to make decisions, skip code blocks, or possibly repeat parts of a program.  By using 5 main control structures, we have all the control over a program that we need.  Those 5 control structures will be:

  • Conditionals: if,  if-else,  else-if
  • Loops:  for, while

Java has other control structures built into it, but these five will let us do everything we need to be able to do in any program.  As we work through this unit, you’ll need to take some good notes and think about the key differences between each of these.  As you continue, you’ll tackle three big parts to our unit:

  1. Use Conditionals to make choices within your program
  2. Use Loops to make your program repeat itself in a variety of ways
  3. Build a few neater programs to solve some problems

When you’re done, you’ll be able to control computers before they learn to control you!


(20 pts)  About 3 days

We’ll start our formal look at control structures with conditionals.  Conditionals are things like ‘if’ and ‘if-else’ that force the program to make a decision based on a logical question.  These conditions determine which parts of the program run, and which ones don’t.  Here you’ll create 4 new programs that use various conditionals.


(30 pts)  About 3 days

Once our program is able to make decisions for itself, the next step is to make it repeat parts of its own logic when convenient.  Repetition is a major part of computer science, and here the two loops “for” and “while” will give us even more control over the flow of the program as you write new applications.


(30 pts)  About 2 days

With the new tools of flow-of-control at our disposal, the last thing is to create your own small gradebook program.  This program will need to let you enter a variety of assignment scores for a simple course in school.  The program then needs to be able to calculate the distribution of scores and your average grade.

PART 1: Decision Making

Using if, if-else, and else-if structures to make decisions

Conditionals are how we make a program make its own decisions.  Structures like the ifif-else, and else-if all let us force the program to make a decision between 1, 2, or more courses of action.  In doing so, our program becomes more flexible and able to handle a variety of situations.  In this first part to our unit, your job is to write four different programs that each require conditionals.  As you work and take some notes in this section, pay close attention to the differences between each of our conditionals.


 Take a full page of notes in your engineering notebook about conditionals, including the differences between the three conditional structures

 Complete the 4 Java Tasks using the appropriate conditionals

Have Mr. Benshoof confirm your working programs

If Statements: Basic

If Statements: Strings

If Statements: Multiple Conditions

What’s Due In Bug Bot Part 1: Wiring

  • Conditionals Notes
  • Conditionals Programs
  • Benshoof’s Check-Off

Here’s what’s due in Part 1: Decision Making

  1.  Take a full page of notes about conditionals after watching the three introductory videos
  2. Complete the 4 Java Tasks on conditionals
  3.  Have Benshoof check-off your programs!

PART 2: Loops

Making your program repeat using 'while' and 'for' loops

while loop structure

for loop structure

Controlling the flow of a program lets us do some pretty impressive things.  If you remember back in Jeroo, it was the while loop that let us make our Jeroo run forever… or at least until we needed it to stop.  Now in Java, we’ll use both while loops and for loops to make portions of our program repeat.  These two loops can both be used in most instances, but their differences are pretty important:

    • Are called “counter controlled repetition”
    • Give us an extra variable to work with within the loop itself
    • Are best used for a set amount of loops
    • Nest within other for loops pretty easily
    • Are called “sentinel controlled repetition”
    • Use a variable that you’ve already created
    • Are best used for loops that need to go until a condition is reached
    • Don’t nest as easily without concern for getting caught in the loop!

While Loops

For Loops

Nested for Loops

What’s Due In Control Structures Part 2: Loops

  • Loop Notes
  • Looping Java Tasks
  • Benshoof’s Check-Off

Here’s what’s due in Part 2: Loops

  1.  Take a full page of notes on for and while loops after watching the three presentations
  2. Complete Java Tasks 16-23, all about loops!
  3.  Have Benshoof check-off your successful programs

PART 3: Gradebook

Create your own grade book program!

Eventually as programmers, your job turns to making programs for other people.  To wrap up this unit, your job is to create a grade book program so that students can summarize their grades in a particular class.  The grade book program you make must meet the following criteria:

  1. Let the user enter a variety of assignment types (at least 2: quizzes and homework).
  2. Let the user enter a variety of assignment grades
  3. Let the user enter the grades and assignments in any order
  4. When the user is done entering assignments, the program should tell them some information:
    1. How many assignments were listed for each type (how many quizzes, how many homeworks, etc)
    2. How many of the total list of assignments were A’s, B’s, C’s, D’s, or F’s
    3. What the average score (based on either points OR percentages… whichever you like best) on all assignments wa
    4. Assuming the upcoming final would be worth 15% of the course grade (and all entered assignments were the remainder of the grade), what grade would the student need on the final to earn their desired course grade.
  5. The program should be relatively easy to use and easy to understand.

What’s Due In Control Structures Part 3: Gradebook

  • Brainstorm & Notes
  • Gradbook Program
  • Log 3: Control Structures

Here’s what’s due in Part 3: Gradebook

  1. Take a full page of notes and brainstormed ideas for making your grade book program work!
  2.  Make your grade book program within the criteria and constraints listed.
  3. Write a full-page response about control structures, Java, and class time in your engineering notebook

Double Check: Unit Expectations

Check what you need to have completed by the unit deadline

The purpose of this unit is to use the Engineering Design Process to wire, design, and build a working Bug Bot.  You should have had the chance to do some soldering, design your own Bug Bot, and use the tools in our makerspace to build your Bug Bot.  If you were really on-task and working hard, you should have also had time to decorate your Bug Bot to make it look super cool.  By the unit deadline, you should have completed and be able to submit the following items:

Engineering Notebook:

 (Part 1) Definition of problem, criteria, constraints, and Bug Bot Overview notes

 (Part 1) Wiring diagram, soldering notes, and wiring reflection

 (Part 2) Bug Bot Design brainstorm, notes, and careful drawing

 (Part 3) Final drawing/picture, half-page written reflection on Bug Bots

Building & Making:

 (Part 1) Wiring should work, soldering should be clean and complete

 (Part 2) Bug Bot design should be carefully drawn out including labels and diagrams

 (Part 3) The Bug Bot should be assembled and should function properly

Benshoof Checkpoints

 (Part 1) Benshoof should have seen your working wiring before you moved on

 (Part 2) Benshoof should have seen your careful drawing before you moved on

 (Part 3) Benshoof should have seen your working Bug Bot