CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2010
    Posts
    4

    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

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Feb 2010
    Posts
    4

    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.

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  5. #5
    Join Date
    Feb 2010
    Posts
    4

    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.

  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  7. #7
    Join Date
    Feb 2010
    Posts
    4

    Re: a little JOptionPane Help?

    alright sounds good!

  8. #8
    Join Date
    Jul 2011
    Posts
    1

    Re: a little JOptionPane Help?

    You are right kiang to visualize anything is easier rather than thinking about the code

  9. #9
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: a little JOptionPane Help?

    Quote Originally Posted by Moriene View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured