← Back to Week 1 Hub
Method Practice
Four small programs that each practice a different aspect of writing methods
Workbook 1c, p.117-118 — Project name: method-practice
In Plain English
This exercise has 4 small programs, each in its own file. Each one practices a different part of writing methods:
void methods (no return), reusable methods (call the same method twice), methods that return a String, and methods that return a boolean.
Tip: Each file is a separate class with its own main method. You can run and test them independently.
What a Successful Run Looks Like
Hello.java
Console Output
Hello, World!
Goodbye!
Good morning!
Menu.java
Console Output
=== MENU ===
1. Coffee - $3.99
2. Tea - $2.99
3. Cookie - $1.99
=== MENU ===
1. Coffee - $3.99
2. Tea - $2.99
3. Cookie - $1.99
Format.java
Console Output
Smith, Bob
Johnson, Alice
CompareNumbers.java
Console Output
false
true
false
true
Note: Each file runs separately. You should get exactly the output shown above for each one.
What This Exercise Practices
This exercise reinforces these concepts from Week 1:
Why this matters: Methods are how you organize code into reusable pieces. This exercise builds the habit of writing small, focused methods — void vs. return, no parameters vs. parameters, String returns vs. boolean returns.
Flow Diagram
Hello.java
main()
entry point
→
sayHello()
prints greeting
→
sayGoodbye()
prints farewell
→
sayGoodMorning()
prints morning
Menu.java
main()
entry point
→
displayMenu()
prints menu
→
displayMenu()
called again
Format.java
main()
entry point
→
formatName("Bob","Smith")
returns String
→
prints result
"Smith, Bob"
CompareNumbers.java
main()
entry point
→
isEven(5)
returns boolean
→
prints result
false
→
isPositive(-3.5)
returns boolean
→
prints result
false
Each file practices a different method pattern. Master all four and you'll be ready for any method the course throws at you.