Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.67 KB | None | 0 0
  1. using System;
  2.  
  3. interface IInformation
  4. {
  5. int ShowParameters();
  6. double area{
  7. get;
  8. }
  9. bool Check();
  10. }
  11.  
  12. class Room : IEquatable<Room>,IInformation
  13. {
  14. static protected int number_of_rooms = 0;
  15. protected double height;
  16. protected double width;
  17. protected double length;
  18.  
  19. public bool Equals(Room temp)
  20. {
  21. if (temp.height == this.height
  22. && temp.width == this.width
  23. && temp.length == this.length)
  24. return true;
  25. else
  26. return false;
  27. }
  28.  
  29. public double this[string index]
  30. {
  31. get
  32. {
  33. switch (index)
  34. {
  35. case "height":
  36. return height;
  37. case "width":
  38. return width;
  39. case "length":
  40. return length;
  41. case "area":
  42. return area;
  43. default:
  44. return 0;
  45. }
  46. }
  47. set
  48. {
  49. switch (index)
  50. {
  51. case "height":
  52. height = value;
  53. break;
  54. case "width":
  55. width = value;
  56. break;
  57. case "length":
  58. length = value;
  59. break;
  60. default:
  61. return;
  62.  
  63. }
  64.  
  65. }
  66. }
  67.  
  68. public double area
  69. {
  70. get
  71. {
  72. return height * width * length;
  73. }
  74. }
  75.  
  76. public virtual bool Check()
  77. {
  78. if (height > 0 && width > 0 && length > 0) return true;
  79. else return false;
  80. }
  81.  
  82. private bool Check(double a, double b, double c)
  83. {
  84. if (a > 0 && b > 0 && c > 0) return true;
  85. else return false;
  86. }
  87.  
  88. static public void ShowNumber()
  89. {
  90. Console.WriteLine("Number of rooms: {0}", number_of_rooms);
  91. }
  92.  
  93. public Room()
  94. {
  95. number_of_rooms += 1;
  96. }
  97.  
  98. public Room(double new_height, double new_width, double new_length)
  99. {
  100. height = new_height;
  101. width = new_width;
  102. length = new_length;
  103. number_of_rooms += 1;
  104. }
  105.  
  106. public virtual int ShowParameters()
  107. {
  108. if (Check())
  109. {
  110. Console.WriteLine("Height: {0}\nWidth: {1}\nLength: {2}", height, width, length);
  111. }
  112. else
  113. {
  114. Console.WriteLine("Incorrect parameters");
  115. }
  116. return 0;
  117. }
  118.  
  119. public int ShowArea()
  120. {
  121. if (Check())
  122. {
  123. Console.WriteLine("Area : {0}", area);
  124. }
  125. else
  126. {
  127. Console.WriteLine("Incorrect parameters");
  128. }
  129. return 0;
  130. }
  131.  
  132. public int ChangeParameters(double new_height, double new_width, double new_length)
  133. {
  134. if (Check(new_height, new_width, new_length))
  135. {
  136. height = new_height;
  137. width = new_width;
  138. length = new_length;
  139. return 0;
  140. }
  141. else
  142. {
  143. Console.WriteLine("Incorrect parameters");
  144. return 0;
  145. }
  146.  
  147. }
  148.  
  149. }
  150.  
  151. abstract class LivingRoom : Room, IEquatable<LivingRoom>, IInformation
  152. {
  153. protected int people;
  154. public override bool Check()
  155. {
  156. if (height > 0 && width > 0 && length > 0 && people >= 0) return true;
  157. else return false;
  158. }
  159.  
  160. protected bool Check(double a, double b, double c, int z)
  161. {
  162. if (a > 0 && b > 0 && c > 0 && z >= 0) return true;
  163. else return false;
  164. }
  165.  
  166. public bool Equals(LivingRoom temp)
  167. {
  168. if (base.Equals(temp)
  169. && temp.people == this.people
  170. )
  171. return true;
  172. else
  173. return false;
  174. }
  175.  
  176. public int ChangeParameters(double new_height, double new_width, double new_length, int new_people = 0)
  177. {
  178. if (Check(new_height, new_width, new_length, people))
  179. {
  180. height = new_height;
  181. width = new_width;
  182. length = new_length;
  183. people = new_people;
  184. return 0;
  185. }
  186. else
  187. {
  188. Console.WriteLine("Incorrect parameters");
  189. return 0;
  190. }
  191. }
  192.  
  193. public override int ShowParameters()
  194. {
  195. if (Check())
  196. {
  197. Console.WriteLine("Height: {0}\nWidth: {1}\nLength: {2}\nPeople: {3}", height, width, length, people);
  198. }
  199. else
  200. {
  201. Console.WriteLine("Incorrect parameters");
  202. }
  203. return 0;
  204. }
  205.  
  206. public LivingRoom(double new_height, double new_width, double new_length, int new_people) : base(new_height,new_width,new_length)
  207. {
  208. height = new_height;
  209. width = new_width;
  210. length = new_length;
  211. people = new_people;
  212. number_of_rooms += 1;
  213. }
  214. }
  215.  
  216. class Bedroom : LivingRoom, IEquatable<Bedroom>, IInformation
  217. {
  218. public struct bedChars
  219. {
  220. public int beds;
  221. public bool isDecorated;
  222. public bool isRepaired;
  223.  
  224. public bedChars(int new_beds, bool decorated, bool repaired)
  225. {
  226. beds = new_beds;
  227. isDecorated = decorated;
  228. isRepaired = repaired;
  229. }
  230.  
  231. }
  232.  
  233. public bedChars chars;
  234.  
  235. public bool Equals(Bedroom temp)
  236. {
  237. if (base.Equals(temp)
  238. && this.chars.beds == temp.chars.beds
  239. && this.chars.isDecorated == temp.chars.isDecorated
  240. && this.chars.isRepaired == temp.chars.isRepaired
  241. )
  242. return true;
  243. else
  244. return false;
  245. }
  246.  
  247. public int ChangeChars(int new_beds, bool decorated, bool repaired)
  248. {
  249. chars.beds = new_beds;
  250. chars.isDecorated = decorated;
  251. chars.isRepaired = repaired;
  252. return 0;
  253. }
  254.  
  255. public int ShowChars()
  256. {
  257. Console.WriteLine("This bedroom have {0} beds", chars.beds);
  258. if (people > chars.beds)
  259. Console.WriteLine("It's not enough for {0} people. You need to buy {1} more beds", people, people - chars.beds);
  260. if (chars.isDecorated)
  261. Console.WriteLine("This bedroom is nicely decorated");
  262. else
  263. Console.WriteLine("This bedroom really need some decorations");
  264. if (chars.isRepaired)
  265. Console.WriteLine("This bedroom is in okay state");
  266. else
  267. Console.WriteLine("This bedroom is in poor shape");
  268. return 0;
  269. }
  270.  
  271. public Bedroom(double new_height = 0, double new_width = 0, double new_length = 0, int new_people = 0,
  272. int bed = 0, bool deco = false, bool rep = false) : base(new_height, new_width, new_length, new_people)
  273. {
  274. chars.beds = bed;
  275. chars.isRepaired = rep;
  276. chars.isDecorated = deco;
  277. }
  278.  
  279. }
  280.  
  281. class Childroom : LivingRoom, IInformation
  282. {
  283. int childs;
  284. string[] toys = new string[5] { " ", " ", " ", " ", " " };
  285. int counter;
  286. enum toys_types
  287. {
  288. bear,
  289. tiger,
  290. cow,
  291. elephant,
  292. other_toy
  293. }
  294.  
  295. public Childroom(double new_height = 0, double new_width = 0, double new_length = 0,
  296. int new_people = 0, int new_childs = 0) : base(new_height, new_width, new_length, new_people)
  297. {
  298. counter = 0;
  299. if (new_childs < people)
  300. {
  301. childs = new_childs;
  302. }
  303. else
  304. {
  305. childs = people;
  306. }
  307. }
  308.  
  309.  
  310.  
  311. public int AddToy(int toy)
  312. {
  313. switch (toy)
  314. {
  315. case (int)toys_types.bear:
  316. toys[counter] = "bear";
  317. break;
  318. case (int)toys_types.tiger:
  319. toys[counter] = "tiger";
  320. break;
  321. case (int)toys_types.cow:
  322. toys[counter] = "cow";
  323. break;
  324. case (int)toys_types.elephant:
  325. toys[counter] = "elephant";
  326. break;
  327. case (int)toys_types.other_toy:
  328. toys[counter] = "other toy";
  329. break;
  330. }
  331. counter++;
  332. return 0;
  333. }
  334. public int ShowChildrens()
  335. {
  336. int i = 0;
  337. Console.WriteLine("Childs : {0}", childs);
  338. while (toys[i] != " ")
  339. {
  340. Console.WriteLine("{0}", toys[i]);
  341. i++;
  342. }
  343. if (counter < childs)
  344. {
  345. Console.WriteLine("Maybe you should consider buying more toys", toys[i]);
  346. }
  347. if (childs == people)
  348. {
  349. Console.WriteLine("Don't leave childs alone");
  350. }
  351. return 0;
  352. }
  353.  
  354. }
  355.  
  356. class Hall : LivingRoom, IInformation
  357. {
  358. int guests;
  359. public Hall(double new_height = 0, double new_width = 0, double new_length = 0,
  360. int new_people = 0, int new_guests = 0) : base(new_height, new_width, new_length, new_people)
  361. {
  362. if (guests < people)
  363. {
  364. guests = new_guests;
  365. }
  366. else
  367. {
  368. guests = people;
  369. }
  370. }
  371.  
  372. }
  373.  
  374.  
  375. class Program
  376. {
  377. static int Main()
  378. {
  379. Room room = new Room(10,10,10);
  380. Room room1 = new Room(18, 10, 10);
  381. Hall hall = new Hall(20, 20, 20, 5, 4);
  382. Bedroom bed = new Bedroom(15, 10, 20, 5, 4, true);
  383. Bedroom bed1 = new Bedroom(15, 10, 20, 5, 4, true);
  384. Childroom child = new Childroom(15, 10, 20, 5, 4);
  385. child.AddToy(2);
  386. child.AddToy(4);
  387. child.ShowChildrens();
  388. child.ShowParameters();
  389. Console.WriteLine(room.Equals(room1));
  390. Console.WriteLine(bed.Equals(bed1));
  391. Console.ReadKey();
  392. return 0;
  393.  
  394. }
  395. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement