zoukankan      html  css  js  c++  java
  • Net基础篇_学习笔记_第十一天_面向对象(练习)

     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();
            }
        }
    }
  • 相关阅读:
    16款值得一用的iPhone线框图模板 (PSD & Sketch)
    设计神器
    {CF812}
    hiho1080(多标记线段树)
    {容斥原理}
    {dp入门}
    {AC自动机}
    CF807
    Trie树
    杂记
  • 原文地址:https://www.cnblogs.com/NBOWeb/p/7542407.html
Copyright © 2011-2022 走看看