Created
June 4, 2020 23:03
-
-
Save smnatale/010c779b126ec350a8fa2ff289a28ee2 to your computer and use it in GitHub Desktop.
Codecademy Challenge - Magic 8 Ball 'Game'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Random; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| public class Magic8{ | |
| // Magic 8 Ball usually has a 20 sided dice inside with 10 positive dice sides, 5 negative dice sides and 5 vague responses | |
| // Below defines positive/negative/vague responses | |
| ArrayList<String> positiveResponses = new ArrayList<String> (Arrays.asList("As I see it yes", "It is certain", "It is decidedly so", "Most likely", "Outlook good", "Signs point to yes", "Without a doubt", "You may rely on it", "Yes definitely", "Absolutely")); | |
| ArrayList<String> negativeResponses = new ArrayList<String> (Arrays.asList("Definitely not", "Outlook not so good", "Very doubtful", "My sources say no", "Don't count on it")); | |
| ArrayList<String> vagueResponses = new ArrayList<String> (Arrays.asList("Ask again later", "Better not tell you now", "Cannot predict at this moment in time", "Concentrate and ask again", "Why are you asking me?")); | |
| // Below generates a random number from 0-19 | |
| public int randomNumber(){ | |
| Random rand = new Random(); | |
| int randomRoll = rand.nextInt(20); | |
| return randomRoll; | |
| } | |
| public static void main(String[] args){ | |
| Magic8 roll = new Magic8(); | |
| // Below defines a new ArrayList which has all reponses combined in one ArrayList | |
| ArrayList<String> allResponses = new ArrayList<String>(); | |
| allResponses.addAll(roll.positiveResponses); | |
| allResponses.addAll(roll.negativeResponses); | |
| allResponses.addAll(roll.vagueResponses); | |
| int response = roll.randomNumber(); | |
| System.out.println("Let me think about that one...\n \n" + allResponses.get(response)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment