Workbook 4.1
From the Java Bootcamp Resources
, launch the Workbook 4.1
folder.
Bart's detention.
Bart's teacher wants him to write lines on the chalkboard.
He needs to write this paragraph 6 times:
I will not copy and paste code.
I will use Camel Case when writing class names.
I will use lower Camel Case when writing function names.
I will use lower Camel Case when writing variables names.
Bart wrote the paragraph once, but it took him a long time!
public class Detention {
public static void main(String[] args) {
//what Bart did so far
System.out.println("I will not copy and paste code.");
System.out.println("I will use Camel Case when writing class names.");
System.out.println("I will use lower Camel Case when writing function names.");
System.out.println("I will use lower Camel Case when writing variables names.");
}
}
>> I will not copy and paste code.
>> I will use Camel Case when writing class names.
>> I will use lower Camel Case when writing function names.
>> I will use lower Camel Case when writing variables names.
Task 1 - Write a function
Help Bart write a function that does the task for him. The doc comment will guide you.
/**
* Function name: printLines
*
* Inside the function:
* 1. prints the four lines
*/
A doc comment is embedded inside /** ... */
. They're best at describing the function name, parameters, and return value.
- The name of the function is
printLines
.
/**
* Function name: printLines <--
*
* Inside the function:
* 1. prints the four lines
*/
-
The comment says nothing about parameters, so you can assume it doesn't take any.
-
The comment says nothing about a return value. So, you can assume the function is
void
. -
Inside the function, it prints the four lines.
/**
* Function name: printLines
*
* Inside the function:
* 1. prints the four lines <--
*/
The doc comment outlines everything you need to make your function.
Task 2 - Call the function
Once you finish writing it, call the function six times from main()
.
Run your code.
>>I will not copy and paste code.
>>I will use Camel Case when writing class names.
>>I will use lower Camel Case when writing function names.
>>I will use lower Camel Case when writing variables names.
>>I will not copy and paste code.
>>I will use Camel Case when writing class names.
>>I will use lower Camel Case when writing function names.
>>I will use lower Camel Case when writing variables names.
>>I will not copy and paste code.
>>I will use Camel Case when writing class names.
>>I will use lower Camel Case when writing function names.
>>I will use lower Camel Case when writing variables names.
...
Visualizing the Runtime
After you solve this workbook, I still recommend watching the video solution on Udemy.
It will show you how to visualize the runtime using Visual Studio Code.