using java program. Page Magic8Ball (20 points): DO NOT create another project,
ID: 3745311 • Letter: U
Question
using java program.
Page Magic8Ball (20 points): DO NOT create another project, we are going to add a new file to Project2. From the NetBeans File'menu select New File'. On the dialog box under File Type' select 'Java Main Class' and click 'Next. Create a main class with the name Magie8Ball, verify it is part of 'P the main method write a program that simulates the popular children's decision- making toy called the Magic 8 Ball. roject2' and click the Finish' button. In To do this, the program will first have to prompt the user to enter his or her question. The user's response should be "stored" in a String-type variable named response. Use the nextLine () method on your Scanner-type object to obtain the entire line of text entered by the user. Once the program has read the entire line of text entered by the user, the program should enerate a random number between 0 and 19, which represents the 20 responses which are possible for a Magic 8 Ball: . It is certain . It is decidedly so . Without a doubt . Yes definitely . You may rely on it .As I see it, yes . Most likely . Outlook good . Yes . Signs point to yes . Reply hazy try agairnExplanation / Answer
import java.util.Random;
import java.util.Scanner;
public class Magic8Ball {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
String question = sc.nextLine();//question to be entered by user
String response = "";//variable to store a response
Random generator = new Random();// random generator function
int number = generator.nextInt(20) + 1;//generating a random number between 1 and 20
switch (number) {//it will switch the number and generate required o/p
case 1:
response = "It is certain";
break;
case 2:
response = "It is decidedly so";
break;
case 3:
response = "Without a doubt";
break;
case 4:
response = "Yes definitely";
break;
case 5:
response = "You may rely on it";
break;
case 6:
response = "As I see it, yes";
break;
case 7:
response = "Most likely";
break;
case 8:
response = "Outlook good";
break;
case 9:
response = "Signs point to yes";
break;
case 10:
response = "Yes";
break;
case 11:
response = "Reply hazy, try again";
break;
case 12:
response = "Ask again later";
break;
case 13:
response = "Better not tell you now";
break;
case 14:
response = "Cannot predict now";
break;
case 15:
response = "Concentrate and ask again";
break;
case 16:
response = "Don't count on it";
break;
case 17:
response = "My reply is no";
break;
case 18:
response = "My sources say no";
break;
case 19:
response = "Outlook does not look so good";
break;
case 20:
response = "Very doubtful";
break;
default:
break;
}
System.out.println(response);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.