Select Page
APCS Unit 3
Control Structures
Control Structures Introduction

Example Control Structures

 

This unit gets into some of the most important computer science topics that we’ll cover all year: control structures.  Control Structures are the things that tell our program when to do what.  With control structures we can train our program to make choices or to iterate (loop) over the same code repeatedly.  In the end, it turns out that we only need five (5) different control structures to make every possible program configuration:

  • if
  • if-else
  • else-if
  • while
  • for

This unit is all about these five control structures, how to use them, and when to use them.  We’ll cover the following topics during this unit:

  1. How to use if, if-else, and else-if strucutres to have your program make decisions
  2. How to use the “while” and “for” loops to have your program iterate over the same code
  3. How to combine these control structures to create a simple gradebook program

By the end of the unit, you should have the knowledge to use these 5 programming tools in a variety of ways!

Part 1: Decision Making

BlueJ Reference

In the first part of this unit we focus on the three different ways that your program can make decisions: the “if”, “if-else”, and “else-if” structures.  It turns out that these sets of questions will give you all of the decision-making options that you’ll need for all of our programs all year long!

As you work through thisfirst part of the unit, you’ll want to pay particularly close attention to the types of questions you can ask inside an if or else-if strucutre.  The types of questions (and their corresponding syntax) will be essential for making most of our programs function the way we want!

GRADING & PROCESS

 Watch the introductory videos about conditionals and the different ways we use “if” statements

 Create a new project in BlueJ called “Unit 3” – you should store ALL of your Unit 3 programs in this same project.  

 Complete Java Task 12: PB&J

 Complete Java Task 13: Prime Factors

 Complete Java Task 14: Day of the Week

 Complete Java Task 15: Calculator Bonus

 Have Mr. Benshoof check-off your completed Java challenges

Java If Statements 1

Java If Statements 2

If Statements with Strings

Part 2: Loops

BlueJ Reference

The second part of our unit is all about making parts of the program repeat.  These “loops” can cause a section of the program to repeat itself a different number of times.  One of the challenges is to use a loop that gives you the kind of control that you want.

The WHILE loop (sometimes called sentinel controlled repetition) uses a counter to keep track of how often the program has run.  Once the counter (or another variable) reaches a threshold, the loop finally stops.

The FOR loop (sometimes called counter-controlled repetition) uses a variable to count the number of times the loop has repeated.  Once the counting variable reaches its limit, the loop ends and the program continues.

These two looping structures are the focus of this part of the unit, and will be important tools throughout the rest of the year!

GRADING & PROCESS

 Watch the videos on loops and looping control structures.  Take a full page of notes on these topics as you watch them.

 Complete Java Task 16: Even/Odd

 Complete Java Task 17: Sum & Average

 Complete Java Task 18: Odd Counter

 Complete Java Task 19: Multiplication Chart

 Complete Java Task 20: Random Grid

 Complete Java Task 21: 12×12 Grid

 Complete Java Task 22: Alternating Grid

 Complete Java Task 23: Small Rectangle

 Have Mr. Benshoof check-off your completed Java challenges

 Complete the short Control Structures Assignment

 Take the Unit 3 Quiz

While Loops

For Loops

Nested For Loops

Part 3: Gradebook

The final part of our unit is to use the control structures we’ve studied to make a working Gradebook program! The gradebook you make needs to meet the criteria listed in the unit paperwork.  Specifically:

  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 was
    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.

 

APCS Unit 3 Map
Looking for something?  Here you'll find a library of links to all the documents, images, and videos needed here in APCS Unit 3.