Jackie: A couple of things, firstly what is it aobut this that is giving you a problem? You asked for help did not tell anyone what it is that you actually need help with, did it compile? Does it run and not give the correct output? A couple of things in looking at your code: The nested if statements, don't appear to be contained in a method. The entire expression of the if statement should be within the ( ). It appears that you are doing an assignment as opposed to a comparison, all of your if statements have a single = in them. The catch statement appears to be within the try statement. you need to close the try statement before you can begin your catch. You second set of if statements are all else-if so as soon as one is found to be true it is executed and the rest are not - think about that and then look at what you are testing for in the statement. One other tip, if you post a lot of code like this it is easier to read if you use the UBB code tags Hope some of this helps
Hi, Welcome to JavaRanch, and please don't cry -- it makes the moose nervous. First, all the code below "//Nested If statements" and above "//End of more if statements" needs to be inside a method, but isn't. Maybe you mean it to be inside the init() method? But there's a closing brace for init() right after the addActionListener() call. I'm not sure where you want this code to be. It doesn't belong in init(), I guess, because it looks like it depends on the user having typed in some information. Does it all belong inside the actionPerformed method? Second, that same chunk of code uses several variables (Code and Average, Grade and ClassStandCode) which aren't defined anywhere. I'm not sure what you want to do with them, so I don't know if they should be declared as local variables in the method you end up moving this code to, or as member variables in the class, but all of those have to be declared somewhere. Third, you're committing the most heinous of all Java crimes -- the empty catch block. This is a terrible, terrible habit to get into. You're telling Java "if something goes wrong, just fail mysteriously -- don't tell me what went wrong." After "catch(NumberFormatException e)" you always at least want a "System.out.println(e)" so the error message is displayed somewhere. Now, there's more stuff going on here, but hopefully this is a starting point. Try to incorporate these comments, then come back and ask some more specific questions. Oh, one more thing: use the UBB "[CODE]" tags around your code so that the formatting is preserved; good formatting makes code much easier to read. Click on "What is UBB Code?" while editing your message for an explanation. Hope this helped.
what I am wanting is to put a name in, a grade in numeric form(but come out in A,B,C, or F) and if they choose 1,2,3,4 display freshmen(if 1is chosen)etc. all in an applet. I tried it other ways. tis code won't compile that is why I am so frustrated. there are 20 guys in my class and I am the only girl. Some of them have already got it to wotk, but they won't tell me how, I have to be better than they are to keep them from being so mean to me. thank you
Joined: May 10, 2001
Jackie OK, lets take this step by step. Did you try to compile just the code for the applet to display itself? Take out all of the other code and logic and make sure you at least get the applet to display. ...... OK, now that applet displays lets add things one thing at a time and then make sure they work. For your button to work you need to add an ActionListener, since your applet itself extends ActionListener you can use it to receive the events from the button. Something like this: calcButton.addActionListener(this); Now, when someone clicks the button the event will be sent to your applet class to the ActionPerformed method. Just to make sure it works correctly go ahead and implement the method to just clear the name they entered from the text field. Something like: studentNameField.setText(""); Now compile it, run it, enter some text and clcik the button. the text should disappear. ... OK, now you can start to implement the actual functionality you need. I assume you need to get all of this info and do the conversions you mentioned then redisplay it. You'll have to get the name and save it to redisplay it. Get the numeric grade they entered and convert it to a letter grade. See my comments on your tests and Ernests comments and create a method (or a block of code in the action handler) to do this. Save the letter value. Now do the same type of thing with the type of student, get the value and convert it to Freshman, sophmore, etc. Take all of these values you get and redisplay them however you need to. I left this deliberately obscure so you can actually do the work yourself, if you get stuck at a cetain point just post the code you've got and we'll give you a hand. As far as the guys in your class being mean to you, well that just ain't right. They could at least give you some tips or an idea of how they did it. You go ahead nad send them around here and we'll learn 'em on how to treat a fellow programmer. Hope this helps
I would suggest doing a smaller example of what you want. You have too much code to start out. Write small chunks of code, make sure they compile and move on from there. Having small pieces of code also makes it easyer to understand the error messages (because you get less of them).
And stop stressing about the gender thing. (Don't worry about it.) [ November 11, 2003: Message edited by: William Barnes ]
Please ignore post, I have no idea what I am talking about.