Advertisement
Levi0227

2. félév 3. hét

Feb 27th, 2024
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.20 KB | Source Code | 0 0
  1. namespace ConsoleApp1
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             //Tarolo[] tarolok = { new Tarolo("Lekvár", 80, Tarolo.Besorolas.KurvaNehez), new Tarolo("Uborka", 40, Tarolo.Besorolas.EbbeMegLehetPakolni), new Tarolo("Kolbász", 150, Tarolo.Besorolas.KurvaNehez) };
  8.  
  9.             //foreach (Tarolo item in tarolok)
  10.             //{
  11.             //    Console.WriteLine(item.Cimke);
  12.             //}
  13.  
  14.             //Array.Sort(tarolok);
  15.  
  16.             //foreach (Tarolo item in tarolok)
  17.             //{
  18.             //    Console.WriteLine(item.Cimke);
  19.             //}
  20.  
  21.             Lodgings lodgings = new Lodgings(3, 25000, 3, 5, 30000);
  22.  
  23.             Console.WriteLine(lodgings.Book(3));
  24.             Console.WriteLine(lodgings.IsBooked());
  25.             Console.WriteLine(lodgings.MoveIn(1));
  26.         }
  27.     }
  28. }
  29.  
  30. ----------------------------------------------------------------------
  31. using System;
  32. using System.Collections.Generic;
  33. using System.Linq;
  34. using System.Text;
  35. using System.Threading.Tasks;
  36.  
  37. namespace ConsoleApp1
  38. {
  39.     internal interface IRealEstate
  40.     {
  41.         int TotalValue();
  42.     }
  43. }
  44.  
  45. ----------------------------------------------------------------------
  46.  
  47. using System;
  48. using System.Collections.Generic;
  49. using System.Linq;
  50. using System.Text;
  51. using System.Threading.Tasks;
  52.  
  53. namespace ConsoleApp1
  54. {
  55.     internal interface IRent
  56.     {
  57.         int GetCost(int months);
  58.         bool IsBooked();
  59.         bool Book(int months);
  60.     }
  61. }
  62.  
  63.  
  64. ----------------------------------------------------------------------
  65.  
  66. using System;
  67. using System.Collections.Generic;
  68. using System.Linq;
  69. using System.Text;
  70. using System.Threading.Tasks;
  71.  
  72. namespace ConsoleApp1
  73. {
  74.     internal abstract class Flat : IRealEstate
  75.     {
  76.         protected double area;
  77.         protected int roomsCount;
  78.         protected int inhabitantsCount;
  79.         protected int unitPrice;
  80.  
  81.         double Area { get; set; }
  82.         int RoomsCount { get; set; }
  83.         int InhabitantsCount { get; set; }
  84.         int UnitPrice { get; set; }
  85.  
  86.         protected Flat(double area, int roomsCount, int inhabitantsCount, int unitPrice)
  87.         {
  88.             this.area = area;
  89.             this.roomsCount = roomsCount;
  90.             this.inhabitantsCount = inhabitantsCount;
  91.             this.unitPrice = unitPrice;
  92.         }
  93.  
  94.         public abstract bool MoveIn(int newInhabitants);
  95.  
  96.         public int GetInhabitamtsCount()
  97.         {
  98.             return this.inhabitantsCount;
  99.         }
  100.  
  101.         public int TotalValue()
  102.         {
  103.             return (int)(this.UnitPrice * this.area);
  104.         }
  105.  
  106.         public override string ToString()
  107.         {
  108.             return $"{this.roomsCount} {this.inhabitantsCount} {this.area} {this.unitPrice}";
  109.         }
  110.     }
  111. }
  112.  
  113.  
  114. ----------------------------------------------------------------------
  115.  
  116. using System;
  117. using System.Collections.Generic;
  118. using System.Linq;
  119. using System.Text;
  120. using System.Threading.Tasks;
  121.  
  122. namespace ConsoleApp1
  123. {
  124.     internal class Lodgings : Flat, IRent
  125.     {
  126.         protected int bookedMonths;
  127.  
  128.         public Lodgings(int bookedMonths, double area, int roomsCount, int inhabitantsCount, int unitPrice) : base(area, roomsCount, inhabitantsCount, unitPrice)
  129.         {
  130.             this.bookedMonths = 0;
  131.             this.inhabitantsCount = 0;
  132.         }
  133.  
  134.         public bool Book(int months)
  135.         {
  136.             return IsBooked();
  137.         }
  138.  
  139.         public int GetCost(int months)
  140.         {
  141.             return (TotalValue() / 240) / inhabitantsCount;
  142.         }
  143.  
  144.         public bool IsBooked()
  145.         {
  146.             if (bookedMonths == 0) return false;
  147.            
  148.             return true;
  149.         }
  150.  
  151.         public override bool MoveIn(int newInhabitants)
  152.         {
  153.             if (IsBooked() == true && (inhabitantsCount + newInhabitants) < 9 && ((inhabitantsCount + newInhabitants) / area) > 2)
  154.             {
  155.                 inhabitantsCount += newInhabitants;
  156.                 return true;
  157.             }
  158.  
  159.             return false;
  160.         }
  161.  
  162.         public override string ToString()
  163.         {
  164.             return $"{base.ToString()} + {bookedMonths}";
  165.         }
  166.     }
  167. }
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement