SNAKES ON PLANE program help!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ccarter45
    New Member
    • Mar 2008
    • 10

    SNAKES ON PLANE program help!!!

    Okay, so I need to write this program that first declares an array and inputs the number of each snake present on a plane (there are 5 diff. snakes). Next, it must print out the number of each snake: "The number of snakes in element 1 is: 7." I also need to make sure that no snakes escape the cart they are stored on on the plane. To keep them contained, the combined weight of the number of carryon pieces in front of the cart door must be great than the total weight of the snakes. Each carryon piece weighs 15 pounds, you have the weight of each snake; it must calculate and print out the minimum number of pieces of carryon luggage you will need in order to keep the snakes from breaking out.: "You will need 75 pieces of carryon luggage to block the snakes!"

    Any help, I can't seem to get the part where I store the weight of each snake, then get the total weight and make sure the carryon weight is great than the snake weight.
    Code:
    public class SnakesonPlane
    {
      public static void main(String[] args)
      {
        int[] a = {1, 7, 8, 7, 13};
        int snakeweight = 6;
        int carryonweight;
        int totalsnake = 20;
        int totalcarryon;
        
        for (int counter = 1; counter < a.length; counter++)
          System.out.printf("The number of snakes in element%2d is%3d \n",counter, a[counter]);
      
        if (counter == 1) 
        {
          snakeweight = 550;
          if (counter == 2)
          {
            snakeweight = 15;
            if (counter == 3)
            {
              snakeweight = 12;
              if (counter == 4)
              {
                snakeweight = 10;
                if (counter == 5)
                {
                  snakeweight = 23;
        for (int counter = 1; counter < a.length; counter++)
         {
           totalsnake = counter*snakeweight;
        
            System.out.println("You will need some pieces of carry-on luggage to block the snakes!");                      
      }
                }}}}}}}
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Starting at line 14: that if 'staircase' doesn't make sense: if counter equals 1 it
    will never equal 2 and when it does equal 2 it won't enter the first if clause etc.

    kind regards,

    Jos

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      @OP: I removed your other thread because it's a double post of this one. Stay
      in one thread for one problem please.

      kind regards,

      Jos (mod)

      Comment

      Working...