- This event has passed.
7 PM – Intro to Java – Sebastian
May 13 @ 7:00 pm - 8:00 pm
Today We Did
- Learned about Java methods
- Learned about the difference between static and non-static methods by looking back at Python’s “self” parameter we had to put in all our methods inside a class.
- Learned how to generate a random number
- AYC Logic’s observed holidays: https://www.ayclogic.com/observed-holidays/
- In case you need anything, feel free to email me at sebastian@ayclogic.com
Homework
- Please submit your homework into your Google Drive
- Homework: Magic 8 ball, but this time in Java. I tried to re-explain it below, but here’s the original Python prompt in case that makes more sense to you (but either way, we’re doing this in Java!): https://www.ayclogic.com/intro-to-python/magic-8-ball/.
- First, create a list containing the following words:“yes”, “no”, “maybe”, “absolutely”, “I don’t think so”, “try again later”, “Cencentrate and ask again”, “My reply is no”
Hint: You can copy/paste this directly into a method which turns this into a list, look back at your notes to find it.
- Next, ask for user input using Scanner
- Then create an infinite loop using while loops (same syntax as we’re used to, but remember to put parenthesis around true!) example:while (true) {
} - Inside our while loop, generate a random number and save it into a variable (make sure it has a good name).
- Ask the user to ask you a yes or no question
- Take in user input using scanner and store inside a string (make sure it has a good name).
- If the user says “stop”, break out of the while loop using the same keyword as in Python (just “break”).
- Otherwise, use the random number we previously generated to print out a random element from our list
- First, create a list containing the following words:“yes”, “no”, “maybe”, “absolutely”, “I don’t think so”, “try again later”, “Cencentrate and ask again”, “My reply is no”
- If everything is working correctly, your program should act like this: You first make a list with all possible responses, then ask the user to ask you questions, allowing the user to stop if they say “stop”, otherwise you print out a random response from the list we made.