473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Checking for invalid data

1
This is my code....

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2. public class AdmissionsSpence
  3. {
  4.    public static void main(String[] args)
  5.    {
  6.     String entranceScore, gradePointAverage;
  7.     gradePointAverage = JOptionPane.showInputDialog(null, "Enter your G.P.A.");
  8.     entranceScore = JOptionPane.showInputDialog(null, "Enter your Entrance score");
  9.     FinalResults(entranceScore, gradePointAverage);
  10.     }
  11.     public static void FinalResults(String entranceScore,String gradePointAverage)
  12.     {
  13.  
  14.     double gPaverage;
  15.     int entScore;
  16.     gPaverage = Double.parseDouble(gradePointAverage);
  17.     entScore = Integer.parseInt(entranceScore);
  18.     if (gPaverage >= 3.0 && entScore > 60)
  19.     JOptionPane.showMessageDialog(null, "Congradulations!");
  20.     else if (entScore >= 85)
  21.     JOptionPane.showMessageDialog(null, "Congradulations!");
  22.     else 
  23.     JOptionPane.showMessageDialog(null, "Try again next year!");
  24.  
  25.     JOptionPane.showMessageDialog(null, "Invalid entry");
  26.     System.exit(0);
  27.     }
  28. }
  29.  
Now, I need to write some code to do some error checking of the data. That is, if the grade point average is not between 0.0 and 4.0 or if the entrance score is not between 0 and 100, then I need an appropriate error message to the screen telling the user that they entered invalid data. How would I go about this and where would I place the code, this is driving me nuts. I already have a JOptionPane.show.Message Dialog (null, Invalid entry); but nothing else.

Thank you
Feb 15 '10 #1
1 1801
chaarmann
785 Expert 512MB
Make an if-statement like the one that you already have inside your code, but with different values (condition).
Place it right before your first if-statement.
Place the error message inside this if-statement.
Feb 18 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: - ions | last post by:
I have created a JComboBox with its Items as a list of "M" numbers ie. M1,M2,M3.......throgh too M110 (thes are the messier objects, a catolouge of deep sky objects) the user selects of of these...
3
by: Guy Robinson | last post by:
I have the code below which parses an expression string and creates tokens. Can anyone suggest the best of error checking for things like: Valid variable only obj.attribute -whitespace allowed...
2
by: mike | last post by:
I had a form like below that validated that a file was there before it would submit. <form name="attach" method="POST" action="run_this_pgm.cfm" enctype="multipart/form-data"...
30
by: Michael B Allen | last post by:
I have a general purpose library that has a lot of checks for bad input parameters like: void * linkedlist_get(struct linkedlist *l, unsigned int idx) { if (l == NULL) { errno = EINVAL;...
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
28
by: romy | last post by:
What's the easiest way to verify the user had entered a valid date ?
6
by: Abubakar | last post by:
Hi, lets say I have a connected SOCKET s. At some point in time, I want to know if the "s" is still valid, that it is still connected. Is there any API that I can give me this information? And...
66
by: Johan Tibell | last post by:
I've written a piece of code that uses sockets a lot (I know that sockets aren't portable C, this is not a question about sockets per se). Much of my code ended up looking like this: if...
0
by: rdemyan | last post by:
Is there a way to check the validity of front-end table links on a backend file where all permissions to data have been revoked. To get at the data, the front end uses RWOP queries. What I'm...
3
by: w.m.gardella.sambeth | last post by:
Hi all, I am more or less new to Python, and currently am making my first "serious" program. The application is a Clinical History manager (for my wife) which stores its data on a sqlite database....
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.