4.Object Oriented Programming – Principles, Part I

01.We are given a school. In the school there are classes of students. Each class has a set of teachers. Each teacher teaches a set of disciplines. Students have name and unique class number. Classes have unique text identifier. Teachers have name. Disciplines have name, number of lectures and number of exercises. Both teachers and students are people. Students, classes, teachers and disciplines could have optional comments (free text block).

Your task is to identify the classes (in terms of OOP) and their attributes and operations, encapsulate their fields, define the class hierarchy and create a class diagram with Visual Studio.

Решение:
SchoolClassDiagram

class Class.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01.School
{
    public class Class : Comment
    {
        // Fields
        private List<Students> students;
        private List<Teachers> teachers;
        private string classID;

        // Constructor
        public Class(List<Students> students, List<Teachers> teachers, string classID)
        {
            this.students = students;
            this.teachers = teachers;
            this.classID = classID;
        }

        // Properties
        public List<Students> Students
        {
            get { return this.students; }
            set { this.students = value; } 
        }

        public List<Teachers> Teachers
        {
            get { return this.teachers; }
            set { this.teachers = value; } 
        }

        public string ClassID 
        {
            get { return this.classID; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Class ID cannot be null!");
                }
                else
                {
                    this.classID = value;
                }
            }
        }

        // Methods
        // Ovveride ToString()
        public override string ToString()
        {
            // Print information about students
            Console.WriteLine("Students .....");
            foreach (var element in Students)
            {
                Console.WriteLine("Full name: {0}, Class: {1}, ClassID: {2}", element.FirstName + " " + element.LastName, element.StudentClassNumber, ClassID);
            }
            Console.WriteLine();

            // Print information about teachers
            Console.WriteLine("Teachers .....");
            foreach (var element in Teachers)
            {
                Console.WriteLine("Full name: {0} \n\nDisciplines: ", element.FirstName + " " + element.LastName);

                foreach (var item in element.Discipline)
                {
                    Console.WriteLine("Discipline name: " + item.DisciplineName);
                    Console.WriteLine("Number of lectures: " + item.NumberOfLectures);
                    Console.WriteLine("Number of exercises: " + item.NumberOfExercises);
                    Console.WriteLine();
                }
            }

            return base.ToString();
        }
    }
}

class Comment.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01.School
{
    public class Comment
    {
        // Fields
        private List<string> inputComment;

        // Constructor
        public Comment()
        {
            this.InputComment = new List<string>();
        }

        // Properties
        public List<string> InputComment 
        {
            get { return this.inputComment; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Comment cannot be null!");
                }
                else
                {
                    this.inputComment = value;
                }
            }
        } 
      
        // Methods
        // Add comment
        public void AddComment(string inputComment)
        {
            InputComment.Add(inputComment);
        }

        // Print commentss
        public void PrintComment()
        {
            foreach (var element in InputComment)
            {
                Console.WriteLine("Comment: " + element);
            }
        }
    }
}

class Discipline.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01.School
{
    public class Discipline : Comment
    {
        // Fields
        private string disciplineName;
        private int numberOfLectures;
        private int numberOfExercises;

        // Constructor
        public Discipline(string disciplineName, int numberOfLectures, int numberOfExercises)
        {
            this.disciplineName = disciplineName;
            this.numberOfLectures = numberOfLectures;
            this.numberOfExercises = numberOfExercises;
        }

        // Properties
        public string DisciplineName 
        {
            get { return this.disciplineName; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Discipline name cannot be null!");
                }
                else
                {
                    this.disciplineName = value;
                }
            }
        }

        public int NumberOfLectures 
        {
            get { return this.numberOfLectures; }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentNullException("Number of lectures cannot be negative or zero!");
                }
                else
                {
                    this.numberOfLectures = value;
                }
            }
        }

        public int NumberOfExercises 
        {
            get { return this.numberOfExercises; }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentNullException("Number of exercises cannot be null!");
                }
                else
                {
                    this.numberOfExercises = value;
                }
            }
        }
    }
}

class Person.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01.School
{
    public class Person : Comment
    {
        // Fields
        private string firstName;
        private string lastName;

        // Constructor
        public Person(string firstName, string lastName)
        {
            this.firstName = firstName;
            this.lastName = lastName;
        }

        // Properties
        public string FirstName 
        {
            get { return this.firstName; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("First name cannot be null!");
                }
                else
                {
                    this.firstName = value;
                }
            }
        }

        public string LastName 
        {
            get { return this.lastName; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Last name cannot be null!");
                }
                else
                {
                    this.lastName = value;
                }
            }
        }
    }
}

class School.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01.School
{
    public class School
    {
        // Fields
        private string schoolName;
        private List<Class> classes;

        //Constructor
        public School(List<Class> classes, string schoolName)
        {
            this.classes = classes;
            this.schoolName = schoolName;
        }

        // Properties
        public string SchoolName 
        {
            get{return this.schoolName;}
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("School name cannot be null!");
                }
                else
                {
                    this.schoolName = value;
                }
            }
        }

        public List<Class> Classes
        {
            get { return this.classes; }
            set { this.classes = value; }
        }

        // Methods
        // Print school name
        public void PrintSchoolName()
        {
            Console.WriteLine("---------- {0} ----------\n", SchoolName);
        }
    }
}

class Students.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01.School
{
    public class Students : Person
    {
        // Fields
        private int studentClassNumber;

        // Constructor
        public Students(string firstName, string lastName, int studentClassNumber)
            : base(firstName, lastName)
        {
            this.studentClassNumber = studentClassNumber;
        }

        // Properties
        public int StudentClassNumber 
        {
            get { return this.studentClassNumber; }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentNullException("Student class number cannot be negative or zero!");
                }
                else
                {
                    this.studentClassNumber = value;
                }
            }
        }
    }
}

class Teachers.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01.School
{
    public class Teachers : Person
    {
        // Fields
        private List<Discipline> discipline;

        // Constructor
        public Teachers(string firstName, string lastName, List<Discipline> discipline)
            : base(firstName, lastName)
        {
            this.discipline = discipline;
        }

        // Properties
        public List<Discipline> Discipline 
        {
            get { return this.discipline; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Discipline cannot be null!");
                }
                else
                {
                    this.discipline = value;
                }
            }
        }
    }
}

class Test.cs

//01.We are given a school. In the school there are classes of students. Each class has a set of teachers. 
//Each teacher teaches a set of disciplines. Students have name and unique class number. Classes have unique 
//text identifier. Teachers have name. Disciplines have name, number of lectures and number of exercises. 
//Both teachers and students are people. Students, classes, teachers and disciplines could have optional 
//comments (free text block).
    
//Your task is to identify the classes (in terms of  OOP) and their attributes and operations, encapsulate 
//their fields, define the class hierarchy and create a class diagram with Visual Studio.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01.School
{
    public class Test
    {
        static void Main(string[] args)
        {
            Students plamenStudent = new Students("Plamen", "Georgiev", 12);
            plamenStudent.AddComment("Plamen is a good student");

            Students peshoStudent = new Students("Pesho", "Peshov", 2);
            peshoStudent.AddComment("Pesho is a bad student");

            Students ivaStudent = new Students("Iva", "Ivanova", 7);
            ivaStudent.AddComment("Iva is poor student");

            Discipline mathematics = new Discipline("Mathematics", 2, 2);
            mathematics.AddComment("I like Mathematics");

            Discipline physics = new Discipline("Physics", 8, 4);
            Discipline chemistry = new Discipline("Chemistry", 3, 2);
            Discipline economy = new Discipline("Economy", 1, 1);

            Teachers mariaTeacher = new Teachers("Maria", "Dimitrova", new List<Discipline>() { mathematics, physics, chemistry });
            mariaTeacher.AddComment("Maria Dimitrova is a great teacher");

            Teachers goshoTeacher = new Teachers("Gosho", "Goshov", new List<Discipline>() { economy });
            Class firstClass = new Class(new List<Students>() { plamenStudent, peshoStudent}, new List<Teachers>() { mariaTeacher }, "A");
            Class secondClass = new Class(new List<Students>() { ivaStudent }, new List<Teachers>() { goshoTeacher }, "B");

            School school = new School(new List<Class>() { firstClass, secondClass }, "SOU \"Vasil Levski\"");
            school.PrintSchoolName();
            firstClass.ToString();
            secondClass.ToString();

            // Show comments
            plamenStudent.PrintComment();
            peshoStudent.PrintComment();
            ivaStudent.PrintComment();
            mathematics.PrintComment();
            mariaTeacher.PrintComment();
        }
    }
}

02.Define abstract class Human with first name and last name. Define new class Student which is derived from Human and has new field – grade. Define class Worker derived from Human with new property WeekSalary and WorkHoursPerDay and method MoneyPerHour() that returns money earned by hour by the worker. Define the proper constructors and properties for this hierarchy. Initialize a list of 10 students and sort them by grade in ascending order (use LINQ or OrderBy() extension method). Initialize a list of 10 workers and sort them by money per hour in descending order.
Merge the lists and sort them by first name and last name.

