Java help

Discussion in 'Off Topic Forum' started by ilikemoneygreen, Aug 24, 2012.

  1. ilikemoneygreen
    Offline

    ilikemoneygreen New Member

    Joined:
    Apr 7, 2010
    Messages:
    2,579
    Likes Received:
    14
    Trophy Points:
    0
    Location:
    AZ, Superstition MTNs!
    What am I doing wrong? i cant seem to get the second dialog box to popup to enter the value. I could get it to work just in the command prompt using System.out.print but its not working out with the dialog box.
    Code:
    /**Area of rectangle *//* ilikemoneygreen
     * CIS163 29843
     * August 24, 2012
     */
     import java.util.Scanner; // scanner package
     import javax.swing.JOptionPane;
     public class RectangleArea {
         public static void main(String[] args) {
             //input the length and width
             Scanner input = new Scanner(System.in);
    
    
             //prompt user for length
             JOptionPane.showInputDialog(null, "Enter the length : " , "Length" , JOptionPane.INFORMATION_MESSAGE);
             double length = input.nextDouble();
             //Prompt user for Width
             JOptionPane.showInputDialog(null, "Enter the width : " , "Width" , JOptionPane.INFORMATION_MESSAGE);
             double width = input.nextDouble();
    
    
             //calculate area
             double area = length * width;
             //Display the results
             System.out.println("The area of a Rectangle with a width of " + width + " and a length of " + length + " is " + area); 
         }
     }
    If you help me, ill give you a cyber hug. :hail:
  2. smokeyrd
    Offline

    smokeyrd Member

    Joined:
    Aug 8, 2012
    Messages:
    135
    Likes Received:
    3
    Trophy Points:
    18
    Location:
    Atlanta, Ga
    Im having flashbacks to middle school and programming my TI81...not the 83, not the 83+, not the silver edition...the 81. Unfortunately Im not quite sure where you are going wrong...The code looks good to me but Im by no means a java guy. Is it giving you any output at all?
  3. ilikemoneygreen
    Offline

    ilikemoneygreen New Member

    Joined:
    Apr 7, 2010
    Messages:
    2,579
    Likes Received:
    14
    Trophy Points:
    0
    Location:
    AZ, Superstition MTNs!
    lol, i cant say ive ever seen an 81. sounds like you had fun with it though. My friend was obsessed with his calc, he played doom in class i think then the teacher wiped it all away. :biggrin:
    and the out i get is it does the first dialog box. I then input a number and hit enter then nothing happens, it hangs. Im thinking its a logic error, which are usually a pain.....
  4. smokeyrd
    Offline

    smokeyrd Member

    Joined:
    Aug 8, 2012
    Messages:
    135
    Likes Received:
    3
    Trophy Points:
    18
    Location:
    Atlanta, Ga
    I learned early on to archive my apps...that way when they wipe, the app stays. Great for having cheat sheets :cool-b: In any case, sorry...Im drawing a blank. This is the reason I hate coding. I hope someone else can be of assistance here.
  5. ilikemoneygreen
    Offline

    ilikemoneygreen New Member

    Joined:
    Apr 7, 2010
    Messages:
    2,579
    Likes Received:
    14
    Trophy Points:
    0
    Location:
    AZ, Superstition MTNs!
    im confident someone on here will know. this forum is quite a few nerdy people. :biggrin: