• Next, the program should present the user with an input box requesting him to type a letter indicating the make (manufacturer) of the car for which the mats are being purchased. Mats-R-Us only sup¬plies mats for three different makes of cars, and those are the options that should be offered. The available options are to be: A = Acura, B = BMW, and M = Mercedes. The program should accept any of these single letters, whether typed in lowercase or uppercase. If the user enters any data other than these three letters, the program should display a message box indicating to the user that the data entered was invalid. Program execution should then end. (Hint: P. 92 in the textbook describes how a program that utilizes the JOptionPane class can be ended.) (Note: In a “real” application program, we would want to let the user try again to input the data correctly but, for now, we will accept this simple approach to dealing with incorrect data entry. There are other places in this program’s execution, described below, where we will make use of this simple program ending approach again.)
• Next, the program should present the user with an input box requesting the user to type a character indicating the model of the car for which the mats are being purchased. The options that are to be presented to the user in this dialog box will depend on the user’s selection of vehicle make in the previous dialog box. For Acura, the model options are to be: X = TSX, R = RL, and T = TL. For BMW, the model options are to be: 3 = 3-Series, 5 = 5-Series, 7 = 7-Series. For Mercedes, the model options are to be: C = C-Class, E = E-Class, and S = S-Class. The program should accept any of these characters, whether typed in lowercase or uppercase. Again, the user is to be presented only the options specific to the car make that he has already selected.
CODE
// Display prompt and get input for mat choice
JOptionPane.showMessageDialog(null, "There are only three types of mats: A = Acura, B = BMW, and M = Mercedes");
String mat;
mat=
JOptionPane.showInputDialog("A = Acura, B = BMW, and M = Mercedes.\n Enter your mat choice:");
String input; // To hold the user's input
String (char);
char A = Acura;
char B = BMW;
char M = Mercedes;
input = JOptionPane.showInputDialog("A = Acura, B = BMW, and M = Mercedes.\n Enter your mat choice:");
if (A)
JOptionPane.showMessageDialog("You have choosen= Acura");
}}
*edit: Please use code tags in the future, thanks!
STUCK AT THIS POINT HELP ANYONE???? THANKS NEVER TOOK PROGRAMMING BEFORE!
This post has been edited by Martyr2: 6 Feb, 2008 - 12:10 PM