Advertisement
karlakmkj

Implementing Interface 2

Nov 24th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. //Truck class implementing Automobile interface like Sedan class
  2. using System;
  3.  
  4. namespace LearnInterfaces
  5. {
  6.   class Truck : IAutomobile
  7.   {
  8.  
  9.     //PROPERTY
  10.     public string LicensePlate
  11.     { get; }
  12.  
  13.     public double Speed
  14.     { get;
  15.     private set;}  //setter created
  16.  
  17.     public int Wheels
  18.     { get; }
  19.  
  20.     public double Weight
  21.     {get; }
  22.      
  23.     public void Honk()
  24.     {
  25.       Console.WriteLine("HONK!");
  26.     }
  27.    
  28.     //CONSTRUCTOR
  29.     public Truck(double speed, double weight){
  30.       this.Speed = speed;
  31.       this.Weight = weight;
  32.       LicensePlate = Tools.GenerateLicensePlate();
  33.       if (Weight < 400){
  34.         Wheels = 8;
  35.       }
  36.       else {
  37.         Wheels = 12;
  38.       }
  39.     }
  40.    
  41.     //need to add private setter in property in order to set the Speed property here in the methods
  42.     public void SpeedUp(){
  43.       Speed+=5;
  44.     }
  45.     public void SlowDown(){
  46.       Speed-=5;
  47.     }
  48.  
  49.   }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement