Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.39 KB | None | 0 0
  1. /*
  2.     WRITE A PROGRAM THAT SIMULATES ALIEN PETS THAT YOU MUST LOOK AFTER
  3.  */
  4.  
  5. import javax.swing.*;//allows to import library
  6. import java.util.Random; //allows to import random number generator
  7.  
  8. class alien
  9.  
  10. {
  11.     public static void main (String [] param)
  12.     {
  13.         welcome();
  14.         start();
  15.         System.exit (0);
  16.    
  17.     }
  18.         public static void welcome()
  19.     {
  20.         JOptionPane.showMessageDialog(null, "Welcome to Alien Planet!");
  21.         System.out.println("          !RULES!");
  22.         System.out.println("Amount Of Players Can Be Chosen");
  23.         System.out.println("Each Player Gets Two Rounds");
  24.     }
  25.    
  26.     public static void start()
  27.     {
  28.         //WORKING ON A+ HERE String element = JOptionPane.showInputDialog("What element do you want your pet do be pick from: water and fire");
  29.      
  30.         int StartGame = 1;
  31.        
  32.         String input= JOptionPane.showInputDialog("Enter number of players");
  33.         int EnterPlayers = Integer.parseInt(input);
  34.        
  35.        
  36.         int [] StoreEmotion = new int [3];//change to [6] later on
  37.        
  38.         String [] StoreName = new String [1];
  39.    
  40.     for(int i = 0; i<StoreEmotion.length; i++)
  41.         {
  42.             StoreEmotion[i] = 0;//use for later on
  43.         }
  44.                 for(int j=StartGame; j<=EnterPlayers; j++)
  45.                 {
  46.                     for(int z = 0; z<StoreName.length; z++)
  47.                     {
  48.                         String AlienPetOne = JOptionPane.showInputDialog("Player " + j + " Pick your alien pet");
  49.                        
  50.                         StoreName[z] = AlienPetOne;
  51.                         System.out.println("welcome " + StoreName[z]);
  52.                         JOptionPane.showMessageDialog (null, "Round: " + j);
  53.            
  54.                         //brefore interacting array
  55.                         StoreEmotion[0] = hungerlvl (AlienPetOne);
  56.                         StoreEmotion[1] = thirstlvl (AlienPetOne);
  57.                         StoreEmotion[2] = irritationlvl (AlienPetOne);
  58.                    
  59.                        /* after interacting array
  60.                         StoreEmotion[3] = Newhungerlvl (AlienPetOne, StoreEmotion[3]);
  61.                         StoreEmotion[4] = Newthirstlvl (AlienPetOne, StoreEmotion[4]);
  62.                         StoreEmotion[5] = Newirritationlvl (AlienPetOne, StoreEmotion[5]);
  63.                         */
  64.          
  65.                         System.out.println("Player " + j + " Round: 1: " + "Hunger levevl = " + StoreEmotion[0] + " thirst level = " + StoreEmotion[1] + " irritation level = " + StoreEmotion[2] );
  66.                        /*
  67.                         System.out.println("Player " + j + " Round: 2: " + "Hunger levevl = " + StoreEmotion[3] + " thirst level = " + StoreEmotion[4] + " irritation level = " + StoreEmotion[5] );
  68.                         */
  69.                         SortA(AlienPetOne, StoreEmotion);
  70.                         System.out.println("NEXT PLAYERS TURN!");
  71.                        
  72.                 }
  73.                    
  74.         }
  75.        
  76.     }
  77.  
  78.   public static int hungerlvl (String AlienPetOne)// added String
  79.     {
  80.         Random number = new Random();//random number generates
  81.         int hunger = number.nextInt(5) + 1;//random number from 1 to 5 (+1 = starts from 1 and not 0)
  82.        
  83.        
  84.         JOptionPane.showMessageDialog(null, "On a scale of 1-10 " + AlienPetOne + " hunger rate is " + hunger + "/10");
  85.        
  86.         if (hunger <=4 )
  87.         {
  88.             JOptionPane.showMessageDialog (null, AlienPetOne + " is hungry, You must feed him right away!");
  89.            
  90.         }
  91.         else if (hunger >= 5 && hunger <= 7)
  92.         {
  93.             JOptionPane.showMessageDialog (null, AlienPetOne + " has just ate,  ");
  94.            
  95.         }
  96.         else
  97.         {
  98.             JOptionPane.showMessageDialog (null, AlienPetOne + " is full, do not over feed him");
  99.            
  100.         }
  101.        
  102.       // Newhungerlvl (AlienPetOne, hunger);
  103.          return hunger;
  104.      
  105.     }
  106.    
  107.  public static int thirstlvl (String AlienPetOne)
  108. {
  109.     Random number = new Random();//random number generates
  110.     int thirst = number.nextInt(5) + 1;//random number from 1 to 10 (+1 = starts from 1 and not 0)
  111.  
  112.        
  113.     JOptionPane.showMessageDialog(null, "On a scale of 1-10 " + AlienPetOne + " thirst rate is " + thirst + "/10");
  114.    
  115.         if (thirst <=4 )
  116.         {
  117.             JOptionPane.showMessageDialog (null, AlienPetOne + " is thirsty, GET MOVING!");
  118.         }
  119.         else if (thirst >= 5 && thirst <= 7)
  120.         {
  121.             JOptionPane.showMessageDialog (null, AlienPetOne + " Seems to be neutral and approachable");
  122.         }
  123.         else
  124.         {
  125.             JOptionPane.showMessageDialog (null, AlienPetOne + " is a happy bunny");
  126.         }
  127.    
  128.    // Newthirstlvl (AlienPetOne, thirst);
  129.     return thirst;
  130. }
  131.    
  132.     public static int irritationlvl (String AlienPetOne)// (String AlienPetOne, int EnterPlayers)
  133.     {
  134.        
  135.         Random number = new Random();//random number generates
  136.         int irritation = number.nextInt(5) + 1;//random number from 1 to 10 (+1 = starts from 1 and not 0)
  137.  
  138.         JOptionPane.showMessageDialog(null, "On a scale of 1-10 " + AlienPetOne + " irritation rate is " + irritation + "/10");
  139.    
  140.         if (irritation <=4 )
  141.         {
  142.             JOptionPane.showMessageDialog (null, AlienPetOne + " is annoyed, play with it!");
  143.         }
  144.         else if (irritation >= 5 && irritation <= 7)
  145.         {
  146.             JOptionPane.showMessageDialog (null, AlienPetOne + " is calm and happy!");
  147.         }
  148.         else
  149.         {
  150.             JOptionPane.showMessageDialog (null, AlienPetOne + " is ecstatic!");
  151.         }
  152.        
  153.        // Newirritationlvl (AlienPetOne, irritation);
  154.         return irritation;
  155.     }
  156.    
  157.     public static void SortA(String AlienPetOne, int [] StoreEmotion)
  158.     {
  159.        
  160.         for (int pass=1; pass<3; pass++)
  161.         {
  162.         for(int i = 0; i<3; i++)
  163.         {
  164.            
  165.                 if (StoreEmotion[i] > StoreEmotion[i+1])
  166.                 {
  167.                  
  168.                     int tmp = StoreEmotion[i+1];
  169.                     StoreEmotion[i+1] = StoreEmotion[i];
  170.                     StoreEmotion[i] = tmp;
  171.                    
  172.                     System.out.println(tmp);
  173.                    
  174.                 }
  175.            
  176.         }
  177.         }
  178.        
  179.         }
  180.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement