473,394 Members | 1,841 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,394 software developers and data experts.

Please Help Me With While Loop & Cancel

Hey all, I would be delighted if someone could help me complete my coding,
im trying to make it able for the user to type in as many percentages and
display the coding for the grade as many times as they like using a WHILE
LOOP and making the LOOP end when the user hits cancel! I got most of the coding just need a small snippet to get it fully function - any help will be GREATLY appreciated

Expand|Select|Wrap|Line Numbers
  1. //here is so far:
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5. public class StudentGradesWeek7
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         String input = JOptionPane.showInputDialog("Enter The Student's Mark As A Percentage:");
  10.  
  11.         int inputMark = Integer.parseInt(input);
  12.  
  13.         char g = getGrade(inputMark);
  14.  
  15.         JOptionPane.showMessageDialog(null, "The Student's Grade Is " + g);
  16.     }
  17.  
  18.     private static char getGrade(int mark)
  19.     {
  20.         char grade;
  21.  
  22.         if (mark >= 70)
  23.         {
  24.             grade = 'A';
  25.         }
  26.         else if (mark >= 60)
  27.         {
  28.             grade = 'B';
  29.         }
  30.         else if (mark >= 50)
  31.         {
  32.             grade = 'C';
  33.         }
  34.         else if (mark >= 40)
  35.         {
  36.             grade = 'D';
  37.         }
  38.         else
  39.         {
  40.             grade = 'F';
  41.         }
  42.         return grade;
  43.     }
  44. }
  45.  
Nov 19 '08 #1
3 1455
r035198x
13,262 8TB
Where is the while loop that you were talking about?
Nov 19 '08 #2
Thats the bit i need the while loop and the cancel part i really dont know where to put it - but i do know how to do while loops
Nov 19 '08 #3
JosAH
11,448 Expert 8TB
Note that the showInputDialog(...) method returns null when the user has
canceled the menu; it's an excellent candidate for a while conditional expression:

Expand|Select|Wrap|Line Numbers
  1. while ((yourString= JOptionPane.showInputDialog( ... )) != null) {
  2.    // process the value of yourString
  3. }
  4.  
kind regards,

Jos
Nov 19 '08 #4

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

Similar topics

7
by: ssantamariagarcia | last post by:
I have found a problem while using a while statement and a linked list. I had never met this matter before....and I am wondering that if you have , please tell me what it is wrong. I am...
1
by: pauljturner99 | last post by:
Hi, I'm trying to pass a parameter from a for loop to the nested while loop but only the first counter is passed. Here is the code: dim ctr redim ctr(5) ctr(0) = 2 ctr(1) = 4 ctr(2) = 6
14
by: dawnerd | last post by:
Hi, I am developing a CMS and came across something which has never happened to me before, and I re-wrote the specific script twice, both differently, and still had the same error. I'm not sure...
13
by: israphelr | last post by:
Hi all. I have a problem with some code :( ----------- hint = raw_input("\nAre you stuck? y/n: ") hint = hint.lower() while (hint != 'n') or (hint != 'y'):
3
by: rmijares | last post by:
I am sure you guys have seen this before. I am working on the famous Employee Payroll program for a class assignment. In any case, the while loop at the end of the Employee class just keeps looping;...
2
by: jesmi | last post by:
when i put while loop, it never stops, it just trap in loop.but when i remove while loop, it will increment one by one, the month,year,week,day. but i need to put this code in while loop. please help...
4
by: devilsangels287 | last post by:
Hey guys I have a problem with this while loop, its not working properly and I think that I might be typing it wrong but I don't how. please help me! Thanks... Anyways this is a calculator which is...
2
by: John Hutchison | last post by:
Hey everybody, this is my first post, so I hope I'm doing this right. I'm just starting to learn how to program, so I'm sorry if my error is obvious, but I can't seem to find the answer. I...
0
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...
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
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
marktang
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,...
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
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.