CS I · Wed Nov 4 · 14.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: Print It. 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.

Print It: What Shows Up, and Where the Lines Break

This reading explains the two Java statements that print text, and then traces one program to show where each piece of output lands.

Two Ways to Print

The statement `System.out.println` prints what is inside its parentheses and then ends the line, so the next output starts on a new line. The statement `System.out.print` prints in the same way but does not end the line, so the next output continues right after it. Oracle's documentation for Java describes `println` as working the same way as `print` followed by `println()` with nothing inside, which terminates the current line by writing a line separator. Text goes inside quotation marks, and the quotation marks themselves are not printed. Every character between them is printed exactly as written, including spaces and commas. The statement `System.out.println()` with nothing inside prints nothing and ends the line, which leaves an empty line when the line was already empty.

One Program, Traced

The program below has 10 lines, numbered from the top, and lines 3 to 8 each hold one print statement.

1public class Main {
2    public static void main(String[] args) {
3        System.out.print("Ready");
4        System.out.print(", set");
5        System.out.println(", go.");
6        System.out.println("Line two");
7        System.out.println();
8        System.out.print("Done");
9    }
10}

The trace table has one row for each print statement. The Output column shows what that statement prints, and the last column says whether the line ends.

Line   Output       Line ends?
3      Ready        no
4      , set        no
5      , go.        yes
6      Line two     yes
7      (nothing)    yes, so this line stays empty
8      Done         no

Lines 3 and 4 use `print`, so "Ready" and ", set" stay on the first line. Line 5 adds ", go." and ends the first line. Line 6 prints "Line two" on the second line and ends it. Line 7 prints nothing and ends the third line, so the third line is empty. Line 8 prints "Done" on the fourth line and does not end it. The real output, checked with the course's Java, is shown below. Nothing comes after "Done," because no statement ends that line.

Ready, set, go.
Line two

Done

Two Mistakes Bench Basics Catches

The first mistake is putting each `print` on its own line of output, as if `print` ended the line the way `println` does. A student who makes this mistake writes "Ready" and ", set" on two separate lines. The second mistake is forgetting that a space inside the quotes is printed exactly. The text ", set" starts with a comma and then a space, so the output reads "Ready, set" and not "Ready,set". The B11 bench checks a prediction exactly, one line at a time, so every space between words and every line break counts. The bench does ignore extra spaces at the very end of a line and empty lines after the last line, but a missing space between two words makes the whole line different from the real output.

Sources: Oracle, Class PrintStream, Java SE 21 (n.d.); Bench Basics classroom data, B11 and the course JDK (2026).

Events, Conditions and Actions

This section explains how a program's behavior is written as sentences, and the three parts that each of those sentences needs.

Events and Conditions

An event is something that happens that a program can respond to. A click on a button, a key press and a web page finishing loading are all events, according to Mozilla's guide for web developers. A request to a server that finishes with its answer back is also an event, and a page can respond to it. For example, pressing Check row on Bench Basics is an event, because at one moment the button is pressed. The phrase "the box is empty" does not describe an event, because nothing happened, so it describes a condition.

A condition is a check that is either true or false at that moment. The box is empty, the row is right and the input is Java are all conditions. Each one has only two possible answers at a given moment. The phrase "you press Check row" does not describe a condition, because it is something that happens, so it is an event.

Actions and the Behavior Sentence

An action is what the program does next. Showing a message, locking a row, sending a request and showing an answer are all actions. The sentence "The bench should work well" names no action, because no one could watch the bench do it. The instruction "Show 'Not yet'" does name an action, because a person can see whether it happened.

A behavior sentence has all three parts, in this order: "When [event], if [condition], [action]." The event comes first, because the program responds to something that happens. The condition comes next, because the program checks it at the moment of the event. The action comes last. Engineers at Rolls-Royce developed a method for writing requirements called EARS, first published in 2009, in which the parts of a requirement always appear in the same order. In EARS, a requirement about an event begins with the word "When," just as a behavior sentence does.

One Event, Different Actions

One event can lead to different actions, because the condition decides which action happens. Figure 1 shows this for Bench Basics. The first behavior sentence reads, "When you press Check row, if the row is right, the bench shows 'Right' in green and locks the row." The second reads, "If the row is not right, the bench shows 'Not yet' and counts one misstep." The event is the same press in both sentences, and only the condition is different, so the action is different too.

Code Coach's requirement R5 can also be written as a behavior sentence: "When you press Ask Code Coach, if the box is empty, the bench shows 'Paste or pick a line first.' and sends no request." Its action includes something the bench must not do. A phone gives an everyday case of the same pattern. Apple's support page explains that when a call arrives and an iPhone is in Silent mode, the phone vibrates for the call. The event is the arriving call, the condition is that Silent mode is on, and the action is a vibration instead of a ring.

Many of a program's behavior sentences cover cases that are not the ordinary one. The ordinary case for Check row is a row that is right, but a complete set of rules also says what happens when the row is wrong. EARS has a separate pattern for this purpose, which states how a system responds to situations that are not wanted. The same Apple page adds a case of its own, because calls from favorite contacts still ring in Silent mode. A rule that covers only the ordinary case leaves every other case to whoever writes the code. That person then has to guess, and two people writing the same program can guess in two different ways.

Conditions in Java

In Java, a condition goes in parentheses after the word if, as the small tag under Figure 1 shows. Oracle's Java tutorial explains that the code controlled by an if runs only when the test is true, and the program skips that code when the test is false. The class will read conditions and if statements on Bench Basics from November 30 to December 2, on benches B20 to B22. The true and false from the B07 bench are the same true and false that an if statement checks.

Summary

A program's behavior is written as sentences with an event, a condition and an action, in the order "When [event], if [condition], [action]." An event is something that happens, a condition is a check that is true or false at that moment, and an action is what the program does next. One event can lead to different actions, and a complete set of rules covers the unusual cases as well as the ordinary one.

Sources: Mozilla, Introduction to events (n.d.); Mozilla, XMLHttpRequestEventTarget: load event (n.d.); Oracle, The if-then and if-then-else Statements (n.d.); Mavin, EARS: The Easy Approach to Requirements Syntax (n.d.); Apple, Use the Action button, side button, and other controls on your iPhone (2026); Bench Basics and Code Coach classroom data (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. A city bus follows this rule: "When a rider taps a bus pass on the reader, if the pass has rides left, the reader beeps once and shows a green light." In this rule, which words are the event?

  • a rider taps a bus pass on the reader
  • the pass has rides left
  • the reader beeps once and shows a green light
  • the bus pass and the reader that it is tapped on

MC 2. A video app follows this rule: "When a video ends, if another video is in the list, the app starts the next video." In this rule, which words are the condition?

  • a video ends
  • another video is in the list
  • the app starts the next video
  • the video that has just ended

MC 3. A game follows this rule: "When a player presses the jump key, if the player is standing on the ground, the character jumps." In this rule, which words are the action?

  • a player presses the jump key
  • the player is standing on the ground
  • the game feels smooth to play
  • the character jumps

MC 4. According to the passage, why does a set of rules need sentences for cases that are not the ordinary one?

  • The ordinary case is the only case that a program is able to check.
  • A case the rules leave out is left to whoever writes the code, who has to guess.
  • A program shows an error message for every case that the rules leave out.
  • Unusual cases never happen once a program has been finished and tested.

MC 5. What does this code segment print?

1System.out.print("Geaux");
2System.out.println("Tigers");
  • Geaux Tigers, on one line with a space between the words
  • GeauxTigers, on one line with no space between the words
  • Geaux on one line, and Tigers on the line after it
  • "Geaux""Tigers", on one line with the quotation marks

MC 6. How many lines of output does this code segment print?

1System.out.println("Red beans");
2System.out.print("and ");
3System.out.print("rice");
4System.out.println();
5System.out.println("Monday");
  • 5, one line for each statement in the segment
  • 4, because println() with nothing inside adds an empty line
  • 3, because the two print statements share one line
  • 2, because only println statements with text make lines

MC 7. In this code segment, what does line 2 print?

1System.out.println("Po-boy");
2System.out.println();
3System.out.println("Gumbo");
  • Nothing, so Gumbo prints right after Po-boy on the same line
  • An empty line, so a blank line appears between Po-boy and Gumbo
  • The word println, because nothing else is inside the parentheses
  • Po-boy a second time, because it repeats the line printed above

MC 8. What does this statement print?

1System.out.println("Mardi Gras");
  • "Mardi Gras", with the quotation marks
  • MardiGras, with no space between the words
  • Mardi Gras, with one space and no quotation marks
  • ("Mardi Gras"), with the parentheses and the quotation marks

MC 9. Which segment prints Jazz Fest, with both words on one line?

1// Segment A
2System.out.println("Jazz");
3System.out.println("Fest");
4
5// Segment B
6System.out.print("Jazz ");
7System.out.println("Fest");
8
9// Segment C
10System.out.println("Jazz ");
11System.out.print("Fest");
12
13// Segment D
14System.out.print("Jazz");
15System.out.println();
16System.out.print("Fest");
  • Segment A
  • Segment B
  • Segment C
  • Segment D

MC 10. What does this code segment print?

1System.out.print("Magazine");
2System.out.println(" Street");
  • MagazineStreet, with no space between the words
  • Magazine and Street, each on its own line
  • Magazine Street, with one space between the words
  • Magazine Street, with two spaces between the words

CR 1. Write the exact output of this code segment, line by line. If a line is empty, write (empty line) on it.

1System.out.print("Beignets");
2System.out.print(" and ");
3System.out.println("coffee");
4System.out.println();
5System.out.println("Shop open");

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

CR 2. A library's self-checkout machine reads the barcode on each book. Write one behavior sentence, with all three parts, for what the machine does when a book's barcode will not scan. Then label the event, the condition and the action.

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

Figure 1. One press of Check row is the event, the bench checks one condition, and the true branch and the false branch each lead to a different action.
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 code segment prints on three lines. Name the one statement you would change so that two of the lines print as one line, write the changed statement, and give the new output.

1System.out.println("Crescent ");
2System.out.println("City");
3System.out.println("Connection");

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

CR 4. Choose a device or app you use. Write two behavior sentences for the same event with two different conditions, so that the program takes a different action in each case. Then say which sentence covers the unusual case and why a program needs it.

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

Bench Basics

Print It

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.