import java.util.*;
public class Homework4 {
private static int age;
private static String name;
private static int currentHunger;
private static int currentDirtiness;
private static int currentBoredom;
private static int hungerRate;
private static int dirtyRate;
private static int boredomRate;
private static int LOW_STAT_THRESHOLD = 25;
private static int MED_STAT_THRESHOLD = 50;
private static int HIGH_STAT_THRESHOLD = 75;
private static int RUNAWAY_STAT_THRESHOLD = 100;
private static Scanner input;
public static void main(String[] args) {
createPet();
agePet();
choice();
startStatusPet();
startStatusPet();
runAwayCheck();
resultOfPlayer();
}
public static void createPet() {
age = 0;
System.out.println("A mysterious egg hatches before you!\nWhat will you name this creature?");
Scanner input = new Scanner(System.in);
name = input.nextLine();
currentHunger = 50;
currentDirtiness = 50;
currentBoredom = 50;
hungerRate = 0;
dirtyRate = 0;
boredomRate = 0;
}
public static void agePet() {
age++;
System.out.println("*********BIRTHDAY UPDATE!*********");
System.out.println(name + " is now " + age + " days old!");
if (age % 2 == 0) {
hungerRate += 1;
System.out.println(name + " gets hungrier faster!");
} else if (age % 3 == 0) {
dirtyRate += 1;
System.out.println(name + " gets dirtier faster!");
} else if (age % 5 == 0) {
boredomRate += 1;
System.out.println(name + " gets more boring!");
}
}
public static void choice() {
System.out.println("1.) Feed\n2.) Clean\n3.) Play");
System.out.println("What would you like to do with " + name);
int playerChoice = input.nextInt();
if (playerChoice == 1) {
statusAfterEating();
} else if (playerChoice == 2) {
statusAfterCleaning();
} else {
statusAfterPlaying();
}
public static void statusAfterEating () {
currentHunger -= hungerRate;
currentDirtiness += dirtyRate;
System.out.println("You feed Cleo but it makes a mess...");
}
public static void statusAfterCleaning () {
currentBoredom -= boredomRate;
currentHunger += hungerRate;
System.out.println("You bathe Cleo but if doesn't like it...");
}
public static void statusAfterPlaying () {
currentDirtiness -= dirtyRate;
currentHunger -= hungerRate;
System.out.println("You play with Cleo and it works up an appetite!");
}
}
public static void startStatusPet() {
System.out.println("*********CURRENT STATS*********");
String hungerDescription = "Hunger level: ";
System.out.println(hungerDescription + "Pretty good!");
String dirtDescription = "Cleanliness level: ";
System.out.println(dirtDescription + "Could be better...");
String boredDescription = "Boredom level: ";
System.out.println(boredDescription + "Sublime!");
public static void statusPet () {
String message = input.nextLine();
if (currentHunger <= LOW_STAT_THRESHOLD || currentDirtiness <= LOW_STAT_THRESHOLD || currentBoredom <= LOW_STAT_THRESHOLD) {
String positiveMessage = "Pretty good!";
System.out.println(positiveMessage);
} else if (currentHunger <= MED_STAT_THRESHOLD || currentDirtiness <= MED_STAT_THRESHOLD || currentBoredom <= MED_STAT_THRESHOLD) {
String concerningMessage = "Could be better...";
System.out.println(concerningMessage);
} else if (currentHunger <= HIGH_STAT_THRESHOLD || currentDirtiness <= HIGH_STAT_THRESHOLD || currentBoredom <= HIGH_STAT_THRESHOLD) {
String urgentMessage = "Sublime!";
System.out.println(urgentMessage);
} else {
System.out.println("The pet has serious problem!");
}
}
}
public static void runAwayCheck() {
if (currentHunger > RUNAWAY_STAT_THRESHOLD) {
System.out.println("The pet ran away because it was too hungry!");
}
if (currentDirtiness > RUNAWAY_STAT_THRESHOLD) {
System.out.println("The pet ran away because it was too dirty!");
}
if (currentBoredom > RUNAWAY_STAT_THRESHOLD) {
System.out.println("The pet ran away because it was too bored!");
}
}
public static void resultOfPlayer() {
System.out.println("You took care of " + name + " for " + age + " days");
if (age < 5) {
System.out.println("Try to be better next time.");
} else if (age >= 6 && age <= 15) {
System.out.println("You spent many days with " + name + "!");
} else if (age >= 16 && age <= 25) {
System.out.println("You are great virtual pet owner!");
} else if (age > 25) {
System.out.println("Great! You are ready to take care of real pet!");
}
}
}
СПАСИБО!!!