1. using System;
    2. using System.Collections.Generic;
    3. using System.Text;
    4. namespace _052_面对对象初级_小练习
    5. {
    6. public class Ticket
    7. {
    8. private double _distance;
    9. public double Distance
    10. {
    11. get { return _distance; }
    12. }
    13. public Ticket(double distance)
    14. {
    15. if (distance < 0)
    16. {
    17. distance = 0;
    18. }
    19. this._distance = distance;
    20. }
    21. private double _price;
    22. public double Price
    23. {
    24. get
    25. {
    26. if (Distance > 0 && Distance < 100)
    27. {
    28. return Distance * 1.0;
    29. }
    30. else if (Distance >= 100 && Distance < 200)
    31. {
    32. return Distance * 0.95;
    33. }
    34. else if (Distance >= 200 && Distance < 300)
    35. {
    36. return Distance * 0.9;
    37. }
    38. else
    39. {
    40. return Distance * 0.8;
    41. }
    42. //return _price;
    43. }
    44. }
    45. public void ShowTicket()
    46. {
    47. Console.WriteLine("{0}公里,需要{1}元", Distance, Price);
    48. }
    49. }
    50. }