svetlozar_kirkov

Gandalf's Stash

Feb 9th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.Map;
  2. import java.util.Scanner;
  3. import java.util.TreeMap;
  4.  
  5. public class GandalfsStash {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.         Map<String,Integer> foods = new TreeMap<>();
  10.         foods.put("cram", 2);
  11.         foods.put("lembas", 3);
  12.         foods.put("apple", 1);
  13.         foods.put("melon", 1);
  14.         foods.put("honeycake", 5);
  15.         foods.put("mushrooms", -10);
  16.         int mood = Integer.parseInt(input.nextLine());
  17.         String[] inputText = input.nextLine().split("[\\W\\s\\_]+");
  18.         for (int i = 0; i < inputText.length; i++){
  19.             if (foods.containsKey(inputText[i].toLowerCase())){
  20.                 mood+=foods.get(inputText[i].toLowerCase());
  21.             }
  22.             else {
  23.                 mood--;
  24.             }
  25.         }
  26.         System.out.println(mood);
  27.         if (mood < -5){
  28.             System.out.println("Angry");
  29.         }
  30.         else if (mood >= -5 && mood < 0){
  31.             System.out.println("Sad");
  32.         }
  33.         else if (mood >= 0 && mood < 15){
  34.             System.out.println("Happy");
  35.         }
  36.         else {
  37.             System.out.println("Special JavaScript mood");
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment