-
February 21st, 2010, 09:12 PM
#1
a little JOptionPane Help?
hey fellas I am brand new to both java programming and codeguru. I have been working on a program for a few hours. and have continually failed to finish it, and was wondering if you guys could help me out.
so far I have written:
import javax.swing.JOptionPane;
public class GetOption {
public static void main(String[] args) {
String input = "";
String str;
str = "Would You Consider Yourself:\r\n\r\n" "a: A Beginner\r\n"
"b: Experienced\r\n" "c: An Expert\r\n\r\n" "Enter a, b, or c:";
do {
input = JOptionPane.showInputDialog(null, str);
if (input != null
&& (input.equalsIgnoreCase("a") || input.equalsIgnoreCase("b") || input
.equalsIgnoreCase("c"))) {
break;
} else {
JOptionPane.showMessageDialog(null, "You must use abc.");
}
} while (true);
// * now use the information in the input variable!
int dollarsPerHour = 0;
if (input.equalsIgnoreCase("a")) {
dollarsPerHour = 10;
} else if (input.equalsIgnoreCase("b")) {
dollarsPerHour = 15;
} else if (input.equalsIgnoreCase("c")) {
dollarsPerHour = 20;
}}}
however, how should I go about adding an input dialog box that then asks how many hours the user worked? and then based on this answer, shows an information dialog box that says:
"(the amount of hours the user just input) at $(the rate shown depending on if the user chose 1, 2, or 3 earlier) makes $(the sum of: the amount of hours the user imput * the rate the user gets depending on if they chose 1 2 or 3)"
haha i know it's kinda complicated and I am completely lost as to how to finish this program.
any and all help would be greatly appreciated!
thanks again,
-Mark
-
February 21st, 2010, 09:21 PM
#2
Re: a little JOptionPane Help?
You've already used an input dialog so why can't you add another one to ask how many hours the user has worked? What specifically are you stuck with?
-
February 21st, 2010, 09:25 PM
#3
Re: a little JOptionPane Help?
i am stuck with the part where i put everything together, I cant really visualize how it looks/is when it all comes together, nor do I know how to put into the code, like, the rate if a user wrote a instead of b or c instead of a or vice versa since depending on what that earlier imputs are is what I need the end to be.
could you perhaps show me how you would write it? i book am i have on this stuff is not helping me at all in applying its examples.
-
February 21st, 2010, 09:35 PM
#4
Re: a little JOptionPane Help?
If I write it for you you won't learn anything. If you are stuck with how it all hangs together then you clearly haven't done sufficient analysis and design before trying to code it.
Rather than thinking about how to code it, think about how you would do it if you had to ask someone these questions. It might be easier to visualise if you imagine a scenario where the only communication is via cards with the questions/messages written on them and you react accordinging to the answer the user points to. Once you have worked out the flow of execution then you should be able to translate it to code.
-
February 21st, 2010, 09:40 PM
#5
Re: a little JOptionPane Help?
i appreciate your concern, and this being my second program ever written I would appreciate if you could write it out if it didnt take more than 5 minutes, so that I can check my text and the answer and visualize and understand how this practice problem is meant to be written in the future.
i have been working on this for a while and I just dont see how putting this all together could be so simple?
thanks again for at least responding to my thread.
-
February 21st, 2010, 10:00 PM
#6
Re: a little JOptionPane Help?
Believe me, having someone else write the code is not going to help you. Writing the code is easy, it's solving the problem that is difficult.
Do as I said in my last post, writing out each step as you go. Once you have a list of steps if you're still stuck show your list and I'll explain how to go from there to code
-
February 21st, 2010, 10:22 PM
#7
Re: a little JOptionPane Help?
-
July 23rd, 2011, 06:27 AM
#8
Re: a little JOptionPane Help?
You are right kiang to visualize anything is easier rather than thinking about the code
-
July 23rd, 2011, 06:41 AM
#9
Re: a little JOptionPane Help?
Originally Posted by Moriene
You are right kiang to visualize anything is easier rather than thinking about the code
Maybe you could visualize a working link next time...
Fixed that for you
Testing can show the presence of errors, but not their absence...
E. Dijkstra
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|