Lab 01 10 pts Week 1 Due Apr 2

Lab 01: Hello, World

Your first Java program — println, escape sequences, concatenation

println escape-sequences concatenation
Clone from GitHub
3 checkpoints 5 autograder 2 timeliness

After this lab, you will be able to:

  • Print multi-line output using System.out.println
  • Use escape sequences (\t, \n, \") to format text
  • Concatenate strings and values with the + operator
  • Match exact expected output required by autograder tests

Before You Start

Make sure you have the following set up on your machine. If anything is missing, head to the Setup Hub and follow the instructions there before continuing.

  • Java JDK 25 — Open a terminal and run java --version. You should see 25.x in the output. If you get “command not found” or a different version, you need to install or update.
  • Git — Run git --version in your terminal. If it prints a version number, you’re good.
  • VS Code with the Extension Pack for Java installed. You can find it in the Extensions sidebar (search “Extension Pack for Java” by Microsoft).
  • A GitHub account — You’ll need this to accept assignments and submit your work.

First time? If this is your first time opening a terminal, don’t panic. On Mac, open the Terminal app. On Windows, open PowerShell or the terminal built into VS Code (Ctrl+`). You’ll type commands there throughout this course.


What You’re Building

You will write a program that prints a formatted profile card to the console. The card has a decorative banner, a tab-aligned profile section, and a stats summary compressed into a single println call using \n. This exercises every basic output technique you will need for the quarter.


Getting Your Lab Code

Every lab in this course lives in its own GitHub repository. Here’s how to get started:

  1. Accept the assignment. You’ll get a GitHub Classroom link in class or on Canvas. Click it and accept. GitHub will create a personal copy of the lab repository for you.

  2. Clone the repo in VS Code. Open VS Code, then open the Command Palette (Ctrl+Shift+P on Windows, Cmd+Shift+P on Mac). Type Git: Clone and select it. Paste the URL of your new repository and choose a folder to save it in.

  3. Open the project folder. VS Code will ask if you want to open the cloned repository. Click Open. You should see a file tree on the left with your project files.

  4. Find the starter file. Look in the src/main/java folder. You’ll see a file called Hello.java — that’s where you write your code.

Where’s the terminal? In VS Code, go to Terminal → New Terminal (or press Ctrl+`). This opens a terminal panel at the bottom of VS Code. You’ll run all your commands there.


Concepts and Misconceptions

Concept Common Mistake What the Test Catches
println vs print Using print when println is required (missing newline) Output diff shows missing line break
Escape sequences Writing a literal \t instead of a tab character Whitespace mismatch in expected output
String concatenation Forgetting spaces around + or missing + entirely Compilation error or garbled output
Exact output matching Extra spaces, missing punctuation, wrong casing Character-level diff failure

Checkpoints

Checkpoint 1: Print a Banner with println

What to do: Use three System.out.println calls to print a banner. Each line is a separate call. Match the exact text below, including the = border characters.

Expected output:

==============================
     Welcome to My Profile
==============================

Since this is your first Java program, here’s what the code looks like. Type this inside the main method in Hello.java:

System.out.println("==============================");
System.out.println("     Welcome to My Profile");
System.out.println("==============================");

Each System.out.println(...) prints the text inside the quotes, then moves to the next line. That’s it. That’s your first Java program.

What the test checks: The first three lines of output match the banner exactly, character for character.

Run your tests to see if you got it right. In the terminal at the bottom of VS Code, type:

./gradlew test

On Windows, use gradlew.bat test instead. If Checkpoint 1 passes, you’ll see a green result for that test. If it fails, read the diff — it will show you exactly where your output doesn’t match.

Debugging tip: If the test says “expected = but got ` ", count your =` signs. There should be exactly 30. Copy the expected output from the test failure message and compare it side by side with your code.


Checkpoint 2: Print a Profile with Tab Alignment

What to do: Below your banner code, add more System.out.println calls to print a profile block. Labels and values are separated by \t (a tab character). For example: "Name:\tAda Lovelace".

Expected output (the gap between label and value is a single tab):

Name:	Ada Lovelace
Role:	Programmer
Year:	1843

Each field gets its own println call. Use \t inside the string — not the Tab key on your keyboard.

What the test checks: Each profile line contains a tab character (not spaces) between the label and value.

Run your tests again:

./gradlew test

Debugging tip: If alignment looks correct in your terminal but the test fails, you probably typed spaces instead of \t. Tabs and spaces look similar but are different characters. Check your string literals character by character.


Checkpoint 3: Print Stats Using \n in a Single println

What to do: Print three lines of stats using a single System.out.println call. Use \n inside the string to create line breaks. Use + to concatenate parts together if the line gets long.

Expected output:

Intelligence: 99
Determination: 100
Charm: Over 9000

All three lines above must come from one println call. For example:

System.out.println("Intelligence: 99\nDetermination: 100\nCharm: Over 9000");

What the test checks: Exactly one println call produces three lines. The test counts println invocations in your source code for this section.

Run your tests one more time:

./gradlew test

Debugging tip: If you see all three stats on one line, your \n might be wrong. Make sure you’re using \n inside double quotes ("..."), not single quotes.


How to Debug

  1. Read the diff. When a test fails, Gradle prints the expected and actual output. Read both lines carefully. The problem is usually a missing space, wrong punctuation, or extra blank line.

  2. Compile before you test. Run javac Hello.java (or ./gradlew build) and fix all compilation errors before running tests. A missing semicolon or unclosed quote produces a wall of errors — fix the first one and recompile.

  3. Use the exact strings. Autograder tests compare your output character by character. Do not paraphrase, reorder, or “improve” the expected text. Copy it exactly from the lab specification.


Submitting Your Work

Once all three checkpoints pass locally, it’s time to submit. You’ll do this with Git, right from the terminal in VS Code.

  1. Save your file. Press Ctrl+S (or Cmd+S on Mac). Unsaved changes won’t be committed.

  2. Stage your changes. In the terminal, run:
    git add .
    
  3. Commit your changes. This creates a snapshot of your work with a message:
    git commit -m "complete lab 01"
    
  4. Push to GitHub. This uploads your commit so the autograder can see it:
    git push
    
  5. Check your results. Go to your repository on GitHub and click the Actions tab. You’ll see your submission being tested. A green checkmark means all tests passed. A red X means something failed — click into it to see which test and why.

Green checkmark = you’re done. That’s your confirmation that your lab is submitted and passing. If you see a red X, read the error, fix your code, and push again. You can push as many times as you want before the due date.


Scoring

Component Points Criteria
Checkpoints 3 1 pt each. Binary: the checkpoint test passes or it does not.
Autograder 5 Correctness across all test cases. Partial credit by proportion of tests passed.
Timeliness 2 Full credit if submitted by the due date. 0 if late.
Total 10