中文响应式网站模板,莱西做网站公司,株洲网站建设优化,模板网站 可以做推广吗//写一个Ticket类#xff0c;有一个距离属性#xff08;本属性只读#xff0c;在构造方法中赋值#xff09;#xff0c;不能为负数//有一个价格属性#xff0c;价格属性为只读#xff0c;并且根据距离distance计算价格Price(1元/公里)//0--100公里 票价不打折//101-20… //写一个Ticket类有一个距离属性本属性只读在构造方法中赋值不能为负数//有一个价格属性价格属性为只读并且根据距离distance计算价格Price(1元/公里)//0--100公里 票价不打折//101-200公里 票价总额9.5折//201-300公里 票价总额9折//301公里以上 票价总额8折 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 面向对象构造函数
{ public class Ticket{ //写一个Ticket类有一个距离属性本属性只读在构造方法中赋值不能为负数//有一个价格属性价格属性为只读并且根据距离distance计算价格Price(1元/公里)//0--100公里 票价不打折//101-200公里 票价总额9.5折//201-300公里 票价总额9折//301公里以上 票价总额8折private double _distance;public double Distance{get { return _distance; }//只读属性意味着只有get 没有set}public Ticket(double distance){if (distance 0){distance 0;}this._distance distance;}private double _price;public double Price{get{if (_distance 0 _distance 100){return _distance * 1.0;}else if (_distance 101 _distance 200){return _distance * 0.95;}else if (_distance 201 _distance 300){return _distance * 0.9;}else{return _distance * 0.8;}}}public void ShowTicket(){Console.WriteLine({0}公里需要{1}元,this.Distance,Price);}}
} using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 面向对象构造函数
{class Program{static void Main(string[] args){Ticket t new Ticket(400);t.ShowTicket();Console.ReadLine();}}
} 转载于:https://www.cnblogs.com/kangshuai/p/4679319.html