• 11-03-2012, 10:22 PM
coolkid456
Write an expression that multiplies the length of a room by the width (to calculate the area) and assign the result to a variable that represents the area.

I can't figure this out, i would appreciate it if someone could explain this to me and write the program for me, thanks.
• 11-03-2012, 10:30 PM
Fubarable
Quote:

Originally Posted by coolkid456
Write an expression that multiplies the length of a room by the width (to calculate the area) and assign the result to a variable that represents the area.

I can't figure this out, i would appreciate it if someone could explain this to me and write the program for me, thanks.

That's not how it works here. We'll be happy to try to help you, but we bristle when someone asks us to write a program for them or do their homework for them. So please show us what you've done so far, please ask specific questions, and let's see how we can clear up any confusions for you and try to help you out.
• 11-03-2012, 10:32 PM
coolkid456
Ok hold on a second
• 11-03-2012, 10:40 PM
coolkid456
String strLength, strHeight;
double dblLength, dblHeight, dblArea;

strLength = JOptionPane.showInputDialog ( “Enter the room’s length: “);
strBase = JOptionPane.showInputDialog ( “Enter the room’s base: ”);

this is what I've have so far, what do you think?
• 11-03-2012, 10:46 PM
Fubarable
The assignment as posted asks for an "expression". To me that suggests that they want a single line of code, and that they assume that length and area have already been obtained. If so, then I'd create a single line of code that does the necessary multiplication and assigns the result to a variable that is supposed to hold the area.

I may be wrong as I have not seen the entire assignment, but just based on your initial post, that appears all that is expected here.
• 11-03-2012, 10:46 PM
coolkid456
I'm not sure if this is what the question is asking me to do.
• 11-03-2012, 10:50 PM
coolkid456
Ok so i don't need to do all that stuff, all i need to do is dblArea = dbLength * dblHeight;
• 11-03-2012, 10:51 PM
coolkid456
• 11-03-2012, 10:53 PM
Fubarable
That's what I would do, yes. But if you want to be fully sure, then post the entire actual assignment text here. And you're welcome!
• 11-03-2012, 11:28 PM
coolkid456
public class Demo1
{
public static void main (String[] args)
{
int numberA, numberB, sum, difference;

numberA = 9;
numberB = 12;

sum = numberA + numberB;
difference = numberA - numberB;

System.out.println ("the sum of " + numberA + " plus " + numberB + " is " + sum);
System.out.println ("the difference of " + numberA " minus " + numberB + " is " + difference);
}
}

No idea whats wrong here but i get an error.
Calculate and display the result of taking the difference of numberA and numberB (ie. numberA – numberB). Your output should look like this…

the sum of 12 plus 9 is 21.
the difference 12 minus 9 is 3.
• 11-04-2012, 12:26 AM
SJF