java problem - Page 3
Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: java problem

  1. #21
    Banned
    Join Date
    Jun 2004
    Posts
    154
    well turns out there is problems

    this is mine

    Code:
    // File: lab3_141.java
    // Jeremy Otis
    // 08
    import java.io.* ;
    public class lab3_141
    {
        public static void main(String[] args)
        {
        double area;
        double wood;
        double width;
        double length;
        double drawer;
        double price = 200;
    
    
         System.out.print("Enter the length of the desk : ");
         length=MyInput.readInt();
         System.out.print("Enter the width of the desk : ");
         width=MyInput.readInt();
    
         area = (length * width);
            if (area > 1000)
                    price += 75;
            if (area > 2000)
                    price += 125;
    
         System.out.println("Wood Selection!");
         System.out.println("1. Oak - $100");
         System.out.println("2. Mahogany - $150");
         System.out.println("3. Pine - $0");
         System.out.print("Enter the type of wood: ");
    
         wood = MyInput.readInt();
             if (wood == 1)
              price += 100;
             if (wood == 2)
              price += 150;
             if (wood == 3)
              price += 0;
         System.out.print("Enter the number of drawers: ");
         drawer= MyInput.readInt();
    
            price += (drawer * 30);
        System.out.println("The cost of your desk is: $" + price );
    }
    }
    when i enter the values 60=leng 48=wid 1=oak 4=drawers
    i get the answer 620

    However on your program (with slight modifications)

    Code:
    import java.io.* ;
    
    public class labredo
    {
            public static void main(String[] args)
     {
                    int price = 200;
                    int width;
                    int length;
                    int surface;
                    int wood;
                    int drawers;
    
                    System.out.print("Enter table surface's width (inches): ");
                    width = MyInput.readInt();
                    System.out.print("Enter table surface's length (inches): ");
                    length = MyInput.readInt();
    
                    surface = width * length;
                    if((surface > 1000) && (surface < 2000)) {
                            price += 75;
                    }
                    if(surface > 2000) {
                            price += 125;
                    }
    
                    System.out.println("Wood Selection!");
                    System.out.println("1. Oak - $100");
                    System.out.println("2. Mahogany - $150");
                    System.out.println("3. Pine - $0");
                    System.out.print("Which type of wood: ");
                    wood = MyInput.readInt();
    
                    if (wood == 1) {
                            price += 100;
                    }if (wood == 2) {
                            price += 150;
                    }if (wood == 3) {
                            price += 0;    }
    
                    System.out.print("How many drawers would you like - $30/drawer:$
                    drawers = MyInput.readInt();
    
                    price += (drawers * 30);
    
                    System.out.println("Your new desk is going to cost: $" + price);
    }
    }
    Using the same values i get 545 which is correct.

    What math am i doing wrong?

  2. #22
    Banned
    Join Date
    Jun 2004
    Posts
    154
    it was the
    if ((area > 1000) && (area <2000) statement

    however i dont really understand what that did

    sorry if im kind of scatter-brained, i keep fixing and finding new problems. This time im done but i dont understand what the difference was

  3. #23
    Banned
    Join Date
    Sep 2004
    Posts
    305
    You're charging them $75 too much like I said in my previous post. You're charging them a $200 fee rather than just a $125. Look at my original and the double condition if statement I have, you should do something similar to it.

    That compund if statement is basically an if with two conditions. Translated into words it means: if the area is greater than 1000 AND ( && ) the area is less than 2000, then perform what's under this if statement.

  4. #24
    Banned
    Join Date
    Jun 2004
    Posts
    154
    oh, tha makes sense then. I changed mine to something similar. Now i might have a bit of an edge in that class. I appreciate everything

Posting Permissions

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