CS I · Wed Dec 2 · 17.3 · We Do

Before the bell

You are responsible for all of this before the end of class.

  1. The discussion form in the I Do deck. All three sections. If you are here, this should be done.
  2. Your classwork. This form on the right. Section 1 before the exit ticket pops up; Section 2 past the floor.
  3. Today's Bench Basics activity: Otherwise. It opens later in class and lives on slide 4 of this deck.
  4. The exit ticket. It opens 15 minutes before the bell and lives on the last slide of this deck.
Classwork

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

Otherwise: if, else if and else

This reading explains how Java chooses one path out of several, and then traces one code segment for five different values.

One Path Out of Several

Yesterday's `if` either ran its lines or skipped them, because its body runs only when its condition is true. An `else` gives Java a second path, which runs when the condition is false. An `else if` adds another condition to check, and a chain can hold as many of them as it needs. Java checks the conditions from the top, runs the first branch whose condition is `true`, and skips every other branch. The `else` at the bottom runs only when no condition above it was `true`. For that reason, exactly one branch of an `if`, `else if` and `else` chain runs. A chain with no `else` at the bottom runs one branch or none, because nothing runs when every condition is false. The segment below was run inside the standard wrapper with the course's Java.

1int minutes = 12;
2if (minutes < 5)
3{
4    System.out.println("on time");
5}
6else if (minutes < 15)
7{
8    System.out.println("a little late");
9}
10else
11{
12    System.out.println("late");
13}
a little late

With `minutes` at 12, the check on line 2 is false, so Java skips the first branch and checks line 6. That check is true, so Java runs line 8, prints "a little late" and skips the `else`.

One Row for Each Value

The table below is the kind that Bench Basics asks for on B22. It has one row for each value of `minutes`, and each row was run as its own program.

minutes   minutes < 5   minutes < 15   branch that runs   printed
3         true          (not checked)  first              on time
5         false         true           second             a little late
12        false         true           second             a little late
15        false         false          else               late
40        false         false          else               late

With 3, the first check is true, so Java runs the first branch and never checks `minutes < 15`. With 5, the first check is false, because 5 is not less than 5, and the second check is true. The row for 12 works the same way as the row for 5. With 15, both checks are false, because 15 is not less than 15, so the `else` runs. With 40, both checks are false again, and the `else` prints "late."

Two Mistakes Bench Basics Catches

The first mistake is thinking that two branches can both run. With `minutes` at 3, both conditions are true, but Java stops at the first true condition and never reaches the second. One job on B22 asks about this mistake. The second mistake is getting a boundary wrong. A student who reads `minutes < 5` as true for 5 will pick the wrong branch, and so will a student who reads `minutes < 15` as true for 15. On the bench, each wrong check and each click on a line that does not run next costs 5 points.

Sources: College Board, AP Computer Science A Course and Exam Description (2025); Bench Basics classroom data, B22 and the course JDK (2026).

Accessibility

This section explains how a builder checks whether a program leaves some people out. A program can work every time it runs and still not work for everyone who tries to use it. The AP Computer Science A course calls this the impact of a program, and it says the impacts can be beneficial or harmful. Every program helps some people, and a program built to fill a need can still leave other people out.

What Accessibility Means

Accessibility means building a program or page so that people with disabilities can use it. The W3C's Web Accessibility Initiative lists visual, hearing, physical, speech, cognitive and neurological disabilities. The same changes help many other people as well. For example, the W3C names a person using a screen in bright sunlight, a person with a broken arm, and older people whose abilities change with age. A page that works for its builder has not been checked for accessibility, because the builder is only one kind of user.

Contrast

Contrast is the difference in brightness between text and its background. It is measured as a ratio, which runs from 1 to 1, for no contrast at all, up to 21 to 1, for black text on a white background. The ratio is calculated from the two colors with a formula in the W3C's Web Content Accessibility Guidelines. The guidelines set a minimum of 4.5 to 1 for ordinary text, so that people with moderately low vision can read it, and large text has a lower minimum. For example, gray text in the color #999999 on a white background measures 2.85 to 1, which is below the minimum. A darker gray, #595959, measures 7.00 to 1 on white and meets the minimum. Figure 1 shows the same sentence printed in both grays.

Hue is not a key factor in the formula, so two colors that look different to one person can still have low contrast, and contrast is measured instead of judged by eye. The grays #777777 and #767676 look almost the same. On white, the first measures 4.48 to 1 and the second measures 4.54 to 1, so the two grays land on opposite sides of the line. The guidelines say that a ratio is not rounded up, so 4.48 to 1 does not meet the minimum.

The Bench Basics code panel was checked this way on October 20, 2026. Its code is dark ink, #1B1B1B, which measures 16.49 to 1 on the off-white panel, #FBFAF6, and 15.48 to 1 on the pale yellow highlight of the line being traced, #FFF3C4. Both pairs meet the minimum, but the line numbers did not. Their gray, #8A8576, measured 3.53 to 1 on the panel and 3.31 to 1 on the highlight. It was darkened to #66624F and measured again, at 5.87 to 1 and 5.51 to 1, so the line numbers now meet the minimum. White text on the copper Check buttons, #C2622F, measured 4.13 to 1, so the copper was darkened to #A04E1D, which measures 5.83 to 1.

Alt Text and the Keyboard

Alt text is a short written description of an image, stored in the page with the image. A screen reader is software that reads a page aloud for a person who cannot see it, and it reads the alt text in place of the image. Good alt text is brief, and it says what the image shows that the words around it do not. For example, Figure 1 shows a picture of a classroom with its alt text beside it, and the alt text names the students, their laptops and the whiteboard. A file name such as IMG_2041.png is not alt text, because it describes nothing about the image. The W3C lists a file name used in place of alt text as a failure, and some screen readers read the file name aloud when an image has no alt text.

A page should also work with the keyboard alone, because some people cannot use a mouse. On a web form, the Tab key moves from one control to the next.

Checking Is Part of Building

The AP course also notes that a program meant to fill a need can have harmful effects that its builder did not intend. A page that leaves out a person with low vision is one such effect, and checking for it is part of building a program. The bench's line numbers show how such a check works: a color is measured, found below the minimum, changed and measured again.

Summary

Accessibility means building a page so that people with disabilities can use it, and the same changes help many other people. Contrast is measured as a ratio from 1 to 1 up to 21 to 1, with a minimum of 4.5 to 1 for ordinary text, and alt text gives a screen reader words to read in place of an image.

Sources: W3C WAI, Introduction to Web Accessibility (2026); W3C WAI, Understanding SC 1.4.3: Contrast (Minimum) (2026); W3C WAI, Understanding SC 1.1.1: Non-text Content (2026); MDN Web Docs, What is accessibility? (2026); MDN Web Docs, HTML: A good basis for accessibility (2026); College Board, AP Computer Science A Course and Exam Description (2025); Bench Basics colors and contrast ratios, course site (2026).

Classwork · Section 1 — Reading 2

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

MC 1. According to the passage, what does accessibility mean?

  • Making a page load quickly on a slow school network
  • Building a program or page so that people with disabilities can use it
  • Making sure a page works on the builder's own laptop
  • Letting anyone on the web open a page's address

MC 2. Which text color meets the minimum of 4.5 to 1 for ordinary text on the background named?

  • #999999 on white, which measures 2.85 to 1
  • #777777 on white, which measures 4.48 to 1
  • #767676 on white, which measures 4.54 to 1
  • #8A8576 on off-white #FBFAF6, which measures 3.53 to 1

MC 3. A page about a second-line parade shows a photo of a brass band marching down a street lined with people. The caption under the photo reads "Sunday's second line." Which is the best alt text for the photo?

  • IMG_3307.jpg
  • Sunday's second line
  • A brass band marches down a street lined with people
  • photo

MC 4. According to the passage, which person without a disability is also helped when a page is accessible?

  • The builder who wrote the page and tested it on a large screen
  • A person using a phone screen outside in bright sunlight
  • Nobody, because accessibility changes help only people with disabilities
  • A person who wants the page to have more pictures

MC 5. Which branch of this code segment runs?

1int temp = 68;
2if (temp > 85)
3{
4    System.out.println("hot");
5}
6else if (temp > 60)
7{
8    System.out.println("warm");
9}
10else
11{
12    System.out.println("cool");
13}
  • The first branch, so it prints hot
  • The second branch, so it prints warm
  • The else branch, so it prints cool
  • The second branch and the else, so it prints warm and then cool

MC 6. A streetcar holds 20 riders. What does this code segment print?

1int riders = 20;
2if (riders < 20)
3{
4    System.out.println("room for more");
5}
6else
7{
8    System.out.println("full");
9}
  • room for more
  • room for more, and then full on the next line
  • full
  • Nothing, because riders is not less than 20

MC 7. In this code segment, every condition is false. What does it print?

1int yards = 3;
2if (yards >= 10)
3{
4    System.out.println("first down");
5}
6else if (yards >= 5)
7{
8    System.out.println("good gain");
9}
10else
11{
12    System.out.println("short gain");
13}
  • Nothing, because no condition is true
  • good gain, because 3 is the closest to 5
  • short gain
  • first down, because the first branch runs when nothing else does

MC 8. In this code segment, both conditions are true for 30. How many branches run?

1int pages = 30;
2if (pages > 10)
3{
4    System.out.println("long");
5}
6else if (pages > 20)
7{
8    System.out.println("very long");
9}
10else
11{
12    System.out.println("short");
13}
  • One, the first branch, so it prints long
  • Two, so it prints long and then very long
  • One, the second branch, so it prints very long
  • Three, because Java runs the chain from top to bottom

MC 9. In line 1 of this segment, the 0 is replaced with a different number. Which number makes the segment print normal?

1int wait = 0;
2if (wait < 10)
3{
4    System.out.println("fast");
5}
6else if (wait < 30)
7{
8    System.out.println("normal");
9}
10else
11{
12    System.out.println("slow");
13}
  • 5
  • 10
  • 30
  • 45

MC 10. This segment prints gold. If the first two conditions are swapped, so that laps >= 4 is checked first and prints silver, what does it print?

1int laps = 9;
2if (laps >= 8)
3{
4    System.out.println("gold");
5}
6else if (laps >= 4)
7{
8    System.out.println("silver");
9}
10else
11{
12    System.out.println("keep going");
13}
  • gold, because 9 is closer to 8 than to 4
  • silver, because laps >= 4 is now checked first and is true
  • gold and silver, because both conditions are true for 9
  • keep going, because the order of the checks was changed

CR 1. The segment below is run four times, with depth set to 4, 6, 12 and 20. Fill a branch table with one row for each value, using these columns: depth, depth > 12, depth > 6, branch that runs, printed. Write (not checked) where Java skips a check.

1int depth = 4;
2if (depth > 12)
3{
4    System.out.println("flooded");
5}
6else if (depth > 6)
7{
8    System.out.println("deep water");
9}
10else
11{
12    System.out.println("passable");
13}

Write your answer in your lab notebook, labeled CR 1.

CR 2. Explain in two sentences why only one branch of an if, else if and else chain runs.

Write your answer in your lab notebook, labeled CR 2.

Figure 1. The same sentence in two grays on white, with each measured contrast ratio, and a picture of a classroom with the alt text that a screen reader reads aloud in its place.
Classwork · Section 2 — Past the floor

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

CR 3. Trace this segment for three values of battery: 3, 20 and 60. For each value, give each check Java makes, the branch that runs and what is printed. Then name the value that sits on a boundary and explain why it goes where it does.

1int battery = 3;
2if (battery <= 5)
3{
4    System.out.println("charge now");
5}
6else if (battery <= 20)
7{
8    System.out.println("low");
9}
10else
11{
12    System.out.println("ok");
13}

Write your answer in your lab notebook, labeled CR 3.

CR 4. Choose an app or website you use. Name one person it may leave out, the feature on the screen that causes the trouble, and one change that would help. Use at least one of today's terms: accessibility, contrast or alt text.

Write your answer in your lab notebook, labeled CR 4.

Bench Basics

Otherwise

Open the bench, do its six jobs, then paste your credit code into the credit-code form. You can turn in up to three codes per bench; your best score is your grade.

Bench Basics opens during your class period.

Classwork

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

Exit Ticket

This opens during your class period.