Java Bootcamp – Workbooks and Challenges
)}

Workbook 4.4

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

Drawing with Java


The user can choose to draw a butterfly, elephant, bear, or snake.

System.out.print( "\nWhich animal would you like to draw?\n" );
System.out.println( "Write 1 for butterfly " );
System.out.println( "Write 2 for elephant  " );
System.out.println( "Write 3 for bear      " );
System.out.println( "Write 4 for snake     " );

Task 1: Pick up the user's choice.


Using Scanner, pick up the user's choice.

Task 2: Write a function


  • Function name.
/** * Function name: draw <----- * @param choice: (int) * * Inside the function: * - Based on the choice, draw: * 1. a butterfly * 2. elephant * 3. bear * 4. snake */
  • Parameters.
/** * Function name: draw * @param choice: (int) <----- * * Inside the function: * - Based on the choice, draw: * 1. a butterfly * 2. elephant * 3. bear * 4. snake */
  • Return value: void.

  • Inside the function, draw one of the animals based on the user's choice.

/** * Function name: draw * @param choice: (int) * * Inside the function: <--------- * - Based on the choice, draw: * 1. a butterfly * 2. elephant * 3. bear * 4. snake */

The drawing of each animal is inside your workbook.

Task 3: Call the function


Call the function from main().

Run your code


Based on the user's choice, the output should draw an animal.

Good Luck!


Feedback Summary
4.8
38 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.