分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

Net基础篇_学习笔记_第十一天_面向对象(练习)

发布时间:2023-09-06 01:12责任编辑:郭大石关键词:面向对象
 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 Ticket10 ????{11 ????????private double _distance;12 ????????public double Distance13 ????????{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 Price26 ????????{27 ????????????get28 ????????????{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 ????????????????else42 ????????????????{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(); ???????} ???}}

Net基础篇_学习笔记_第十一天_面向对象(练习)

原文地址:http://www.cnblogs.com/NBOWeb/p/7542407.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved