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]
# 1
> if u c the following. wen i enter a number for eidth> in the size class it doesnt do the calc:u c calc?
prometheuzza at 2007-7-7 16:22:42 > top of Java-index,Java Essentials,Java Programming...
# 2
One of these lines sets a value in the class. The other sets a local value. One of them is wrong. Guess which one.double width = Double.parseDouble(widthA);length = 5.0;
doremifasollatidoa at 2007-7-7 16:22:42 > top of Java-index,Java Essentials,Java Programming...
# 3

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

The_Onea at 2007-7-7 16:22:42 > top of Java-index,Java Essentials,Java Programming...
# 4

> 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;

}

doremifasollatidoa at 2007-7-7 16:22:42 > top of Java-index,Java Essentials,Java Programming...
# 5

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.

ChuckBinga at 2007-7-7 16:22:42 > top of Java-index,Java Essentials,Java Programming...
# 6

public Size(double w, double h)

{

width = w;

height = h;

}

wat exacly is that doin. could u explain it? bit confused

The_Onea at 2007-7-7 16:22:43 > top of Java-index,Java Essentials,Java Programming...