Course: Introduction to Java Programming
Unit: Module 1 – Java Basics and Control Flow
Based on: Head First Java, 3rd Edition, Chapter 1
By the end of this unit, you will be able to:
- Write and run a basic Java program with a
mainmethod. - Declare and use variables of types
int,String, anddouble. - Write a
whileloop and aforloop to repeat actions. - Write
if/elseconditional statements to branch logic. - Use
System.out.print()andSystem.out.println()to display output. - Follow proper Java syntax rules (semicolons, curly braces, comments).
Complete the assigned reading before starting each activity. Links will be posted here by your instructor.
| Assignment | Reading |
|---|---|
| MyFirstApp – Java Syntax Practice | Link coming soon |
| Sharpen Your Pencil 1 – Easy Write Java | Link coming soon |
| Sharpen Your Pencil 2 – Conditional Branching | Link coming soon |
| BottleSong – Debug Activity | Link coming soon |
| PhraseOMatic – Coding Activity | Link coming soon |
This repository contains 5 assignments for Chapter 1. Complete them in order.
| # | File | Type | Description | Points |
|---|---|---|---|---|
| 1 | MyFirstApp.java |
Coding | Write a program using variables, loops, and conditionals from scratch using TODOs | 100 pts |
| 2 | 113_Look-How-Easy-It-Is-To-Write-Java_SharpenPencil1.md |
Written | Read Java code snippets and explain in plain English what each line does | 20 pts |
| 3 | 118_Conidtional-Branching_SharpenPencil2.md |
Written + Fill-in | Fill in missing values in the Doobee program and answer explanation questions | 20 pts |
| 4 | 119_Coding-A-Serious-Business-Application_Activity.md + BottleSong.java |
Debug + Written | Find and fix the flaw in the BottleSong program; answer reflection questions | 25 pts |
| 5 | PhraseOMatic.java |
Coding | Build the Phrase-O-Matic program step by step using guided TODOs | Ungraded / Practice |
Total Graded Points: 165 pts
In Chapter 1 of Head First Java, you learned that your code can tell the JVM to do three things:
| # | What it does | Syntax used |
|---|---|---|
| 1 | Do something | Declarations, assignments, method calls |
| 2 | Do something again and again | while loops, for loops |
| 3 | Do something under a condition | if/else statements |
Every Java statement ends with a semicolon (;). Classes and methods are wrapped in curly braces { }. Comments start with //.
You have been given a starter file — MyFirstApp.java — that contains the class structure and TODO comments. Your job is to fill in the code so that the program compiles and produces the correct output.
Task 1 – Variable Declarations and Assignments (25 pts)
Inside the main method, declare and assign the following variables:
- An
intnamedxwith a value of3 - A
Stringnamednamewith a value of"Dirk" - Multiply
xby17and store the result back inx - Print
"x is "followed by the value ofxusingSystem.out.print() - Declare a
doublenameddand assign it a random number usingMath.random() - Add at least one single-line comment (
//) explaining what one of your lines does
Task 2 – Loops (30 pts)
- Write a
whileloop that subtracts1fromxas long asxis greater than12 - Write a
forloop that startsiat0, runs whileiis less than10, and incrementsiby1each time- Inside the
forloop, print"i is now "followed by the value ofion its own line
- Inside the
Task 3 – Conditional Branching (30 pts)
- Write an
if/elsestatement that:- Prints
"x must be 10"ifxequals10 - Prints
"x isn't 10"otherwise
- Prints
- Write a second
ifstatement that prints"Gently"ifxis less than3ANDnameequals"Dirk"(use.equals()for String comparison) - After both conditionals, print
"this line runs no matter what"
Task 4 – Syntax Rules (15 pts)
Review your code and make sure:
- Every statement ends with a semicolon
- All blocks are closed with matching curly braces
- You have added at least three comments total across your code explaining what different sections do
- Your code compiles and runs without errors
x is 51i is now 0
i is now 1
i is now 2
i is now 3
i is now 4
i is now 5
i is now 6
i is now 7
i is now 8
i is now 9
x isn't 10this line runs no matter what
Note:
System.out.print()does not add a newline. OnlySystem.out.println()adds a newline.
See RUBRIC.md for the full grading breakdown.
Open 113_Look-How-Easy-It-Is-To-Write-Java_SharpenPencil1.md. For each Java code snippet, write a plain-English explanation of what the line does. Three answers are already filled in as examples. Replace every ___________ with your own explanation, then commit and push.
Open 118_Conidtional-Branching_SharpenPencil2.md. Fill in the two missing values in the Doobee program so it produces the correct output, then answer the four explanation questions. Commit and push when done.
Open BottleSong.java — it compiles and runs, but the output has a flaw. Open 119_Coding-A-Serious-Business-Application_Activity.md and follow the three parts: spot the flaw, fix the code, and answer the reflection questions. Push both files when done.
Open PhraseOMatic.java. Follow the five guided TODO steps to build a program that randomly generates business buzzword phrases. This is an ungraded practice activity — focus on getting it to compile and run.
- Accept this assignment via the GitHub Classroom link provided by your instructor.
- Clone your personal repository to your local machine:
git clone <your-repo-url>
- Work through the assignments in order (1 → 5).
- Compile and test any
.javafiles:javac FileName.java java FileName
- Commit and push your work regularly:
git add . git commit -m "Your message here" git push
| File | Description |
|---|---|
MyFirstApp.java |
Assignment 1 starter file |
113_Look-How-Easy-It-Is-To-Write-Java_SharpenPencil1.md |
Assignment 2 fill-in activity |
118_Conidtional-Branching_SharpenPencil2.md |
Assignment 3 fill-in activity |
118_Conidtional-Branching_SharpenPencil2.md |
Assignment 4 debug questions |
BottleSong.java |
Assignment 4 buggy starter file |
PhraseOMatic.java |
Assignment 5 guided coding starter |
RUBRIC.md |
Grading rubric for Assignment 1 |
README.md |
This file |
- Push all completed files to your GitHub Classroom repo before the deadline.
- Do not submit compiled
.classfiles — only.javaand.mdsource files will be graded. - All
.javafiles must compile without errors to receive full coding credit.
- Revisit the Syntax Fun box from Chapter 1 for a quick reference on rules.
- Use
String.equals()instead of==when comparing Strings. Math.random()returns adoublebetween0.0(inclusive) and1.0(exclusive).- If you get a compile error, read the error message carefully — it will tell you the line number.
Based on Head First Java, 3rd Edition by Kathy Sierra & Bert Bates (O'Reilly Media, 2022).