Advertisement
Vickyyy01

Dog Name & Breed - my solution

Dec 14th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2.  
  3. public interface IDog
  4. {
  5.     string Name {get;}
  6.     string Breed {get;}
  7. }
  8.  
  9. public class Dog: IDog
  10. {
  11.     public string Name {get;}
  12.     public string Breed {get;}
  13.    
  14.     public Dog(string name, string breed)
  15.     {
  16.         this.Name = name;
  17.         this.Breed = breed;
  18.     }
  19.    
  20.     public Dog()
  21.     {
  22.     }
  23.    
  24.     public override string ToString()
  25.     {
  26.         string s;
  27.        
  28.         if(this.Breed != null && this.Name != null)
  29.         {
  30.            s = string.Format("The {0} dog {1} said BARK!",this.Breed,this.Name);
  31.         }
  32.         else
  33.         {
  34.             s = null;
  35.         }
  36.         return s;
  37.     }
  38. }
  39.                    
  40. public class Program
  41. {
  42.     public static void Main()
  43.     {
  44.       string breed = "poodle";
  45.       string name = "Angel";
  46.        
  47.         Dog poodle = new Dog(name,breed);
  48.         Console.WriteLine(poodle);
  49.        
  50.         Dog shephard = new Dog();
  51.         Console.WriteLine(shephard);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement