我正在编写此程序,用户可以与“宠物”进行交互。 宠物应该有随机的口渴,饥饿和烦躁程度。 并且用户应该能够通过喂食(降低饥饿分数),唱歌(降低烦躁评分)和给予水(降低口渴水平)来降低水平。
我现在对它进行了一些修改,并想知道如何将情绪状态存储到数组中
我有点卡住了,不胜感激。
import javax.swing.*;
import java.util.Random;
public class petInteraction
{
public static void main(String[] args)
{
petEmotion();
System.exit(0);
} //ENDS main
public static String petInteraction() //Use this further on in petEmotion()
{
String petName;
petName = JOptionPane.showInputDialog("What is your pet called?");
System.out.println("Oh cool, " + petName + " is a very unique name!");
Random emotion = new Random();
int hungerLVL = emotion.nextInt(10) + 1;
if (hungerLVL == 1 || hungerLVL == 2 || hungerLVL == 3)
{
System.out.println(petName + " is feeling Calm.");
}
else if (hungerLVL == 4 || hungerLVL == 5 || hungerLVL == 6 )
{
System.out.println(petName + " is feeling tetchy!");
}
else if (hungerLVL == 7 || hungerLVL == 8 || hungerLVL == 9 || hungerLVL == 10 )
{
System.out.println(petName + " is DANGEROUS RIGHT NOW!!!.");
}
return petName;
} //ENDS petInteraction
public static void petEmotion() //This method changes the emotional states of the pet.
{
String petname;
petname = petInteraction();
for (int round =1; round <=4; round++) //Generate random values for the Pet's emotional levels.
{
Random emotion = new Random();
int irritabilityLVL = emotion.nextInt(10) + 1;
int thirstLVL = emotion.nextInt(10) + 1;
int hungerLVL = emotion.nextInt(10) + 1;
System.out.println(petname + "'s irrtability level is " + irritabilityLVL);
System.out.println(petname + "'s thirst level is " + thirstLVL);
System.out.println(petname + "'s hunger level is " + hungerLVL);
String askToReduceIrritable = JOptionPane.showInputDialog("Would you like to sing for " + petname + " in order to lower the pets irritability level?");
if (askToReduceIrritable.equals("Yes") || askToReduceIrritable.equals ("yes"))
{
irritabilityLVL = irritabilityLVL - 1;
System.out.println(petname + "'s irrtability level is now " + irritabilityLVL);
}
String askToReduceThirst = JOptionPane.showInputDialog("Would you like to give " + petname + " some water in order to reduce the thirst level?");
if (askToReduceThirst.equals("Yes") || askToReduceThirst.equals ("yes"))
{
thirstLVL = thirstLVL - 1;
System.out.println(petname + "'s thirst level is now " + thirstLVL);
}
String askToReduceHunger = JOptionPane.showInputDialog("Would you like to give " + petname + " some food in order to reduce the hunger level?");
if (askToReduceHunger.equals("Yes") || askToReduceHunger.equals ("yes"))
{
hungerLVL = hungerLVL - 1;
System.out.println(petname + "'s hunger level is now " + hungerLVL);
}
System.out.println("");
JOptionPane.showMessageDialog(null, "A new round has begun!");
}
}//ENDS petEmotion
} //ENDS Class alientpetprogram