443,836 Members | 2,059 Online
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

# SNAKES ON PLANE program help!!!

 P: 10 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. Expand|Select|Wrap|Line Numbers 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!");                         }             }}}}}}} Mar 20 '08 #1
2 Replies

 Expert 10K+ P: 11,448 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 Mar 20 '08 #2

 Expert 10K+ P: 11,448 @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) Mar 20 '08 #3