Решение:

class Human.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _02.HumanStudentWorker
{
    public abstract class Human
    {
        // Fields
        private string firstName;
        private string lastName;

        // Constructor
        public Human(string firstName, string lastName)
        {
            this.firstName = firstName;
            this.lastName = lastName;
        }

        // Properties
        public string FirstName
        {
            get { return this.firstName; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("First name cannot be null!");
                }
                else
                {
                    this.firstName = value;
                }
            }
        }

        public string LastName
        {
            get { return this.lastName; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Last name cannot be null!");
                }
                else
                {
                    this.lastName = value;
                }
            }
        }
    }
}

class Student.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _02.HumanStudentWorker
{
    public class Student : Human
    {
        // Fields
        private int grade;

        // Constructor
        public Student(string firstName, string lastName, int grade)
            : base (firstName, lastName)
        {
            this.grade = grade;
        }

        // Properties
        public int Grade 
        {
            get { return this.grade; }
            set
            {
                if (value < 1 || value > 12)
                {
                    throw new ArgumentException("Grade cannot be different by the range 1-12!");
                }
                else
                {
                    this.grade = value;
                }
            }
        }
    }
}

class Worker.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _02.HumanStudentWorker
{
    public class Worker : Human
    {
        // Fields
        private double weekSalary;
        private int workHoursPerDay;

        // Constructor
        public Worker(string firstName, string lastName, double weekSalary, int workHoursPerDay)
            : base(firstName, lastName)
        {
            this.weekSalary = weekSalary;
            this.workHoursPerDay = workHoursPerDay;
        }

        // Properties
        public double WeekSalary 
        {
            get { return this.weekSalary; }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentException("Week salary cannot be negative or zero!");
                }
                else
                {
                    this.weekSalary = value;
                }
            }
        }

        public int WorkHoursPerDay 
        {
            get { return this.workHoursPerDay; }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentException("Work hours per day cannot be negatice or zero!");
                }
                else
                {
                    this.workHoursPerDay = value;
                }
            }
        }

        // Methods
        // Calculate money earned by hour by the worker
        public double MoneyPerHour()
        {
            int workHoursPerWeek = (5 * this.workHoursPerDay);
            double moneyPerHour = this.weekSalary / workHoursPerWeek;

            return moneyPerHour;
        }
    }
}

class Test.cs

//02.Define abstract class Human with first name and last name. Define new class Student which is derived from 
//Human and has new field – grade. Define class Worker derived from Human with new property WeekSalary and 
//WorkHoursPerDay and method MoneyPerHour() that returns money earned by hour by the worker. Define the proper 
//constructors and properties for this hierarchy. Initialize a list of 10 students and sort them by grade in ascending 
//order (use LINQ or OrderBy() extension method). Initialize a list of 10 workers and sort them by money per 
//hour in descending order. Merge the lists and sort them by first name and last name.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _02.HumanStudentWorker
{
    class Test
    {
        // Sort students by grade in ascending order, using LINQ
        static void SortStudentByGrade(List<Student> studentsList)
        {
            var sortedList =
                from stud in studentsList
                orderby stud.Grade ascending
                select stud;

            // Print sorted students
            Console.WriteLine("---------- STUDENTS ----------");
            foreach (var element in sortedList)
            {
                Console.WriteLine("Full name: {0}, Grade: {1}", element.FirstName + " " + element.LastName, element.Grade);
            }

            Console.WriteLine();
        }

        // Sort workers by money per hours in descending  order, using LINQ
        static void SortWorkersByMoneyPerHours(List<Worker> workersList)
        {
            var sortedList = workersList.OrderByDescending(x => x.MoneyPerHour());

            // Print workers
            Console.WriteLine("---------- WORKERS ----------");
            foreach (var element in sortedList)
            {
                Console.WriteLine("Full name: {0}", element.FirstName+ " " + element.LastName);
                Console.WriteLine("Week salary: " + element.WeekSalary);
                Console.WriteLine("Work hours per day: " + element.WorkHoursPerDay);
                Console.WriteLine("Money per hours: " + element.MoneyPerHour());
                Console.WriteLine();
            }
        }

        // Sort merged list by first name and last name
        static void SortMergedList(List<Human> mergedList)
        {
            var sortedList =
                from merge in mergedList
                orderby merge.FirstName, merge.LastName
                select merge;

            // Print merged list
            Console.WriteLine("---------- MERGED LIST ----------");
            foreach (var element in sortedList)
            {
                Console.WriteLine("First name: {0}, Last name: {1}", element.FirstName, element.LastName);
            }
        }

        static void Main(string[] args)
        {
            // List of 10 students
            List<Student> studentsList = new List<Student>()
            {
                new Student("Plamen", "Georgiev", 12),
                new Student("Ivan", "Ivanov", 1),
                new Student("Gosho", "Goshov", 1),
                new Student("Katrin", "Dimitrova", 3),
                new Student("Pesho", "Peshov", 9),
                new Student("Maria", "Borisova", 5),
                new Student("Gabriela", "Marinova", 3),
                new Student("Petko", "Petkov", 8),
                new Student("Kiril", "Kirilov", 8),
                new Student("Dimitar", "Dimitrov", 4)
            };

            // List of 10 workers
            List<Worker> workersList = new List<Worker>()
            {
                new Worker("Kosta", "Kostov", 555, 4),
                new Worker("Krum", "Krumov", 900, 12),
                new Worker("Mira", "Stamenova", 100, 40),
                new Worker("Petka", "Petkanova", 1021, 50),
                new Worker("Stefan", "Stefanov", 200, 21),
                new Worker("Jordan", "Jordanov", 111, 10),
                new Worker("Nikolay", "Georgiev", 1000, 9),
                new Worker("Stamat", "Stamatov", 11, 11),
                new Worker("Goran", "Goranov", 88, 8),
                new Worker("Samuil", "Samuilov", 1111, 11)
            };

            // Call methods
            SortStudentByGrade(studentsList);
            SortWorkersByMoneyPerHours(workersList);

            // Merge studentsList and workersList
            List<Human> mergeList = new List<Human>();
            mergeList.AddRange(studentsList);
            mergeList.AddRange(workersList);

            // Call method
            SortMergedList(mergeList);
        }
    }
}

03.Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define useful constructors and methods. Dogs, frogs and cats are Animals. All animals can produce sound (specified by the ISound interface). Kittens and tomcats are cats. All animals are described by age, name and sex. Kittens can be only female and tomcats can be only male. Each animal produces a specific sound. Create arrays of different kinds of animals and calculate the average age of each kind of animal using a static method (you may use LINQ).

Решение:
AnimalsClassDiagram

class Animal.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _03.Animals
{
    public abstract class Animal : ISound
    {
        // Fields
        private string name;
        private int age;
        private string sex;

        // Constructor
        public Animal(string name, int age, string sex)
        {
            this.name = name;
            this.age = age;
            this.sex = sex;
        }

        // Properties
        public string Name 
        {
            get { return this.name; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Animal name cannot be null!");
                }
                else
                {
                    this.name = value;
                }
            }
        }

        public int Age
        {
            get { return this.age; }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentException("Animal age cannot be negative or zero!");
                }
                else
                {
                    this.age = value;
                }
            }
        }

        public string Sex 
        {
            get { return this.sex; }
            set
            {
                if (value == null || (value != "male" && value != "female"))
                {
                    throw new ArgumentNullException("Animal sex cannot be null or different from male or female!");
                }
                else
                {
                    this.sex = value;
                }
            }
        }

        // Methods

        // Produce sound
        public abstract void Sound();

        // Calculate average age of each kind of animal
        public static double CalculateAverageAge(Animal [] animal)
        {
            double sum = 0;

            foreach (var element in animal)
            {
                sum += element.Age;
            }

            double result = sum / animal.Length;

            return result;
        }
    }
}

class Cat.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _03.Animals
{
    public class Cat : Animal
    {
        // Fields
        private string catBreed;

        // Constructor
        public Cat(string name, int age, string sex, string catBreed)
            : base(name, age, sex)
        {
            this.catBreed = catBreed;
        }

        // Properties
        public string CatBreed 
        {
            get { return this.catBreed; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Cat breed cannot be null!");
                }
                else
                {
                    this.catBreed = value;
                }
            }
        }

        //Methods
        // Produce sound
        public override void Sound()
        {
            Console.WriteLine("Cat {0} say: miaowwww", this.Name);
        }
    }
}

class Dog.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _03.Animals
{
    public class Dog : Animal
    {
        // Fields
        private string dogBreed;

        // Constructor
        public Dog(string name, int age, string sex, string dogBreed)
            : base(name, age, sex)
        {
            this.dogBreed = dogBreed;
        }

        // Properties
        public string DogBreed 
        {
            get { return this.dogBreed; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Dog breed cannot be null!");
                }
                else
                {
                    this.dogBreed = value;
                }
            }
        }

        //Methods
        // Produce sound
        public override void Sound()
        {
            Console.WriteLine("Dog {0} say: bow-wowwww", this.Name);
        }
    }
}

class Frog.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _03.Animals
{
    public class Frog : Animal
    {
        // Fields
        private string frogBreed;

        // Constructor
        public Frog(string name, int age, string sex, string frogBreed)
            : base(name, age, sex)
        {
            this.frogBreed = frogBreed;
        }

        // Properties
        public string FrogBreed 
        {
            get { return this.frogBreed; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Frog breed cannot be null!");
                }
                else
                {
                    this.frogBreed = value;
                }
            }
        }

        // Methods
        // Produce sound
        public override void Sound()
        {
            Console.WriteLine("Frog {0} say: ribbitttt", this.Name);
        }
    }
}

interface ISound

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _03.Animals
{
    public interface ISound
    {
        void Sound();
    }
}

class Kitten.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _03.Animals
{
    public class Kitten : Cat
    {
        // Constructor
        public Kitten(string name, int age, string sex, string gender)
            : base(name, age, "female", gender)
        {

        }

        // Methods
        // Produce sound
        public override void Sound()
        {
            Console.WriteLine("Kitten {0} say: miaowwww", this.Name);
        }
    }
}

class Tomcat.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _03.Animals
{
    public class Tomcat : Cat
    {
        // Constructor
        public Tomcat(string name, int age, string sex, string breed)
            : base(name, age, "male", breed)
        {

        }

        // Methods
        // Produce sound
        public override void Sound()
        {
            Console.WriteLine("Tomcat {0} say: miaowwww", this.Name);
        }
    }
}

class Test.cs

//03.Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define useful constructors and methods. 
//Dogs, frogs and cats are Animals. All animals can produce sound (specified by the ISound interface). 
//Kittens and tomcats are cats. All animals are described by age, name and sex. Kittens can be only female 
//and tomcats can be only male. Each animal produces a specific sound. Create arrays of different kinds 
//of animals and calculate the average age of each kind of animal using a static method (you may use LINQ).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _03.Animals
{
    class Test
    {
        static void Main(string[] args)
        {
            // Array of dogs
            Dog[] dogs = new Dog[] 
            {
                new Dog("Sharo", 3, "male", "Labrador"),
                new Dog("Cujo", 2, "male", "Saint Bernard"),
                new Dog("Rex", 6, "female", "German Shepherd"),
                new Dog("Lassie", 4, "female", "Collie")
            };

            // Array of cats
            Cat[] cats = new Cat[]
            {
                new Cat("Tom", 2, "male", "Balinese"),
                new Cat("Sarah", 5, "female", "Bombay"),
                new Cat("Iva", 1, "female", "Cymric"),
                new Cat("Gosho", 9, "male", "Javanese")
            };

            Tomcat tom = new Tomcat("Kiro", 9, "male", "Bombay");
            Kitten kitten = new Kitten("Sisi", 1, "female", "Cymric");

            // Array of frogs
            Frog[] frogs = new Frog[]
            {
                new Frog("Pesho", 2, "male", "Black Toad"),
                new Frog("Maria", 1, "female", "Arizona Toad"),
                new Frog("Misho", 3, "male", "Texas Toad"),
                new Frog("Petia", 8, "male", "Arroyo Toad")
            };

            // Call methods about dogs
            Console.WriteLine("Average age of dogs are: " + Dog.CalculateAverageAge(dogs));
            dogs[2].Sound();
            dogs[1].Sound();
            dogs[3].Sound();
            dogs[0].Sound();
            
            Console.WriteLine();

            // Call methods about cats
            Console.WriteLine("Average age of cats are " + Cat.CalculateAverageAge(cats));
            cats[0].Sound();
            cats[3].Sound();
            tom.Sound();
            kitten.Sound();

            Console.WriteLine();

            // Call methods about frogs
            Console.WriteLine("Average age of frogs are: " + Frog.CalculateAverageAge(frogs));
            frogs[3].Sound();
            frogs[0].Sound();
            frogs[1].Sound();
            frogs[2].Sound();

            Console.WriteLine();
        }
    }
}
Advertisements

2 responses to “4.Object Oriented Programming – Principles, Part I

  1. Hi,
    A very nice explanation of UML and class diagrams were excellent, i have just started learning about OOAD and your blog helped me a lot, especially the code.
    Kindly visit my blog and if possible give feedback on my learnings.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s