Results 1 to 13 of 13
Thread: Simple program, simple problem
- 06-20-2011, 03:50 AM #1
Member
- Join Date
- May 2011
- Posts
- 17
- Rep Power
- 0
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);
}
}
- 06-20-2011, 03:59 AM #2
Look very carefully at that line of code. Do you see something that shouldn't be there?Java Code:public static void displayData(double length, double width, area);
Oh and something that is missing.
- 06-20-2011, 04:06 AM #3
Member
- Join Date
- May 2011
- Posts
- 17
- Rep Power
- 0
Well I thought I needed a "double" in front of area, but it just gives me more errors if I do that. :/
- 06-20-2011, 04:18 AM #4
Member
- Join Date
- May 2011
- Posts
- 17
- Rep Power
- 0
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"
- 06-20-2011, 04:22 AM #5
Have you tried both changes together?
- 06-20-2011, 04:27 AM #6
Member
- Join Date
- May 2011
- Posts
- 17
- Rep Power
- 0
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.
- 06-20-2011, 04:29 AM #7
Post your latest code between code tags. Place [ code ] before and [ /code ] after without the spaces.
Post the full and exact error message.
- 06-20-2011, 04:38 AM #8
Member
- Join Date
- May 2011
- Posts
- 17
- Rep Power
- 0
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); } }
- 06-20-2011, 04:40 AM #9
Member
- Join Date
- May 2011
- Posts
- 17
- Rep Power
- 0
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
- 06-20-2011, 04:49 AM #10
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?
Where in that code have you declared a variable called "width"?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; }
- 06-20-2011, 05:01 AM #11
Member
- Join Date
- May 2011
- Posts
- 17
- Rep Power
- 0
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.
- 06-20-2011, 05:04 AM #12
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!
- 06-20-2011, 05:12 AM #13
Member
- Join Date
- May 2011
- Posts
- 17
- Rep Power
- 0
Similar Threads
-
simple program
By kayln in forum EclipseReplies: 0Last Post: 05-01-2011, 10:03 PM -
Please help with simple program.. Very simple.
By jonytek in forum New To JavaReplies: 7Last Post: 02-14-2011, 12:44 AM -
Problem with very simple program
By iratus in forum New To JavaReplies: 13Last Post: 11-07-2010, 04:43 PM -
Simple program help
By jtyler in forum New To JavaReplies: 3Last Post: 09-20-2010, 07:43 AM -
simple program
By blastoff in forum New To JavaReplies: 5Last Post: 04-14-2010, 11:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks