repl.it
@kironroy/

polymorphism

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
  • notes.txt
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;

namespace PolymorphicPoolshapes {

  class PoolDefaultShape {
    protected int _width, _height, _depth; // class members

    // constructor  below
    public PoolDefaultShape( int width = 0, int height = 0, int depth = 0) {
      _width = width;
      _height = height;
      _depth = depth;
    }
    
    public virtual int volume() {
      Console.WriteLine("Pool default volume: ");
      return 1000; 
    }
  } // Class PoolDefaultShape END 



  class RectangularShape : PoolDefaultShape {
    public RectangularShape( int width = 0, int height = 0, int depth = 0): base(width,height,depth) {

    }

    public override int volume() {
      Console.WriteLine("Rectangular pool volume: ");
      return (_width * _height * _depth);
    }
  } // Class RectangularShape END



  class TriangularShape : PoolDefaultShape {
    public TriangularShape( int width = 0, int height = 0, int depth = 0): base(width,height,depth) {

    }

    public override int volume() {
      Console.WriteLine("Triangular pool volume: ");
      return ((_width * _height * _depth) / 2);
    }
  } // Class RectangularShape END



  class PoolVolumeCaller { 
    public void CallVolume(PoolDefaultShape sh) {
      int pooldimension;
      pooldimension = sh.volume();
      Console.WriteLine($"{pooldimension} cubic feet");
    }
  } // Class PoolVolumeCaller END 



  class PoolPrintOuts {
    static void Main(string[]args) {

      // Default pool object
      var poolPrintDef = new PoolVolumeCaller(); // object init
      var clientDefault = new PoolDefaultShape(20, 10, 6);
      poolPrintDef.CallVolume(clientDefault);

      Console.WriteLine(); // breakline
      
      // Rectangular pool object
      var poolPrintOutRect = new PoolVolumeCaller(); // object init
      var clientRectangle = new RectangularShape(23, 12, 8);
      poolPrintOutRect.CallVolume(clientRectangle);

      Console.WriteLine(); // breakline
    
      // Triangular pool object
      var poolPrintOutTri = new PoolVolumeCaller(); // object init
      var clientTriangle = new TriangularShape(33, 13, 7);
      poolPrintOutTri.CallVolume(clientTriangle);


    }
  }

} // PolymorphicPoolshapes namespace END