Advertisement
butoff

Mordor’s Cruel Plan

Feb 24th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. public class Program
  5. {
  6.     static void Main()
  7.     {
  8.         int points = 0;
  9.         FoodCreator fc = new FoodCreator();
  10.         string[] delimiter = new string[] { " " };
  11.         string[] data = Console.ReadLine().Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
  12.         foreach (string str in data)
  13.         {
  14.             var food = fc.CreateFood(str);
  15.             points += food.Points;
  16.         }
  17.  
  18.         Console.WriteLine(points);
  19.         Console.WriteLine(Evaluate(points));
  20.     }
  21.     public static string Evaluate(int points)
  22.     {
  23.         if (points < -5)
  24.         {
  25.             return "Angry";
  26.         }
  27.         else if (points >= -5 && points <= 0)
  28.         {
  29.             return "Sad";
  30.         }
  31.         else if (points >= 1 && points <= 15)
  32.         {
  33.             return "Happy";
  34.         }
  35.         return "JavaScript";
  36.     }
  37.  
  38. }
  39. class Food
  40. {
  41.     private int points;
  42.  
  43.     public int Points
  44.     {
  45.         get { return points; }
  46.         set { points = value; }
  47.     }
  48. }
  49. class Apple : Food
  50. {
  51.     public Apple(int points) { base.Points = points; }
  52. }
  53. class Cram : Food
  54. {
  55.     public Cram(int points) { base.Points = points; }
  56. }
  57. class Lembas : Food
  58. {
  59.     public Lembas(int points) { base.Points = points; }
  60. }
  61. class Melon : Food
  62. {
  63.     public Melon(int points) { base.Points = points; }
  64. }
  65. class HoneyCake : Food
  66. {
  67.     public HoneyCake(int points) { base.Points = points; }
  68. }
  69. class Mushrooms : Food
  70. {
  71.     public Mushrooms(int points) { base.Points = points; }
  72. }
  73. class Other : Food
  74. {
  75.     public Other(int points) { base.Points = points; }
  76. }
  77.  
  78. abstract class Creator
  79. {
  80.     public abstract Food CreateFood(string type);
  81. }
  82.  
  83. class FoodCreator : Creator
  84. {
  85.     public override Food CreateFood(string type)
  86.     {
  87.         switch (type.ToLower())
  88.         {
  89.             case "cram": return new Cram(2);
  90.             case "lembas": return new Lembas(3);
  91.             case "apple": return new Apple(1);
  92.             case "melon": return new Melon(1);
  93.             case "honeycake": return new HoneyCake(5);
  94.             case "mushrooms": return new Mushrooms(-10);
  95.             default: return new Other(-1);
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement