Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mordorsCrueltyPlan;
- /**
- * Created by Venelin on 3.3.2017 г..
- */
- public class Gandalf {
- private int happiness;
- @Override
- public String toString() {
- return this.getHappiness() + System.lineSeparator() + this.getMood();
- }
- public void eat(Food food) {
- String type = food.getType().toLowerCase();
- switch (type) {
- case "cram":
- this.happiness += 2;
- break;
- case "lembas":
- this.happiness += 3;
- break;
- case "apple":
- case "melon":
- this.happiness += 1;
- break;
- case "honeycake":
- this.happiness += 5;
- break;
- case "mushrooms":
- this.happiness -= 10;
- default:
- this.happiness -= 1;
- break;
- }
- }
- private String getMood() {
- int happiness = this.getHappiness();
- if (happiness < -5) {
- return "Angry";
- } else if (happiness < 0) {
- return "Sad";
- } else if (happiness < 15) {
- return "Happy";
- } else {
- return "JavaScript";
- }
- }
- private int getHappiness() {
- return this.happiness;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment