0% found this document useful (0 votes)
36 views3 pages

Magic 8-Ball

Java Assignment

Uploaded by

hollybrigs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Magic 8-Ball

Java Assignment

Uploaded by

hollybrigs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Magic 8-Ball Author: Graham Mitchell

Filename: Magic8Ball.java
Files Needed

Magic8Ball.java

import java.util.Random;

public class Magic8Ball


{
public static void main ( String[] args )
{
Random r = new Random();

int choice = 1 + r.nextInt(15);


String response = "";

if ( choice == 1 )
response = "It is certain";
else if ( choice == 2 )
response = "It is decidedly so";
else if ( choice == 3 )
response = "Without a doubt";
else if ( choice == 4 )
response = "Yes - definitely";
else if ( choice == 5 )
response = "You may rely on it";
else if ( choice == 6 )
response = "As I see it, yes";
else if ( choice == 7 )
response = "Most likely";
else if ( choice == 8 )
response = "Outlook good";
else if ( choice == 9 )
response = "Signs point to yes";
else if ( choice == 10 )
response = "Yes";
else if ( choice == 11 )
response = "Reply hazy, try again";
else if ( choice == 12 )
response = "Ask again later";
else if ( choice == 13 )
response = "Better not tell you now";
else if ( choice == 14 )
response = "Cannot predict now";
else if ( choice == 15 )
response = "Concentrate and ask again";
else
response = "8-BALL ERROR!";

System.out.println( "MAGIC 8-BALL SAYS: " + response );


}
}

What You Should See


Your answers will probably be different than these. Actually, that's kind of the point.

MAGIC 8-BALL SAYS: It is decidedly so

MAGIC 8-BALL SAYS: Reply hazy, try again

MAGIC 8-BALL SAYS: Signs point to yes

What You Should Do on Your Own


Assignments turned in without these things will receive no credit.

1. The real Magic 8-Ball™ contains 20 responses, not 15. Change the code so that it picks a random number from 1-20, and add the following five
responses:
Don't count on it
My reply is no
My sources say no
Outlook not so good
Very doubtful

©2013 Graham Mitchell


This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy