Workbook 4.4
From the Java Bootcamp Resources
, launch the Workbook 4.4
folder.
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.
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.
Associated Course: The Complete Java Development Bootcamp
Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer
Feedback Summary
4.7
43 students
5
91%
4
2%
3
0%
2
0%
1
7%
Written Reviews
There are no written reviews yet.