java problem
Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: java problem

  1. #1
    Banned
    Join Date
    Jun 2004
    Posts
    154

    java problem

    I am programming in java and i just started out in college.
    For my class i have to write a program with the if/else statements

    i have this so far and im getting the following errors
    System.out.print("Enter the length of the desk : ");
    int length=MyInput.readInt();
    System.out.print("Enter the width of the desk : ");
    int width=MyInput.readInt();
    int area = (length * width)
    System.out.println("Enter 1 for pine wood");
    System.out.println("Enter 2 for oak wood");
    System.out.println("Enter 3 for mahogany wood");
    System.out.print("Enter the type of wood: ");
    int wood = MyInput.readInt();
    if (wood == 2)
    (desk+100);
    else
    (desk+150);
    if (wood == 1)
    desk = 200);

    System.out.print("Enter the number of drawers: ");
    int wood= MyInput.readInt();

    lab3_141.java:20: ';' expected
    System.out.print("Enter the number of drawers: ");
    ^
    lab3_141.java:23: not a statement
    desk+75;
    ^
    lab3_141.java:25: not a statement
    desk+150; }
    ^
    3 errors

    any suggestions?

  2. #2
    Hi mom!
    Join Date
    Aug 2001
    Posts
    1,103
    Redirect your java-related questions to http://forum.java.sun.org

    While you're asking them here, try using this forums code-tags to format your code, it'll help others to read your code clearly.

    Your first problem seems to be this: there's no ; after this line: int area = (length * width) Furthermore, you didn't declare a variable with the name 'desk'. At last, lines like these have no meaning:
    Code:
     (desk+150);
    Did you mean desk=150; ?
    I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.

  3. #3
    Banned
    Join Date
    Sep 2004
    Posts
    305
    desk+100; isn't a proper Java statement. desk = desk + 100; will do what you want. That takes care of two errors.

    lab3_141.java:20: ';' expected
    System.out.print("Enter the number of drawers: ");

    That's because of this statement:

    desk = 200);

    The ; should be after the 200.

  4. #4
    Banned
    Join Date
    Jun 2004
    Posts
    154
    even when i declare desk to be 200 up top, it still has the same errors

  5. #5
    Banned
    Join Date
    Sep 2004
    Posts
    305
    Paste your entire code here. It'll be easier to understand what to fix.

  6. #6
    Banned
    Join Date
    Jun 2004
    Posts
    154

    ytyes

    AH TT your a savior, thats what it was, thank you much

    ^

  7. #7
    Banned
    Join Date
    Sep 2004
    Posts
    305
    /me bows.

    Think I need to edit this, your code is horriblely written. Post it here and we'll show you how to keep it nice and clean.

  8. #8
    Banned
    Join Date
    Jun 2004
    Posts
    154
    int drawer= MyInput.readInt();
    int drawers = drawer * 30;
    if (area > 1000)
    desk = desk+75;
    if (area > 2000)
    desk = desk+125;
    else
    desk=desk;
    if (wood == 2)
    desk=desk+100;
    if (wood == 3)
    desk=desk+150;
    else
    desk=desk;
    System.out.println("The cost of your desk is: " + (desk+drawers));


    Are my If/elses ok, b/c im not gettin the correct calculation

  9. #9
    Banned
    Join Date
    Jun 2004
    Posts
    154
    here this is my whole code

    import java.io.* ;
    public class lab3_141
    {
    public static void main(String[] args)
    {
    int desk=200;
    System.out.print("Enter the length of the desk : ");
    int length=MyInput.readInt();
    System.out.print("Enter the width of the desk : ");
    int width=MyInput.readInt();
    int area = (length * width);
    System.out.println("Enter 1 for pine wood");
    System.out.println("Enter 2 for oak wood");
    System.out.println("Enter 3 for mahogany wood");
    System.out.print("Enter the type of wood: ");
    int wood = MyInput.readInt();
    System.out.print("Enter the number of drawers: ");
    int drawer= MyInput.readInt();
    int drawers = drawer * 30;
    if (area > 1000)
    desk = desk+75;
    if (area > 2000)
    desk = desk+125;
    else
    desk=desk;
    if (wood == 2)
    desk=desk+100;
    if (wood == 3)
    desk=desk+150;
    else
    desk=desk;
    System.out.println("The cost of your desk is: " + (desk+drawers));




    }
    }

  10. #10
    Banned
    Join Date
    Jun 2004
    Posts
    154
    This is what it is supposed to do

    Purpose : To write a simple program to perform input, output and use control structures in Java.

    Description : Write a program to that calculates and displays prices for custom made desks.The base price for a desk is $200.00. Our desks are built using three types of wood, pine, oak, and mahogany. Add $100.00 to the cost for oak and $150.00 for mahogany. No extra charge for pine. If the surface area of the desk is over 1000 square inches, add $75.00. If the surface area of the desk is over 2000 square inches add $125.00. There is a $30 charge for each drawer in the desk. Compute the price display the values. Use a switch statement to determine cost for wood type.

Posting Permissions

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