Results 1 to 13 of 13
  1. #1
    taymilll is offline Member
    Join Date
    May 2011
    Posts
    17
    Rep Power
    0

    Default Simple program, simple problem

    Hey guys, I have to write a program using methods that will calculate the area of a rectangle. I'm using textpad and when I try to compile it says:

    <identifier> expected on line 84
    (which is the last header: public static void displayData(double length, double width, area);)

    I tried adding:

    area= Double.parseDouble(input);

    a line before "return length * width, and a "double" before area in the header, but that just gave me even more errors! Any suggestions? Here is my program:

    import javax.swing.JOptionPane;

    public class AreaRectangle
    {
    public static void main(String[] args)
    {
    double length, // The rectangle's length
    width, // The rectangle's width
    area; // The rectangle's area

    // Get the rectangle's length from the user.
    length = getLength();

    // Get the rectangle's width from the user.
    width = getWidth();

    // Get the rectangle's area.
    area = getArea(length, width);

    // Display the rectangle data.
    displayData(length, width, area);

    System.exit(0);
    }

    /**
    Get the rectangle's length
    @return The length
    */

    public static double getLength()
    {
    String input;
    double length;

    input = JOptionPane.showInputDialog("Please enter the rectangle's length.");

    length = Double.parseDouble(input);

    return length;
    }

    /**
    Get the rectangle's width
    @return The width
    */

    public static double getWidth()
    {
    String input;
    double getWidth;

    input = JOptionPane.showInputDialog("Please enter the rectangle's width.");

    width = Double.parseDouble(input);

    return width;
    }

    /**
    Find the area of the rectangle
    @return The area
    */

    public static double getArea (double length, double width)
    {
    return length * width;
    }

    /**
    Display the rectangle data
    @param length The rectangle's length
    @param width The rectangle's width
    @param area The rectangle's area
    */


    public static void displayData(double length, double width, area);

    {
    JOptionPane.showmessageDialog(null, length + "x" + width + "=" + "a rectangle area of" + area);
    }

    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    Java Code:
    public static void displayData(double length, double width, area);
    Look very carefully at that line of code. Do you see something that shouldn't be there?

    Oh and something that is missing.

  3. #3
    taymilll is offline Member
    Join Date
    May 2011
    Posts
    17
    Rep Power
    0

    Default

    Well I thought I needed a "double" in front of area, but it just gives me more errors if I do that. :/

  4. #4
    taymilll is offline Member
    Join Date
    May 2011
    Posts
    17
    Rep Power
    0

    Default

    Also, initially I thought I didn't need a semicolon after the parenthesis, but when I didn't have one, it said there was an error "; expected"

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    Have you tried both changes together?

  6. #6
    taymilll is offline Member
    Join Date
    May 2011
    Posts
    17
    Rep Power
    0

    Default

    Yep, still no luck :( Any other ideas? I have a feeling it's something to do with "double area," but I'm not quite sure what.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    Post your latest code between code tags. Place [ code ] before and [ /code ] after without the spaces.

    Post the full and exact error message.

  8. #8
    taymilll is offline Member
    Join Date
    May 2011
    Posts
    17
    Rep Power
    0

    Default

    Oh I was wondering about that haha thanks! I'll repost the whole program in the correct format. (I put the changes I made in red, and I removed that semicolon)

    Java Code:
     import javax.swing.JOptionPane;
    
    public class AreaRectangle
    {
       public static void main(String[] args)
       {
          double length,    // The rectangle's length
                 width,     // The rectangle's width
                 area;      // The rectangle's area
    
          // Get the rectangle's length from the user.
          length = getLength();
    
          // Get the rectangle's width from the user.
          width = getWidth();
    
          // Get the rectangle's area.
          area = getArea(length, width);
    
          // Display the rectangle data.
          displayData(length, width, area);
    
          System.exit(0);
       }
    
       /**
       Get the rectangle's length
       @return The length
       */
    
       public static double getLength()
       {
    	   String input;
    	   double length;
    
    	   input = JOptionPane.showInputDialog("Please enter the rectangle's length.");
    
    	   length = Double.parseDouble(input);
    
    	   return length;
       }
    
       /**
       Get the rectangle's width
       @return The width
       */
    
       public static double getWidth()
       {
    	   String input;
    	   double getWidth;
    
    	   input = JOptionPane.showInputDialog("Please enter the rectangle's width.");
    
    	   width = Double.parseDouble(input);
    
    	   return width;
       }
    
       /**
       Find the area of the rectangle
       @return The area
       */
    
       public static double getArea (double length, double width)
       {
    [COLOR="red"]area = Double.parseDouble(input);[/COLOR]	   	
      return length * width;
       }
    
       /**
       Display the rectangle data
       @param length The rectangle's length
       @param width The rectangle's width
       @param area The rectangle's area
       */
    
    
    	   public static void displayData(double length, double width, [COLOR="red"]double [/COLOR]area)
    
    	   	{
    		   JOptionPane.showmessageDialog(null, length + "x" + width + "=" + "a rectangle area of" + area);
       		}
    
    }

  9. #9
    taymilll is offline Member
    Join Date
    May 2011
    Posts
    17
    Rep Power
    0

    Default

    Without those changes the error message was:

    C:\Users\Public\Documents\Java\AreaRectangle.java: 85: <identifier> expected
    public static void displayData(double length, double width, area)
    ^
    1 error
    Tool completed with exit code 1

    With those changes, the errors are:

    C:\Users\Public\Documents\Java\AreaRectangle.java: 62: cannot find symbol
    symbol : variable width
    location: class AreaRectangle
    width = Double.parseDouble(input);
    ^
    C:\Users\Public\Documents\Java\AreaRectangle.java: 64: cannot find symbol
    symbol : variable width
    location: class AreaRectangle
    return width;
    ^
    C:\Users\Public\Documents\Java\AreaRectangle.java: 74: cannot find symbol
    symbol : variable area
    location: class AreaRectangle
    area = Double.parseDouble(input);
    ^
    C:\Users\Public\Documents\Java\AreaRectangle.java: 74: cannot find symbol
    symbol : variable input
    location: class AreaRectangle
    area = Double.parseDouble(input);
    ^
    C:\Users\Public\Documents\Java\AreaRectangle.java: 89: cannot find symbol
    symbol : method showmessageDialog(<nulltype>,java.lang.String)
    location: class javax.swing.JOptionPane
    JOptionPane.showmessageDialog(null, length + "x" + width + "=" + "a rectangle area of" + area);
    ^
    5 errors

    Tool completed with exit code 1

  10. #10
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    So now you have completely different error messages that have nothing to do with the problems you first asked about. Just saying "Yep, still no luck" how the heck are we supposed to know what your problems are without you posting relevant information?

    Java Code:
    public static double getWidth()
       {
    	   String input;
    	   double getWidth;
    
    	   input = JOptionPane.showInputDialog("Please enter the rectangle's width.");
    
    	   width = Double.parseDouble(input);
    
    	   return width;
       }
    Where in that code have you declared a variable called "width"?

  11. #11
    taymilll is offline Member
    Join Date
    May 2011
    Posts
    17
    Rep Power
    0

    Default

    No, I still have the same problem as before, I was just showing you the error messages I got with my original code compared to the error messages I got after I made a change.

    I declared the width variable in the beginning. In the line of code you pointed out, it's actually supposed to be width instead of getWidth, but I just corrected that mistake and I still have the same errors I originally had.

  12. #12
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    No, you have complety different errors. You have 5 errors now and none of them have to do with the displayData method which is what your first post was about. The fact that you fixed those first errors have now revealed other errors. This does not mean that whatever changes you made to displayData was wrong!

  13. #13
    taymilll is offline Member
    Join Date
    May 2011
    Posts
    17
    Rep Power
    0

    Default

    Oh I see what you're saying. Sorry, this is my first computer science class and we are only on chapter five so this is all very new to me.

Similar Threads

  1. simple program
    By kayln in forum Eclipse
    Replies: 0
    Last Post: 05-01-2011, 10:03 PM
  2. Please help with simple program.. Very simple.
    By jonytek in forum New To Java
    Replies: 7
    Last Post: 02-14-2011, 12:44 AM
  3. Problem with very simple program
    By iratus in forum New To Java
    Replies: 13
    Last Post: 11-07-2010, 04:43 PM
  4. Simple program help
    By jtyler in forum New To Java
    Replies: 3
    Last Post: 09-20-2010, 07:43 AM
  5. simple program
    By blastoff in forum New To Java
    Replies: 5
    Last Post: 04-14-2010, 11:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •