By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
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
  1. public class SnakesonPlane
  2. {
  3.   public static void main(String[] args)
  4.   {
  5.     int[] a = {1, 7, 8, 7, 13};
  6.     int snakeweight = 6;
  7.     int carryonweight;
  8.     int totalsnake = 20;
  9.     int totalcarryon;
  10.  
  11.     for (int counter = 1; counter < a.length; counter++)
  12.       System.out.printf("The number of snakes in element%2d is%3d \n",counter, a[counter]);
  13.  
  14.     if (counter == 1) 
  15.     {
  16.       snakeweight = 550;
  17.       if (counter == 2)
  18.       {
  19.         snakeweight = 15;
  20.         if (counter == 3)
  21.         {
  22.           snakeweight = 12;
  23.           if (counter == 4)
  24.           {
  25.             snakeweight = 10;
  26.             if (counter == 5)
  27.             {
  28.               snakeweight = 23;
  29.     for (int counter = 1; counter < a.length; counter++)
  30.      {
  31.        totalsnake = counter*snakeweight;
  32.  
  33.         System.out.println("You will need some pieces of carry-on luggage to block the snakes!");                      
  34.   }
  35.             }}}}}}}
Mar 20 '08 #1
Share this Question
Share on Google+
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

Post your reply

Sign in to post your reply or Sign up for a free account.