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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Beginners needing help

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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.
    Last edited by Govna242; February 21st, 2013 at 04:16 PM. Reason: Wrapping


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Beginners needing help

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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: ==.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Govna242 (February 21st, 2013)

  6. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Beginners needing help

    Did you try doing a search for equals? Its used lots of times.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #7
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Beginners needing help

    Glad you got it working.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #9
    Junior Member Robertgif's Avatar
    Join Date
    Feb 2013
    Posts
    19
    My Mood
    Amazed
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Beginners needing help

    This is really not important at all, but you write:

    table = 0.00 twice,

    once when you initialize the variable and once again when you are about to do your if statements.
    "You should not let technology (or method) drive your design, but make your design drive the technology".

    Always learning!

Similar Threads

  1. Newbie needing a little help
    By Bgriesh in forum Loops & Control Statements
    Replies: 3
    Last Post: September 24th, 2012, 07:19 PM
  2. beginer in java .. needing help
    By Kandarp in forum Java IDEs
    Replies: 4
    Last Post: August 31st, 2012, 08:05 AM
  3. NEEDING HELP UNDERSTANDING A CODE FROM THREE CLASSES!!!
    By BlackShadow in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 5th, 2012, 09:29 AM
  4. New student needing help!
    By newstudent in forum Object Oriented Programming
    Replies: 2
    Last Post: January 30th, 2012, 12:49 AM
  5. [SOLVED] [Method] needing some help
    By Perplexing in forum Object Oriented Programming
    Replies: 4
    Last Post: December 2nd, 2010, 05:03 PM