You will create a program that helps the user make a difficu
Solution
hope this will help
import javax.swing.* and java.awt.* etc..
import javax.swing.JOptionPane;
public class MakingDecisions {
public static void main(String[] args) {
String[] choices = {\"Monday\", \"Tuesday\",\"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"};
String dayPicked = (String)JOptionPane.showInputDialog(null, \"Pick a day:\", \"Days of the Week\", JOptionPane.QUESTION_MESSAGE, null, choices, choices[0]);
if (dayPicked == null)
{
JOptionPane.showMessageDialog(null, \"You didn\'t pick a day!\");
}
else //executes when a dayPicked has been a value.
{
//Note: For this switch to work it must be used with JDK7 (or higher)
//The string picked is used as a conparison against the case statements. When a match is found the code in that case block will be executed. If none of the //cases match the default case statement is triggered.
String funfact = \"\";
switch (dayPicked)
{
case \"Monday\":
funfact = \"McDonald\";
break;
case \"Tuesday\":
funfact = \"Burger King\";
break;
case \"Wednesday\":
funfact = \"wendy\'s.\";
break;
case \"Thursday\":
funfact = \"Taco Johns\";
break;
case \"Friday\":
funfact = \"KFC\";
break;
case \"Saturday\":
funfact = \"Hardees\";
break;
case \"Sunday\":
funfact = \"Sub-way\";
break;
default:
funfact = \"Something went wrong with picking a day of the \"
+ \"week as I\'m a default fact \"
+ \"that is no fun at all!\";
break;
}
JOptionPane.showMessageDialog(null, funfact);
}
//Options for Numbers between 1 and 12 input dialog
Integer[] oneToTen = {1,2,3,4,5,6,7,8,9,10,11,12};
//Input dialog box allowing the user to pick a day of the week.
Integer numberPicked = (Integer)JOptionPane.showInputDialog(null, \"Pick a Number:\"
, \"Numbers between 1 and 12\", JOptionPane.QUESTION_MESSAGE
, null, oneToTen, oneToTen[0]);
//Use an if then else statement to see if the user picks a number.If picked has a null value it means the input dialog box was closed
//either by pressing cancel or by using the close \'x\' button.
if (numberPicked == null)
{
JOptionPane.showMessageDialog(null, \"You didn\'t pick a number!\");
}
else //executes because numberPicked has a value.
{
//turn the Integer object into a simple int value.
int choice = numberPicked.intValue();
String xmasSong = \"\";
String day = \"\";
//The int chosen is used as a conparison against the case statements. When a match is found the code in that case block will
//be executed. If none of the cases match the default case statement is triggered.
switch (choice)
{
case 1:
day = \"first\";
xmasSong = \"A partridge in a pear tree.\";
break;
case 2:
day = \"second\";
xmasSong = \"2 Turtle Doves\";
break;
case 3:
day = \"third\";
xmasSong = \"3 French Hens\";
break;
case 4:
day = \"fourth\";
xmasSong = \"4 Calling birds\";
break;
case 5:
day = \"fifth\";
xmasSong = \"5 Gold Rings\";
break;
case 6:
day = \"sixth\";
xmasSong = \"6 Geese-a-laying\";
break;
case 7:
day = \"seventh\";
xmasSong = \"7 Swans-a-Swimming\";
break;
case 8:
day = \"eigth\";
xmasSong = \"8 Maids-a-Milking\";
break;
case 9:
day = \"nineth\";
xmasSong = \"9 Ladies Dancing\";
break;
case 10:
day = \"tenth\";
xmasSong = \"10 Lords-a-Leaping\";
break;
case 11:
day = \"eleventh\";
xmasSong = \"11 Pipers Piping\";
break;
case 12:
day = \"twelveth\";
xmasSong = \"12 Drummers Drumming\";
break;
default:
day = \"special day\";
xmasSong = \"ferrari\";
break;
}
JOptionPane.showMessageDialog(null, \"On the \" + day + \"day of \" + \"Christmas.\ \" + xmasSong);
}
}
}


