Main.java 1001 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import java.util.Scanner;
  2. public class Main{
  3. public static void main (String[] args){
  4. // read user input
  5. Scanner input = new Scanner(System.in);
  6. char userinput = 'c';
  7. // load existing pet if there is one
  8. Pet mypet = Pet.loadFromDisk();
  9. if(mypet == null){
  10. mypet = new Pet();
  11. }
  12. // main game loop
  13. System.out.println("Welcome to \"The Pet Simulator.\"");
  14. while(userinput != 'q' && mypet.isAlive()){
  15. System.out.println("Here are your pet's stats:");
  16. mypet.printStatus();
  17. System.out.println("Enter \'f,\' \'w,\' or \'r\' to feed, water, or rest your pet.");
  18. System.out.println("Enter \'q\' to save and quit.");
  19. userinput = input.next().charAt(0);
  20. if(userinput == 'f'){
  21. mypet.feed();
  22. }
  23. if(userinput == 'w'){
  24. mypet.water();
  25. }
  26. if(userinput == 'r'){
  27. mypet.rest();
  28. }
  29. }
  30. // present the bad news
  31. if(!mypet.isAlive()){
  32. System.out.println("This pet has died.");
  33. }
  34. // clean up
  35. mypet.saveToDisk();
  36. input.close();
  37. }
  38. }