LardaX

Gandalf

Mar 3rd, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package mordorsCrueltyPlan;
  2.  
  3. /**
  4.  * Created by Venelin on 3.3.2017 г..
  5.  */
  6. public class Gandalf {
  7.  
  8.     private int happiness;
  9.  
  10.     @Override
  11.     public String toString() {
  12.         return this.getHappiness() + System.lineSeparator() + this.getMood();
  13.     }
  14.  
  15.     public void eat(Food food) {
  16.         String type = food.getType().toLowerCase();
  17.  
  18.         switch (type) {
  19.             case "cram":
  20.                 this.happiness += 2;
  21.                 break;
  22.             case "lembas":
  23.                 this.happiness += 3;
  24.                 break;
  25.             case "apple":
  26.             case "melon":
  27.                 this.happiness += 1;
  28.                 break;
  29.             case "honeycake":
  30.                 this.happiness += 5;
  31.                 break;
  32.             case "mushrooms":
  33.                 this.happiness -= 10;
  34.             default:
  35.                 this.happiness -= 1;
  36.                 break;
  37.         }
  38.     }
  39.  
  40.     private String getMood() {
  41.         int happiness = this.getHappiness();
  42.         if (happiness < -5) {
  43.             return "Angry";
  44.         } else if (happiness < 0) {
  45.             return "Sad";
  46.         } else if (happiness < 15) {
  47.             return "Happy";
  48.         } else {
  49.             return "JavaScript";
  50.         }
  51.     }
  52.  
  53.     private int getHappiness() {
  54.         return this.happiness;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment