Advertisement
BloodMoonYTC

hotel

Oct 20th, 2021
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 KB | None | 0 0
  1. using System;
  2.  
  3. namespace hotel
  4. {
  5.     class Hotel
  6.     {
  7.         private float length = 1;
  8.         private float width = 1;
  9.  
  10.         public Hotel(float length, float width)
  11.         {
  12.             Length = length;
  13.             Width = width;
  14.         }
  15.  
  16.         public float Length
  17.         {
  18.             get { return this.length; }
  19.             set
  20.             {
  21.                 if (value <= 0.0f)
  22.                     this.length = 1.0f;
  23.                 else
  24.                     this.length = value;
  25.             }
  26.         }
  27.         public float Width
  28.         {
  29.             get { return this.width; }
  30.             set
  31.             {
  32.                 if (value <= 0.0f)
  33.                     this.width = 1.0f;
  34.                 else
  35.                     this.width = value;
  36.             }
  37.         }
  38.  
  39.         public float Perimeter
  40.         {
  41.             get
  42.             {
  43.                 return (Length + Width) * 2;
  44.             }
  45.         }
  46.  
  47.         public float Area
  48.         {
  49.             get
  50.             {
  51.                 return (Length * Width);
  52.             }
  53.         }
  54.  
  55.         public override string ToString()
  56.         {
  57.             return string.Format("A szoba területe: " + Area);
  58.         }
  59.  
  60.     }
  61.     class Program
  62.     {
  63.         static void Main(string[] args)
  64.         {
  65.             while (true)
  66.             {
  67.                 float length, width;
  68.                 Console.WriteLine("Írd be a szoba szélességét: ");
  69.                 width = float.Parse(Console.ReadLine());
  70.                 Console.WriteLine("Írd be a szoba hosszát: ");
  71.                 length = float.Parse(Console.ReadLine());
  72.  
  73.                 if (length < 0.0f || width < 0.0f)
  74.                     break;
  75.  
  76.                 Hotel sz1 = new Hotel(length, width);
  77.  
  78.                 Console.WriteLine(sz1);
  79.                 Console.WriteLine("Nyomj entert az új szoba kiszámolásához!");
  80.                 Console.ReadKey();
  81.             }
  82.         }
  83.     }
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement