Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## 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

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.

2. ## 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.

3. ## 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

4. ## 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
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: ==.

5. ## The Following User Says Thank You to Norm For This Useful Post:

Govna242 (February 21st, 2013)

6. ## 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.

7. ## Re: Beginners needing help

Did you try doing a search for equals? Its used lots of times.

8. ## 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

table = 0.00;
if (area > 750)
{charge += 50;}
if (wood.equals("mahogany"))
{charge += 200.00;}
if (wood.equals("oak"))
{charge += 100.00;}