Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-22-2008, 04:26 AM
Member
 
Join Date: Nov 2008
Posts: 32
Rep Power: 0
hungdukie is on a distinguished road
Question [SOLVED] Using dialog boxes and switch statements question
I'm a newb to Java and doing my best to learn on my own, without much help but the book I have is tough to figure out. If anyone could help me out I would surely appreciate it. I am doing a Lab exercise where I am expected to write a program to display a dialog box to the user asking what their choice of three models of televisions will be. They are to enter the model number: 100, 200, or 300. I am to write a switch structure that will, based on their selection, display in a dialog box their choice along with the feature set and price of the model they chose. I have started my code but I checked after the first case to see how it would compile and I am getting the following message:
Quote:
Tvs.java:31: cannot find symbol
symbol : variable output
location: class Tvs
output.Str = "You chose model " + model + "TV with these features:" + "\n"
I am not sure why I am getting this message unless I am not declaring a variable that I'm supposed to, but I really don't know how I should declare one for the output string.
Here is my code:
Code:
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;

public class Tvs
{
public static void main(String[] args)
{

String inputStr;
String outputStr;
int model;
inputStr = JOptionPane.showInputDialog
			  ("This program asks the user to enter a television model number." +"\n"	
			  + "The description of the model chosen will be displayed" + "\n"
			  + "\n"
			  + "\n"
			  + "Please enter the model chosen" + "\n"
			  + "Model 100 comes with remote control, timer," + "\n"
			  + "and stereo sound and costs $1000" + "\n"
			  + "Model 200 come with all features of model 100" + "\n"
			  + "and picture-in-picture, and costs $1200" + "\n"
			  + "Model 300 comes with all features of model 200 and" + "\n"
			  + "HDTV, flat screen, 16x9 aspect ratio and costs $2400" + "\n");


			  
			  switch (model)
			  {
			  case 100:
			  	output.Str = "You chose model " + model + "TV with these features:" + "\n"
				+ "Remote control, timer, and stereo sound" + "\n"
				+ "Your price will be $1000.00" + "\n";
JOptionPane.showMessageDialog(null, outputStr,
					   "Television Selection",
						JOptionPane.INFORMATION_MESSAGE);
			   case 200: 					
				} 
			  }
			  }

Last edited by hungdukie; 11-22-2008 at 04:31 AM. Reason: forgot to mark thread as a question
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-22-2008, 05:21 AM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 451
Rep Power: 2
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Default
The output variable was not initialized ,you didn't declare it at all.
instead of this
Code:
output.Str = "You chose model " + model + "TV with these features:" + "\n"
				+ "Remote control, timer, and stereo sound" + "\n"
				+ "Your price will be $1000.00" + "\n";
type this

Code:
outputStr = "You chose model " + model + "TV with these features:" + "\n"
				+ "Remote control, timer, and stereo sound" + "\n"
				+ "Your price will be $1000.00" + "\n";
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-22-2008, 05:30 AM
Member
 
Join Date: Nov 2008
Posts: 32
Rep Power: 0
hungdukie is on a distinguished road
Default Declare all variables!
Yes, I figured out that that was the problem. I declared and initialized the variable and voila! It compiles and runs like ti is supposed to. If I did something incorrectly I would appreciate any feedback you all might have.
Thanks.
I will post my code in the hopes that it may help someone else:
Code:
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;

public class Tvs
{
public static void main(String[] args)
{

String inputStr;
String outputStr;
int model;
inputStr = JOptionPane.showInputDialog
			  ("This program asks the user to enter a television model number." +"\n"	
			  + "The description of the model chosen will be displayed" + "\n"
			  + "\n"
			  + "\n"
			  + "Please enter the model chosen" + "\n"
			  + "Model 100 comes with remote control, timer," + "\n"
			  + "and stereo sound and costs $1000" + "\n"
			  + "Model 200 come with all features of model 100" + "\n"
			  + "and picture-in-picture, and costs $1200" + "\n"
			  + "Model 300 comes with all features of model 200 and" + "\n"
			  + "HDTV, flat screen, 16x9 aspect ratio and costs $2400" + "\n");
			  model = Integer.parseInt(inputStr);




			  
			  switch (model)
			  {
			  case 100:
			  	outputStr = "You chose model " + model + " TV with these features:" + "\n"
				+ "Remote control, timer, and stereo sound" + "\n"
				+ "Your price will be $1000.00" + "\n";
JOptionPane.showMessageDialog(null, outputStr,
					   "Television Selection",
						JOptionPane.INFORMATION_MESSAGE);
						break;
			   case 200:
			  	outputStr = "You chose model " + model + " TV with these features:" + "\n"
				+ "Remote control, timer, stereo sound and picture-in-picture" + "\n"
				+ "Your price will be $1200.00" + "\n";
JOptionPane.showMessageDialog(null, outputStr,
					   "Television Selection",
						JOptionPane.INFORMATION_MESSAGE);
						break;
				case 300:
				 outputStr = "You chose model " + model + " TV with these features:" + "\n"
				+ "HDTV, flat screen, 16x9 aspect ratio" + "\n"
				+ "picture-in-picture,"  + "\n"
				+ "remote control, timer, and stereo sound" + "\n"
				+ "Your price will be $2400.00" + "\n";
JOptionPane.showMessageDialog(null, outputStr,
					   "Television Selection",
						JOptionPane.INFORMATION_MESSAGE);
						break;				
 					
				} 
			  }
			  }
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] JOptionPaneMessage dialog question blueyan New To Java 2 09-28-2008 07:50 AM
Help! Need to randomly assign boxes newb101 New To Java 1 09-16-2008 10:57 PM
Need help - using algorithm statements javanewbie New To Java 2 07-23-2008 11:20 AM
avoiding if statements valoyivd New To Java 1 04-02-2008 09:08 AM
Help with if else statements zoe New To Java 1 07-24-2007 07:56 PM


All times are GMT +2. The time now is 03:23 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org