Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class Animal
- {
- //Class Variables
- public static int Count = 0;
- public string name;
- public int age;
- public float happiness;
- // Class Constructor
- public Animal ()
- {
- name = "Spotty";
- age = 6;
- happiness = 0.5f;
- Count++;
- }
- public Animal(string _name, int _age, float _happiness)
- {
- name = _name;
- age = -age;
- happiness = _happiness;
- Count++;
- }
- //Class Methods
- public void Print ()
- {
- Console.WriteLine("Name: " + name);
- Console.WriteLine("Age: " + age);
- Console.WriteLine("Happiness Level: " + happiness);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Animal dog = new Animal ();
- dog.Print();
- Console.WriteLine();
- Animal cat = new Animal("MrBeans", 10, 0.8f);
- cat.Print();
- Console.WriteLine();
- Console.WriteLine("Number of animals: " + Animal.Count );
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement