CS I · Tue Dec 1 · 17.2 · 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: If It Is True. 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.

If It Is True

This reading explains how an if statement decides which lines of a Java program run. Yesterday's bench built true-or-false checks, and an if statement uses one of those checks to make a decision.

How an If Statement Decides

An if statement checks a boolean expression, which is a check whose value is true or false. When the check is true, the lines inside the braces run, and when the check is false, Java skips those lines and goes on to the line after the closing brace. Lines outside the if statement always run, whatever the check gives. The segment below was run inside the standard Main wrapper with the course JDK, and its output is shown under it.

1int temp = 48;
2System.out.println("Check the weather.");
3if (temp < 50)
4{
5    System.out.println("Bring a jacket.");
6}
7System.out.println("Have a good day.");
Check the weather.
Bring a jacket.
Have a good day.

Clicking the Next Line

The bench asks for the lines in the order they run. The braces are lines 4 and 6, and they mark where the if statement's block starts and stops. With temp at 48, the lines that run are 1, 2, 3, 5 and 7. Line 1 stores 48 in temp, and line 2 prints the first message, since neither line is inside the if statement. Line 3 checks 48 < 50, which is true, so line 5 runs next and prints the jacket message. Line 7 runs last, because it sits outside the braces and does not depend on the check.

The same segment was run again with line 1 changed to store 65.

1int temp = 65;
2System.out.println("Check the weather.");
3if (temp < 50)
4{
5    System.out.println("Bring a jacket.");
6}
7System.out.println("Have a good day.");
Check the weather.
Have a good day.

With temp at 65, the lines that run are 1, 2, 3 and 7. Lines 1 and 2 run as before, and line 3 still runs, because the program has to check 65 < 50 to decide, and the check is false. Java skips line 5 and goes straight to line 7, the first line after the closing brace.

Two Mistakes to Watch For

The bench catches two common mistakes, and the first is thinking that a false check skips the rest of the program, which would leave out line 7. Only the lines inside the braces are skipped, and line 7 runs for every value of temp. The second mistake is checking the condition with the wrong value, such as the starting number from a different job, or a number from before the box changed. Before deciding at line 3, a careful reader finds the last line that stored a value in temp and uses that value.

Sources: Oracle, The Java Language Specification, Java SE 21 Edition, §14.9 (n.d.); course JDK runs (2026).

Bugs, Issues and Steps to Reproduce

This section explains how to write down a problem in a tool so that the builder can make it happen again, find it and fix it.

Problems a Builder Missed

Code Coach has five written requirements, R1 to R5, and a test checks a tool against them. A test covers only the inputs that someone thought to try. People who use a tool often find problems that its builder missed.

A bug is a case where a program does something different from what its requirements say it should do. For example, R1 says, "Code Coach explains only the Java the student asked about." If a student asks about one line and Code Coach explains a different line, that is a bug, because the program broke a written requirement.

Not every problem a user reports is a bug, and a student might wish, for example, that Code Coach would give the answer to a bench job. The description of Code Coach says that it does not give the answer to a bench job, and R3 says that it does not write new code for the student. Wishing Code Coach would give the bench answer is a request, not a bug, because its requirements never promised that, and the builder decides whether to grant a request.

Writing a Problem Down as an Issue

An issue is a written report of a problem or a request, kept where the builders track their work, such as a repository. GitHub's documentation says that issues can track "ideas, feedback, tasks, or bugs." An issue stays open until someone closes it, for example when the bug is fixed or when the builders decide the work is not planned. Telling the builder about a problem in the hallway leaves no record, while an issue is written down and stays open until it is closed.

Steps to reproduce are the numbered actions that make the problem happen again. Mozilla's guide states, "Steps to reproduce are the most important part of any bug report." The same guide says that a bug a developer can reproduce is very likely to be fixed. A report that says "It broke when I used it" gives no steps, so the builder cannot make the problem happen again. After the steps, a report describes the expected result, which comes from the requirements, and the actual result, which is what happened instead. The report also says how often the problem happens, because a model's answer can change from try to try. Finally, a report needs a title that names the problem exactly. Mozilla gives "Software crashes" as an example of a poor summary, and a title such as "It's broken" has the same weakness, because neither one says what went wrong.

A Real Code Coach Bug

In October, the builder tested Code Coach with an 11-line segment of Java and asked what line 3 does. The segment and its real output are below, and line 3 is the if condition.

1int score = 17;
2int bonus = score % 5;
3if (score + bonus > 20)
4{
5    System.out.println("high");
6}
7else
8{
9    System.out.println("low");
10}
11System.out.println(score + bonus);
low
19

This request was built by a capture script, a small program that sends test requests to the class endpoint, and not by the bench. The script put a label line, "Java:", above the code, as the request's first four lines show.

Java:
int score = 17;
int bonus = score % 5;
if (score + bonus > 20)

Code Coach answered the question five times, and all five answers explained the line that stores bonus instead of line 3. The label line counted as line 1, so the third line of the request was the bonus line, and every line number was off by one. The builder concluded that the bug was in how the request was built, not in the model. Written as a report, the bug has a title and three parts. Figure 1 lays out the same report as a form.

Title: Asked about line 3, Code Coach explains line 2

Steps to reproduce
1. Use Code Coach's system prompt, version 2.
2. Put the label line "Java:" above the 11 lines of code.
3. Below the code, add the line "Question: What does line 3 do?"
4. Send the request to the class endpoint with the capture script.

Expected (from the requirements)
R1. Code Coach explains only the Java the student asked about.
Line 3 is the if condition, so the answer explains the if condition.

What happened
"Line 3 calculates the remainder when `score` (17) is divided by 5. It stores the result (2) in the variable `bonus`."
How often: 5 of 5 tries

Because the steps let the builder send the same request and get the same wrong line, the builder could test a change that sends the code as numbered lines, the way the bench shows them. With the same question, Code Coach explained line 3 in 5 of 5 tries. One answer began, "Line 3 checks if the sum of `score` and `bonus` is greater than 20." The bench now always sends the code to Code Coach as numbered lines, so a student cannot make this bug happen on today's bench.

Students who find a problem on a bench can report it in the bug report section of the Bench Basics credit code form. A report written there helps the builder most when it has the same parts as the Code Coach report.

Summary

A bug is a difference between what a program does and what its requirements say. An issue is a written report of a bug or a request, and it stays open until someone closes it. Steps to reproduce, what was expected and what happened give a builder what is needed to make a problem happen again and fix it.

Sources: Mozilla, Bug Writing Guidelines (n.d.); GitHub Docs, About issues (n.d.); GitHub Docs, Closing an issue (n.d.); Code Coach README and test captures (2026); course JDK runs (2026); Build spec Oct 26–Dec 18, §4.1 and §5 (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 makes a problem a bug?

  • The user did not like what the program did.
  • The program did something different from what its requirements say.
  • The program gave a different answer the second time.
  • The builder wrote the program in Java instead of another language.

MC 2. Which report gives steps to reproduce?

  • "Code Coach is wrong, and it was wrong again today."
  • "Code Coach should be faster when the whole class is asking."
  • "Code Coach broke when I used it on Tuesday's bench."
  • "On B21 job 4, I picked line 2, pressed Ask, and the answer stopped mid-sentence."

MC 3. Which part of a bug report is taken from the requirements?

  • The title
  • The steps to reproduce
  • What was expected
  • What happened

MC 4. Code Coach's requirements are R1 to R5 in the passage. Which of these is a request, not a bug?

  • Asked about line 4, Code Coach explains every line of the code.
  • Asked about a line, Code Coach writes a new version of the line.
  • A student wishes Code Coach would say whether the bench answer is right.
  • Given a sentence in plain English, Code Coach explains it as Java.

MC 5. Which lines run, in order?

1int points = 12;
2System.out.println("Start");
3if (points > 10)
4{
5    System.out.println("Level up");
6}
7System.out.println("Done");
  • 1, 2, 3, 7
  • 1, 2, 5, 7
  • 1, 2, 3, 5, 7
  • 1, 2, 3, 4, 5, 6, 7

MC 6. What is printed?

1int laps = 3;
2if (laps >= 4)
3{
4    System.out.println("Finished");
5}
6System.out.println("Cool down");
  • Cool down
  • Finished, then Cool down on the next line
  • Finished
  • Nothing is printed, because the check is false.

MC 7. What is printed?

1int tickets = 5;
2System.out.println("Line opens");
3if (tickets != 0)
4{
5    System.out.println("Tickets left");
6}
7System.out.println("Line closes");
  • Line opens, then Line closes, on two lines
  • Tickets left, then Line closes, on two lines
  • Line opens, Tickets left and Line closes, on three lines
  • Line opens and Tickets left, on two lines

MC 8. Line 1 is changed to store a different number in books. Which value makes line 4 run?

1int books = 2;
2if (books > 6)
3{
4    System.out.println("Heavy bag");
5}
6System.out.println("Ready");
  • 6
  • 5
  • 7
  • 2, the value it already has

MC 9. What is printed when temp is exactly 50?

1int temp = 50;
2if (temp < 50)
3{
4    System.out.println("Wear a jacket");
5}
6System.out.println("See you later");
  • Wear a jacket, then See you later on the next line
  • See you later
  • Wear a jacket
  • Nothing is printed, because 50 is not less than 50.

MC 10. The value in wait is 8. After line 4 runs, which line runs next?

1int wait = 8;
2if (wait > 5)
3{
4    System.out.println("Long wait");
5}
6System.out.println("Thanks");
  • Line 2, to check the condition again
  • Line 5, the closing brace
  • Line 6
  • No line, because the program stops after the block.

CR 1. List the lines that run, in order, when coins is 30, and give the output. Then line 1 is changed to store 20. List the lines that run and give the output again.

1int coins = 30;
2System.out.println("Count");
3if (coins >= 25)
4{
5    System.out.println("Buy a snack");
6}
7System.out.println("Save the rest");

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

CR 2. A classmate's whole report says "Code Coach is broken." Rewrite it as a report with a title, steps to reproduce, what was expected and what happened. You can use the Code Coach bug from the passage or a problem you make up, as long as every part is filled in.

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

Figure 1. The Code Coach report from the passage, laid out as a bug report form, with a title and three parts, and the last part saying how often the bug happened.
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. This segment has two if statements, one after the other. Trace it with miles at 6. Give the output, and name the line inside braces that is skipped and why.

1int miles = 6;
2if (miles > 2)
3{
4    System.out.println("Ride the bus");
5}
6if (miles > 10)
7{
8    System.out.println("Pack a lunch");
9}
10System.out.println("Leave at 7");

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

CR 4. Think of a real problem you have seen in any app or website. Write a bug report for it with a title, steps to reproduce, what you expected, what happened and how often it happens. If what you saw is really a request, say so and explain why.

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

Bench Basics

If It Is True

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.