1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace juhnko 8 { 9 class Ticket 10 { 11 private double _distance; 12 public double Distance 13 { 14 get { return _distance; } 15 } 16 public Ticket(double distance) 17 { 18 if (distance<0) 19 { 20 distance = 0; 21 } 22 this._distance=distance; 23 } 24 private double _price; 25 public double Price 26 { 27 get 28 { 29 if (_distance > 0 && _distance <= 100) 30 { 31 return _distance * 1.0*1.00; 32 } 33 else if (_distance > 100 && _distance <= 200) 34 { 35 return _distance * 0.95 * 1.00; 36 } 37 else if (_distance > 200 && _distance <= 300) 38 { 39 return _distance * 0.9 * 1.00; 40 } 41 else 42 { 43 return _distance * 0.8 * 1.00; 44 } 45 } 46 } 47 public void ShowTicket() 48 { 49 Console.WriteLine("{0}公里需要{1}元",this.Distance,this.Price); 50 } 51 } 52 }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace juhnko { class Program { static void Main(string[] args) { Ticket myTicket = new Ticket(260); myTicket.ShowTicket(); Console.ReadKey(); } } }
时间: 2024-10-04 02:49:45