Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can please fix / evaluate my java code so that it continues to generate random prizes until the user decides to select quit. It currently

Can please fix/evaluate my java code so that it continues to generate random prizes until the user decides to select quit. It currently will not generate a new vacation it insteads repeats the same one over and over and it also loops for a limited number of times when it should keep going until the user decides to quit.
import java.util.*;//RANDOM CLASS
import javax.swing.*;//JOPTIONPANE
import java.io.*;//CLASS FILE TO TEST VISIBILITY
public class ChooseAPrize
{
public static void main(String[] args)
{
String[] islands ={ "Bermuda", "Bahama", "Jamaica", "Aruba",
"Martinique", "Antigua" };
String[] activities ={"parasailing","surfing", "snorkeling",
"DeepSeaFishing", "sailBoarding", "sharkSpotting",
"JetSkiing","scubaing", "shipwreck"};
ImageIcon prize_png= new ImageIcon("icons/prize.png");
JOptionPane.showMessageDialog(null,
"This program will randomly generate"
+ "a grand prize"+"
"
+" that includes a trip to a carribean island and a "+
"
"
+ "two day pass for a specific island related activity"+"
"+"
"
+"Click on"
+" 'Okay' to see your next prize!!","Welcome to the prize chooser "
+ "presented by ",JOptionPane.DEFAULT_OPTION,
prize_png);
Random randGen=new Random();
int island= randGen.nextInt(islands.length);
int activity=randGen.nextInt(activities.length);
String activityFile="icons/"+ activities[activity]+".png";
File iconFile= new File(activityFile);
if(!iconFile.exists())
System.out.print("
cant see the file -"+activityFile);
else
System.out.print("
Can see the file -"+activityFile);
String[] options={"Get another Trip","Quit"};
ImageIcon icon=new ImageIcon(activityFile);
String text="
on "+islands[island]+"";
int choice=JOptionPane.showOptionDialog(null,text,"Your Prize presented"
+"",0,1,icon,options, options[0]);
ImageIcon trip_png= new ImageIcon("icons/Trip.png");
while (true)
{
if(choice==0)
JOptionPane.showOptionDialog(null,text,"Your Prize presented"
+"",0,1,icon,options, options[0]);
else
JOptionPane.showMessageDialog(null,"Enjoy your prize program ending"
,"Thank you for playing!!",JOptionPane.DEFAULT_OPTION,trip_png);
break;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

Describe the main features of the VSEPR model.

Answered: 1 week ago