Java Bootcamp – Workbooks and Challenges
)}

Workbook 4.1

From Java Bootcamp Resources -> Module 1 -> 4. Functions, open Workbook 4.1.

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.

   ...

Good Luck!


Feedback Summary
4.8
39 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.