Okay, I finally got this program to run according to what the book had us build it as. Now prof wants case 2 and case 3 to prompt again for input, check input to see if it is the correct type, then display a "correct" message if is correct.
So, If you choose 2 from the original pane, you would be prompted to enter an integer. The program would check to see if you input an integer and if it was then you would get a "correct" message. If not you would get an error message.
I have tried and tried to get this and I am out of time here. It does not go over this in my book and I have only had Java a few weeks now. PLEASE HELP if you can. I really really appreciate it!
Thanks -
-
import javax.swing.JOptionPane;
-
import java.io.*;
-
-
public class MyTypeafter
-
{
-
public static void main(String[] args) throws IOException
-
{
-
// declare and construct variables
-
String strChoice, strTryString, strTryInt, strTryDouble;
-
int choice, tryInt;
-
double tryDouble;
-
boolean done = false;
-
-
// loop while user does not click cancel button
-
while(!done)
-
{
-
try
-
{
-
String myMsg = "What's my Type?\n";
-
myMsg = myMsg + "1) String\n";
-
myMsg += "2) Integer\n";
-
myMsg += "3) Double\n";
-
myMsg += "4) Quit the Program\n";
-
-
strChoice = JOptionPane.showInputDialog(null, myMsg, "Input", JOptionPane.QUESTION_MESSAGE);
-
if(strChoice == null) break;
-
choice = Integer.parseInt(strChoice);
-
-
switch(choice)
-
{
-
case 1:
-
JOptionPane.showMessageDialog(null, "Correct, any input can be saved as a String");
-
break;
-
-
case 2:
-
JOptionPane.showMessageDialog(null, "Please enter an integer");
-
tryInt = Integer.parseInt(strChoice);
-
if (strChoice == integer)
-
{
-
JOptionPane.showMessageDialog("correct");
-
}//end if
-
break;
-
-
case 3:
-
JOptionPane.showMessageDialog(null, "Correct Double Value");
-
tryDouble = Double.parseDouble(strChoice);
-
break;
-
-
case 4:
-
done = true;
-
JOptionPane.showMessageDialog(null, "Now Closing");
-
break;
-
-
default:
-
throw new NumberFormatException();
-
-
}//end switch
-
-
}//end try
-
-
catch(NumberFormatException e)
-
{
-
String myMsg2 = "Error, problem with number format\n" + e;
-
JOptionPane.showMessageDialog(null, myMsg2, "Error", JOptionPane.INFORMATION_MESSAGE);
-
}//end catch
-
-
}//end while
-
-
}//end main method
-
-
}//end class
-
-
1 7404 - import javax.swing.JOptionPane;
-
-
public class MyType
-
{
-
-
public static void main(String[] args)
-
{
-
// declare and construct variables
-
-
-
-
int choice = 0;
-
int tryInt = 0;
-
double tryDouble = 0.0;
-
boolean done = false;
-
-
// loop while user does not click cancel button
-
String entered = "";
-
while(!done) {
-
try {
-
String strChoice = JOptionPane.showInputDialog(null,"What's My Type?\n1)String\n2)integer\n3)double\n4Quit the program\n");
-
if(strChoice == null) {
-
strChoice = ""+4;
-
}
-
choice = Integer.parseInt(strChoice);
-
switch(choice) {
-
case 1: {
-
entered = JOptionPane.showInputDialog(null,"Enter The String\n");
-
JOptionPane.showMessageDialog(null, "Correct, any input can be saved as a String");
-
break;
-
}
-
case 2: {
-
entered = JOptionPane.showInputDialog(null,"Enter The integer\n");
-
tryInt = Integer.parseInt(entered);
-
JOptionPane.showMessageDialog(null, "Correct");
-
break;
-
}
-
case 3: {
-
entered = JOptionPane.showInputDialog(null,"Enter The Double\n");
-
tryDouble = Integer.parseInt(entered);
-
JOptionPane.showMessageDialog(null, "Correct");
-
-
break;
-
}
-
case 4:
-
done = true;
-
JOptionPane.showMessageDialog(null, "Now Closing");
-
break;
-
default:
-
throw new NumberFormatException();
-
-
}
-
}
-
catch(NumberFormatException e) {
-
JOptionPane.showMessageDialog(null, "Please try again");
-
}
-
}
-
-
System.exit(0);
-
-
}
-
-
}
oops hope this is not too late!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dave |
last post by:
After following Microsofts admonition to reformat my system before doing a
final compilation of my app I got many warnings/errors upon compiling an rtf
file created in word. I used the Help...
|
by: Manjesh Gowda |
last post by:
Hi all,
I am maintaing a persistent HTTP connection using the "HTTP
CONNECT" method , this works fine for many proxies like Squid, ISA ,
etc. But the iPlanet proxy disconnects the conneciton...
|
by: wukexin |
last post by:
Help me, good men. I find mang books that introduce bit "mang header
files",they talk too bit,in fact it is my too fool, I don't learn it, I have
do a test program, but I have no correct doing...
|
by: Corepaul |
last post by:
Missing Help Files
When I enter "recordset" as the keyword and search the Visual Basic Help index,
I get many topics of interest in the resulting list. But there isn't any
information available...
|
by: Funky |
last post by:
Hi,
I have developed an ASP.NET application which has been running in
production for around 3 months without any major glitches. Recently, a
user was attempting to upload a rather large CSV file...
|
by: switzerland qunatium computer |
last post by:
HERE I BUILT A QUICK MATRIX TOOOK 5 MINS
Body: HERE I BUILD ONE FOR YOU
1.http://en.wikipedia.org/wiki/Real-time_computing
2.http://en.wikipedia.org/wiki/Quantum_computing
NOW ALL YOU NEED...
|
by: Mark |
last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my
home computer has an abbreviated help screen not 2% of the help on my laptop.
All the settings look the same on both...
|
by: JonathanOrlev |
last post by:
Hello everybody,
I wrote this comment in another message of mine, but decided to post it
again as a standalone message.
I think that Microsoft's Office 2003 help system is horrible, probably...
|
by: cbsGEM |
last post by:
I have a start and end date columns (date) and start and end time columns (varchar2).
I need to calculate the days, hours and minute between these 4 columns, I also have to exclude weekends and...
|
by: ashes |
last post by:
Hi all,
i am creating a website and i want to log out the user after 30 mins of inactivity. how do i do this using vb.net.
Also, if the user tries to login and not getting through. after 3...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |