Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help with hypotenuse code that uses JOptionPane PLEASE help

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with hypotenuse code that uses JOptionPane PLEASE help

    I was out for a couple days in my class and i have no idea where to even begin on the following program.
    -create a program called hypotenuse
    -use JOptionPane input to ask the user for x, y, width and height of a rectangle.
    calculate the length on the diagonal
    Diagonal = square root of(width squared+height squared)
    -report to the user in a JOptionPane message the width height and diagonal length


  2. #2
    Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Default Re: Help with hypotenuse code that uses JOptionPane PLEASE help

    Being out of class is no excuse for lack of effort. I do not mean to sound rude but what have you tried? As anyone with some experience will tell you when it comes to programming practice is what makes you better.

    Have you used JOPtionPane before?
    How would you get the hypotenuse by hand?

  3. #3
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    203
    My Mood
    Stressed
    Thanks
    22
    Thanked 35 Times in 35 Posts

    Default Re: Help with hypotenuse code that uses JOptionPane PLEASE help

    Here's what you would need from JOptionPane:
    JOptionPane (Java Platform SE 7 )

    Note, that the showInputDialog is static and called with the class name and also returns a String so you'll have to Integer.parseInt() or Double.parseDouble() it to get it into the number format you want. Also, as for the Component param, you can usually pass it null.

    Second, the Math class has a method called sqrt() that takes the double as a param and returns a double I think. It is also a static method, meaning that it is called with the class name.

    As for the output, this should work

    JOptionPane (Java Platform SE 7 )


    Note, that again the component param can be null.

Similar Threads

  1. [SOLVED] Calculator Using JOptionPane
    By norbel88 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 12th, 2013, 12:04 PM
  2. JOptionPane code for testing without the prompts
    By Norm in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: March 12th, 2013, 10:18 AM
  3. Still having problem with JOptionPane
    By runkerr in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 28th, 2013, 06:40 PM
  4. Errors with beginning jOptionPane code
    By LoganC in forum What's Wrong With My Code?
    Replies: 12
    Last Post: September 29th, 2012, 12:23 PM
  5. JOptionPane using If and Else
    By Liuric in forum Member Introductions
    Replies: 7
    Last Post: October 1st, 2010, 12:05 AM