Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- interface IInformation
- {
- int ShowParameters();
- double area{
- get;
- }
- bool Check();
- }
- class Room : IEquatable<Room>,IInformation
- {
- static protected int number_of_rooms = 0;
- protected double height;
- protected double width;
- protected double length;
- public bool Equals(Room temp)
- {
- if (temp.height == this.height
- && temp.width == this.width
- && temp.length == this.length)
- return true;
- else
- return false;
- }
- public double this[string index]
- {
- get
- {
- switch (index)
- {
- case "height":
- return height;
- case "width":
- return width;
- case "length":
- return length;
- case "area":
- return area;
- default:
- return 0;
- }
- }
- set
- {
- switch (index)
- {
- case "height":
- height = value;
- break;
- case "width":
- width = value;
- break;
- case "length":
- length = value;
- break;
- default:
- return;
- }
- }
- }
- public double area
- {
- get
- {
- return height * width * length;
- }
- }
- public virtual bool Check()
- {
- if (height > 0 && width > 0 && length > 0) return true;
- else return false;
- }
- private bool Check(double a, double b, double c)
- {
- if (a > 0 && b > 0 && c > 0) return true;
- else return false;
- }
- static public void ShowNumber()
- {
- Console.WriteLine("Number of rooms: {0}", number_of_rooms);
- }
- public Room()
- {
- number_of_rooms += 1;
- }
- public Room(double new_height, double new_width, double new_length)
- {
- height = new_height;
- width = new_width;
- length = new_length;
- number_of_rooms += 1;
- }
- public virtual int ShowParameters()
- {
- if (Check())
- {
- Console.WriteLine("Height: {0}\nWidth: {1}\nLength: {2}", height, width, length);
- }
- else
- {
- Console.WriteLine("Incorrect parameters");
- }
- return 0;
- }
- public int ShowArea()
- {
- if (Check())
- {
- Console.WriteLine("Area : {0}", area);
- }
- else
- {
- Console.WriteLine("Incorrect parameters");
- }
- return 0;
- }
- public int ChangeParameters(double new_height, double new_width, double new_length)
- {
- if (Check(new_height, new_width, new_length))
- {
- height = new_height;
- width = new_width;
- length = new_length;
- return 0;
- }
- else
- {
- Console.WriteLine("Incorrect parameters");
- return 0;
- }
- }
- }
- abstract class LivingRoom : Room, IEquatable<LivingRoom>, IInformation
- {
- protected int people;
- public override bool Check()
- {
- if (height > 0 && width > 0 && length > 0 && people >= 0) return true;
- else return false;
- }
- protected bool Check(double a, double b, double c, int z)
- {
- if (a > 0 && b > 0 && c > 0 && z >= 0) return true;
- else return false;
- }
- public bool Equals(LivingRoom temp)
- {
- if (base.Equals(temp)
- && temp.people == this.people
- )
- return true;
- else
- return false;
- }
- public int ChangeParameters(double new_height, double new_width, double new_length, int new_people = 0)
- {
- if (Check(new_height, new_width, new_length, people))
- {
- height = new_height;
- width = new_width;
- length = new_length;
- people = new_people;
- return 0;
- }
- else
- {
- Console.WriteLine("Incorrect parameters");
- return 0;
- }
- }
- public override int ShowParameters()
- {
- if (Check())
- {
- Console.WriteLine("Height: {0}\nWidth: {1}\nLength: {2}\nPeople: {3}", height, width, length, people);
- }
- else
- {
- Console.WriteLine("Incorrect parameters");
- }
- return 0;
- }
- public LivingRoom(double new_height, double new_width, double new_length, int new_people) : base(new_height,new_width,new_length)
- {
- height = new_height;
- width = new_width;
- length = new_length;
- people = new_people;
- number_of_rooms += 1;
- }
- }
- class Bedroom : LivingRoom, IEquatable<Bedroom>, IInformation
- {
- public struct bedChars
- {
- public int beds;
- public bool isDecorated;
- public bool isRepaired;
- public bedChars(int new_beds, bool decorated, bool repaired)
- {
- beds = new_beds;
- isDecorated = decorated;
- isRepaired = repaired;
- }
- }
- public bedChars chars;
- public bool Equals(Bedroom temp)
- {
- if (base.Equals(temp)
- && this.chars.beds == temp.chars.beds
- && this.chars.isDecorated == temp.chars.isDecorated
- && this.chars.isRepaired == temp.chars.isRepaired
- )
- return true;
- else
- return false;
- }
- public int ChangeChars(int new_beds, bool decorated, bool repaired)
- {
- chars.beds = new_beds;
- chars.isDecorated = decorated;
- chars.isRepaired = repaired;
- return 0;
- }
- public int ShowChars()
- {
- Console.WriteLine("This bedroom have {0} beds", chars.beds);
- if (people > chars.beds)
- Console.WriteLine("It's not enough for {0} people. You need to buy {1} more beds", people, people - chars.beds);
- if (chars.isDecorated)
- Console.WriteLine("This bedroom is nicely decorated");
- else
- Console.WriteLine("This bedroom really need some decorations");
- if (chars.isRepaired)
- Console.WriteLine("This bedroom is in okay state");
- else
- Console.WriteLine("This bedroom is in poor shape");
- return 0;
- }
- public Bedroom(double new_height = 0, double new_width = 0, double new_length = 0, int new_people = 0,
- int bed = 0, bool deco = false, bool rep = false) : base(new_height, new_width, new_length, new_people)
- {
- chars.beds = bed;
- chars.isRepaired = rep;
- chars.isDecorated = deco;
- }
- }
- class Childroom : LivingRoom, IInformation
- {
- int childs;
- string[] toys = new string[5] { " ", " ", " ", " ", " " };
- int counter;
- enum toys_types
- {
- bear,
- tiger,
- cow,
- elephant,
- other_toy
- }
- public Childroom(double new_height = 0, double new_width = 0, double new_length = 0,
- int new_people = 0, int new_childs = 0) : base(new_height, new_width, new_length, new_people)
- {
- counter = 0;
- if (new_childs < people)
- {
- childs = new_childs;
- }
- else
- {
- childs = people;
- }
- }
- public int AddToy(int toy)
- {
- switch (toy)
- {
- case (int)toys_types.bear:
- toys[counter] = "bear";
- break;
- case (int)toys_types.tiger:
- toys[counter] = "tiger";
- break;
- case (int)toys_types.cow:
- toys[counter] = "cow";
- break;
- case (int)toys_types.elephant:
- toys[counter] = "elephant";
- break;
- case (int)toys_types.other_toy:
- toys[counter] = "other toy";
- break;
- }
- counter++;
- return 0;
- }
- public int ShowChildrens()
- {
- int i = 0;
- Console.WriteLine("Childs : {0}", childs);
- while (toys[i] != " ")
- {
- Console.WriteLine("{0}", toys[i]);
- i++;
- }
- if (counter < childs)
- {
- Console.WriteLine("Maybe you should consider buying more toys", toys[i]);
- }
- if (childs == people)
- {
- Console.WriteLine("Don't leave childs alone");
- }
- return 0;
- }
- }
- class Hall : LivingRoom, IInformation
- {
- int guests;
- public Hall(double new_height = 0, double new_width = 0, double new_length = 0,
- int new_people = 0, int new_guests = 0) : base(new_height, new_width, new_length, new_people)
- {
- if (guests < people)
- {
- guests = new_guests;
- }
- else
- {
- guests = people;
- }
- }
- }
- class Program
- {
- static int Main()
- {
- Room room = new Room(10,10,10);
- Room room1 = new Room(18, 10, 10);
- Hall hall = new Hall(20, 20, 20, 5, 4);
- Bedroom bed = new Bedroom(15, 10, 20, 5, 4, true);
- Bedroom bed1 = new Bedroom(15, 10, 20, 5, 4, true);
- Childroom child = new Childroom(15, 10, 20, 5, 4);
- child.AddToy(2);
- child.AddToy(4);
- child.ShowChildrens();
- child.ShowParameters();
- Console.WriteLine(room.Equals(room1));
- Console.WriteLine(bed.Equals(bed1));
- Console.ReadKey();
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement