2 classes
if u c the following. wen i enter a number for eidth in the size class it doesnt do the calc:
publicclass RoomTest
{
publicstaticvoid main(String[] args)
{
String displaySize;
Size sizeA =new Size();
displaySize = sizeA.getSize();
System.out.println(displaySize);
}
}
import javax.swing.*;
publicclass Size
{
privatedouble width;
privatedouble length;
public Size()
{
String widthA = JOptionPane.showInputDialog(null,"Enter width:");
double width = Double.parseDouble(widthA);
length = 5.0;
}
public String getSize()
{
double area = (width*length);
String sizeString = ("The area is: " + area);
return sizeString;
}
}
It just doesnt take the number i entered to do the calculation
THANKS
[1788 byte] By [
The_Onea] at [2007-11-26 12:44:44]

not quite sure. wat i understood but i think is wrong is that u cant input a number and use one already set together:
so i did this:
public Size()
{
String widthA = JOptionPane.showInputDialog(null, "Enter width:");
double width = Double.parseDouble(widthA);
String lengthA = JOptionPane.showInputDialog(null, "Enter length:");
double length = Double.parseDouble(lengthA);
}
But still it doesnt work.. can u elaborate wat u can do?
thanks
> not quite sure. wat i understood but i think is wrong
> is that u cant input a number and use one already set
> together:
Yes, you can use one input and one already set together.
You had "length" set correctly before. Having the word "double" in front of "width" made it a local variable, instead of the one defined at the top of the class. Remove the word "double" before "width" in your original constructor.
It's a bit odd (I think) for a constructor to popup the dialogs. You might want to popup the dialogs in main (or in some other method), and then have a constructor that takes and sets the size:
public Size(double w, double h)
{
width = w;
height = h;
}
Also, note that the users of these forums are from many countries around the world, and in many cases English is not the person's primary language.
When you post "if u c the following. wen", "wat u", and similar, then you are just adding to the communication gap. Please use standard English, not sms-spk or the like.