๐ฏ Unit 2 Activities
Table of Contents
๐ป ACTIVITY PROGRAM SETUP INSTRUCTIONS
- Go to the public template repository for our class: BWL-CS Java Template
- Click the button above the list of files then select
Create a new repository
- Specify the repository name:
CS2-Unit2-Activity#
Replace
#
with the specific activity number. - Click
Now you have your own personal copy of this starter code that you can always access under the
Your repositories
section of GitHub! ๐ - Now on your repository, click and select the
Codespaces
tab - Click
Create Codespace on main
and wait for the environment to load, then youโre ready to code!
๐ When class ends, donโt forget to SAVE YOUR WORK! Codespaces are TEMPORARY editing environments, so you need to COMMIT changes properly in order to update the main repository for your program.
There are multiple steps to saving in GitHub Codespaces:
- Navigate to the
Source Control
menu on the LEFT sidebar - Click the button on the LEFT menu
- Type a brief commit message at the top of the file that opens, for example:
updated main.py
- Click the small
โ๏ธ
checkmark in the TOP RIGHT corner - Click the button on the LEFT menu
- Finally you can close your Codespace!
๐ฎ ACTIVITY #1: Magic 8 Ball
Have you ever used a Magic 8 ball? You ask it a yes-no question and then shake it to get a random response like Signs point to yes!
, Very doubtful
, etc.
Try out this Magic 8 Ball Simulator
PART A:
Write a branching program in the main()
method that does the following:
- Choose a random integer from 1 to 10
To review generating random numbers, see ๐ 1.11: Math Class
- Come up with 10 possible responses to yes-no questions.
- Use if statements to test the number and print out a different response for each number.
- Use Math.random() to toss a coin to choose between 2 choices
- Use an if/else statement to test the random number and print out โLucky!โ or else โNo Luck!โ