# Beginners needing help

• February 21st, 2013, 03:00 PM
Govna242
Beginners needing help
Im a beginner programmer and im trying to complete this assignment but i need Help.

In this lab you have a prewritten Java program for a furniture company. The program is supposed to compute the price of any table a customer orders, based on the following facts:

The charge for all tables ia minimum of \$150.00
If the surface(length * width) is over 750 square inches, add \$50.00
If the wood is "mahogany" add \$200.00; for "oak" add \$100.00. No charge is added for "pine"
For extension leaves for the table, there is an additional \$50.00 charge each.

You need to declare variables for the following, and initialize them where specified:

A Variable for the cost of the table initialized to 0.00
A variable for the length of the table initialized to 50 inches
A variable for the width of the table initialized to 40 inches
A variable for the surface area of the table
A variable for the wood type initialized with the value "oak"
A variable for the number of extension leaves initialized with the value 2.

Write the rest of the program using assignments statement and if statements as appropriate. The out statement is written for you. Your output should be: The charge for this table is \$400.0.

This is what i have

Code java:

```public class Furniture { public static void main(String args[]) { // Declare and initialize variables here. // Charge for this table. double charge = 150.00; double table = 0.00;   // Length of table in inches. int length = 50;   // Width of table in inches. int width = 40;   // Area of this table in square inches. int area = length * width;   // Type of wood. String wood = oak;   // Number of extension leaves. int leaves = 2;   // Write assignment and if statements here as appropriate.   table = 0.00; if (area > 750) {charge += 50;} if (wood = "mahogany") {charge += 200.00;} if (wood = "oak") {charge += 100.00;}         // Output Charge for this table. System.out.println("The charge for this table is \$" + charge);   System.exit(0); } }```

Can you tell me what i need to add or delete rather than just writing it out. But if you do write if out can you explain it please.
• February 21st, 2013, 03:03 PM
Norm
Re: Beginners needing help
[code=java]
[/code]
to get highlighting and preserve formatting.

Can you explain what problems you are having with your assignment?
Ask some specific questions about the program's code and what you need to do.
• February 21st, 2013, 03:19 PM
Govna242
Re: Beginners needing help
I'm trying to get the output to say The charge for this table is \$400.0. The problem im having is i added all the variables they asked and the if statements but it does not compile and i feel as if im leaving something out. When i try to compile the error im getting is:
Furniture.java:23: error: cannot find symbol
String wood = oak;
^
symbol: variable oak
location: class Furniture
• February 21st, 2013, 03:25 PM
Norm
Re: Beginners needing help
String wood = oak;
The compiler thinks oak is the name of a variable. If you mean for it to be a String, enclose it it "s
Code :

`if (wood = "oak")`
When comparing the contents of objects like Strings, use the equals() method not the == operator.
The = operator is the assignment operator, not the equality testing operator: ==.
• February 21st, 2013, 03:37 PM
Govna242
Re: Beginners needing help
Can you give me an example of what you mean when you say use the () method not == operator. I ran the code and it said the charge for this table is \$300.00 and it should be \$400.00. I think i left something out with the leaves but i dont know exactly what to add.
• February 21st, 2013, 03:48 PM
Norm
Re: Beginners needing help
Did you try doing a search for equals? Its used lots of times.
• February 21st, 2013, 03:58 PM
Govna242
Re: Beginners needing help
Oh i understand what your saying now. I was reading it as use the equals "()" method not the == operator instead of use the "equals()" method not the == operator. So i would say if (wood.equals("mahogany")). Thank i got it i also realized that i needed to add the two leaves which were \$50 each that gave me the \$100 i need. Thanks for the help Norm

Code java:

```table = 0.00; if (area > 750) {charge += 50;} if (wood.equals("mahogany")) {charge += 200.00;} if (wood.equals("oak")) {charge += 100.00;}```
• February 21st, 2013, 04:31 PM
Norm
Re: Beginners needing help