Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- WRITE A PROGRAM THAT SIMULATES ALIEN PETS THAT YOU MUST LOOK AFTER
- */
- import javax.swing.*;//allows to import library
- import java.util.Random; //allows to import random number generator
- class alien
- {
- public static void main (String [] param)
- {
- welcome();
- start();
- System.exit (0);
- }
- public static void welcome()
- {
- JOptionPane.showMessageDialog(null, "Welcome to Alien Planet!");
- System.out.println(" !RULES!");
- System.out.println("Amount Of Players Can Be Chosen");
- System.out.println("Each Player Gets Two Rounds");
- }
- public static void start()
- {
- //WORKING ON A+ HERE String element = JOptionPane.showInputDialog("What element do you want your pet do be pick from: water and fire");
- int StartGame = 1;
- String input= JOptionPane.showInputDialog("Enter number of players");
- int EnterPlayers = Integer.parseInt(input);
- int [] StoreEmotion = new int [3];//change to [6] later on
- String [] StoreName = new String [1];
- for(int i = 0; i<StoreEmotion.length; i++)
- {
- StoreEmotion[i] = 0;//use for later on
- }
- for(int j=StartGame; j<=EnterPlayers; j++)
- {
- for(int z = 0; z<StoreName.length; z++)
- {
- String AlienPetOne = JOptionPane.showInputDialog("Player " + j + " Pick your alien pet");
- StoreName[z] = AlienPetOne;
- System.out.println("welcome " + StoreName[z]);
- JOptionPane.showMessageDialog (null, "Round: " + j);
- //brefore interacting array
- StoreEmotion[0] = hungerlvl (AlienPetOne);
- StoreEmotion[1] = thirstlvl (AlienPetOne);
- StoreEmotion[2] = irritationlvl (AlienPetOne);
- /* after interacting array
- StoreEmotion[3] = Newhungerlvl (AlienPetOne, StoreEmotion[3]);
- StoreEmotion[4] = Newthirstlvl (AlienPetOne, StoreEmotion[4]);
- StoreEmotion[5] = Newirritationlvl (AlienPetOne, StoreEmotion[5]);
- */
- System.out.println("Player " + j + " Round: 1: " + "Hunger levevl = " + StoreEmotion[0] + " thirst level = " + StoreEmotion[1] + " irritation level = " + StoreEmotion[2] );
- /*
- System.out.println("Player " + j + " Round: 2: " + "Hunger levevl = " + StoreEmotion[3] + " thirst level = " + StoreEmotion[4] + " irritation level = " + StoreEmotion[5] );
- */
- SortA(AlienPetOne, StoreEmotion);
- System.out.println("NEXT PLAYERS TURN!");
- }
- }
- }
- public static int hungerlvl (String AlienPetOne)// added String
- {
- Random number = new Random();//random number generates
- int hunger = number.nextInt(5) + 1;//random number from 1 to 5 (+1 = starts from 1 and not 0)
- JOptionPane.showMessageDialog(null, "On a scale of 1-10 " + AlienPetOne + " hunger rate is " + hunger + "/10");
- if (hunger <=4 )
- {
- JOptionPane.showMessageDialog (null, AlienPetOne + " is hungry, You must feed him right away!");
- }
- else if (hunger >= 5 && hunger <= 7)
- {
- JOptionPane.showMessageDialog (null, AlienPetOne + " has just ate, ");
- }
- else
- {
- JOptionPane.showMessageDialog (null, AlienPetOne + " is full, do not over feed him");
- }
- // Newhungerlvl (AlienPetOne, hunger);
- return hunger;
- }
- public static int thirstlvl (String AlienPetOne)
- {
- Random number = new Random();//random number generates
- int thirst = number.nextInt(5) + 1;//random number from 1 to 10 (+1 = starts from 1 and not 0)
- JOptionPane.showMessageDialog(null, "On a scale of 1-10 " + AlienPetOne + " thirst rate is " + thirst + "/10");
- if (thirst <=4 )
- {
- JOptionPane.showMessageDialog (null, AlienPetOne + " is thirsty, GET MOVING!");
- }
- else if (thirst >= 5 && thirst <= 7)
- {
- JOptionPane.showMessageDialog (null, AlienPetOne + " Seems to be neutral and approachable");
- }
- else
- {
- JOptionPane.showMessageDialog (null, AlienPetOne + " is a happy bunny");
- }
- // Newthirstlvl (AlienPetOne, thirst);
- return thirst;
- }
- public static int irritationlvl (String AlienPetOne)// (String AlienPetOne, int EnterPlayers)
- {
- Random number = new Random();//random number generates
- int irritation = number.nextInt(5) + 1;//random number from 1 to 10 (+1 = starts from 1 and not 0)
- JOptionPane.showMessageDialog(null, "On a scale of 1-10 " + AlienPetOne + " irritation rate is " + irritation + "/10");
- if (irritation <=4 )
- {
- JOptionPane.showMessageDialog (null, AlienPetOne + " is annoyed, play with it!");
- }
- else if (irritation >= 5 && irritation <= 7)
- {
- JOptionPane.showMessageDialog (null, AlienPetOne + " is calm and happy!");
- }
- else
- {
- JOptionPane.showMessageDialog (null, AlienPetOne + " is ecstatic!");
- }
- // Newirritationlvl (AlienPetOne, irritation);
- return irritation;
- }
- public static void SortA(String AlienPetOne, int [] StoreEmotion)
- {
- for (int pass=1; pass<3; pass++)
- {
- for(int i = 0; i<3; i++)
- {
- if (StoreEmotion[i] > StoreEmotion[i+1])
- {
- int tmp = StoreEmotion[i+1];
- StoreEmotion[i+1] = StoreEmotion[i];
- StoreEmotion[i] = tmp;
- System.out.println(tmp);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement