Guest User

Untitled

a guest
Oct 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. class Immobilie
  2. {
  3. protected string ort;
  4. protected double gesamtgröße, preis;
  5. public Immobilie(string ort, double gesamtgröße, double preis)
  6. {
  7. this.ort = ort;
  8. this.gesamtgröße = gesamtgröße;
  9. this.preis = preis;
  10. }
  11. public Immobilie() : this(null, 0, 0) { }
  12. public override string ToString()
  13. {
  14. string str = "Ort: "+ ort + "\nGesamtgröße: " + gesamtgröße + "\nPreis: " + preis;
  15. return str;
  16. }
  17. class Mehrfamilienhaus : Immobilie
  18. {
  19. double [] wohnflächen = new double [5];
  20. public Mehrfamilienhaus(string ort, double gesamtgröße, double preis, double[] wohnflächen)
  21. {
  22. this.ort = ort;
  23. this.gesamtgröße = gesamtgröße;
  24. this.preis = preis;
  25. this.wohnflächen = wohnflächen;
  26. }
  27. public override string ToString()
  28. {
  29. return base.ToString()+ "\nWohnflachen" + wohnflächen;
  30. }
  31. }
  32.  
  33. class Eigentumswohnung : Immobilie
  34. {
  35. int baujahr;
  36. public Eigentumswohnung(string ort, double gesamtgröße, double preis, int baujahr)
  37. : base (ort, gesamtgröße, preis)
  38. {
  39. this.baujahr = baujahr;
  40. }
  41. public double Preisproqm()
  42. {
  43. return preis / gesamtgröße;
  44. }
  45. public override string ToString()
  46. {
  47. return base.ToString()+"\nbaujahr: " + baujahr;
  48. }
  49. }
  50.  
  51. }
  52.  
  53. class Program
  54. {
  55. static void Main(string[] args)
  56. {
  57. Immobilie a = new Immobilie("Erlangen", 300, 15000);
  58. Immobilie b = new Eigentumswohung("Erlangen", 300, 15000, 2002);
  59.  
  60. }
  61. }
Add Comment
Please, Sign In to add comment