1. Member
Join Date
Nov 2012
Posts
7
Rep Power
0

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.

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.

3. Member
Join Date
Nov 2012
Posts
7
Rep Power
0

Ok hold on a second

4. Member
Join Date
Nov 2012
Posts
7
Rep Power
0

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?

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.

6. Member
Join Date
Nov 2012
Posts
7
Rep Power
0

I'm not sure if this is what the question is asking me to do.

7. Member
Join Date
Nov 2012
Posts
7
Rep Power
0

Ok so i don't need to do all that stuff, all i need to do is dblArea = dbLength * dblHeight;

8. Member
Join Date
Nov 2012
Posts
7
Rep Power
0

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!

10. Member
Join Date
Nov 2012
Posts
7
Rep Power
0

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. Senior Member
Join Date
Oct 2012
Posts
108
Rep Power
0

Well, you're missing a plus sign ("+") in one of your println statements....

But for future, please use the code and /code tags and post the errors you get! I'm sure "sytax error on token ..." doesn't mean much to you now, but it will.
Last edited by SJF; 11-04-2012 at 12:26 AM. Reason: now not know

#### Posting Permissions

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