Advertisement
WilleMahMille

Exempel - Human

Nov 8th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Human {
  8.     class Program {
  9.         static void Main(string[] args) {
  10.  
  11.             Forum flashback = new Forum();
  12.             flashback.members.Add(new Spanish());
  13.             flashback.members.Add(new Swedish());
  14.             flashback.members.Add(new English());
  15.             Console.WriteLine("Humans created: " + Human.objectsCreated);
  16.             flashback.MakePeopleTalk();
  17.             Console.ReadKey(true);
  18.         }
  19.     }
  20.     public class Forum {
  21.         public Forum() {
  22.             members = new List<Human>();
  23.         }
  24.         public void MakePeopleTalk() {
  25.             foreach(Human h in members) {
  26.                 h.Talk();
  27.             }
  28.         }
  29.         public List<Human> members;
  30.     }
  31.     public interface INationalSong {
  32.         string getNationalSongTitle();
  33.     }
  34.     public abstract class Human {
  35.         public static int objectsCreated { get; private set; } = 0;
  36.         public Human() { objectsCreated++; }
  37.         public virtual void Talk() {
  38.             Console.WriteLine("The human says: hi mi estas viro");
  39.         }
  40.         public abstract void sayHello();
  41.     }
  42.     public class Swedish : Human, INationalSong {
  43.         public Swedish() { }
  44.         public void sing() {
  45.             Console.WriteLine("Nä, här i sverige sjunger man inte");
  46.         }
  47.         public override void Talk() {
  48.             Console.WriteLine("The swede says: flashback forum är ju där man får lite vett om världen");
  49.         }
  50.         public override void sayHello() {
  51.             Console.WriteLine("Tjänare Bengt");
  52.         }
  53.         string INationalSong.getNationalSongTitle() {
  54.             return "Du gamla du fria";
  55.         }
  56.     }
  57.     public class English : Human {
  58.         public English() { }
  59.         public override void sayHello() {
  60.             Console.WriteLine("Good evening, sir");
  61.         }
  62.         public override void Talk() {
  63.             Console.WriteLine("The englishman says: it's tea o'clock *slurp slurp*");
  64.         }
  65.     }
  66.     public class Spanish : Human {
  67.         public Spanish() { }
  68.         public override void sayHello() {
  69.             Console.WriteLine("Ni hao");
  70.         }
  71.         public override void Talk() {
  72.             Console.WriteLine("The spaniard says: hola hola maldito burrito");
  73.         }
  74.     }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement