C#2022/11/10

这段代码展示了面向对象编程的基本概念,如类的定义、属性和方法的使用。它涵盖了汽车、学生、银行账户(储蓄和信用卡)、角色扮演类游戏以及几何形状的抽象表示。此外,还实现了接口和抽象类的概念,以及运费计算和飞行能力的模拟。
摘要由CSDN通过智能技术生成

//Car car = new Car();                      //车名+行驶速度;
            //car.Name = "AudiRs7";
            //car.CurrentSpeed = 200;          
            //car.Name = "梅赛德斯奔驰";
            //car.CurrentSpeed = 120;

            //Student student1 = new Student();         //Student类比较体重;
            //student1.Name = "showmaker";
            //student1.Weight = 70;
            //Student student2 = new Student();
            //student2.Name = "scout";
            //student2.Weight = 50;
            //if (student1.Weight>student2.Weight)
            //{
            //    Console.WriteLine("{0}比{1}重",student1.Name,student2.Name);
            //}
            //else
            //{
            //    Console.WriteLine("{0}比{1}重", student2.Name, student1.Name );
            //}

            //savingBank saving = new savingBank();              //银行;
            //Console.WriteLine("银行账号:" + saving.Id);
            //Console.Write("输入新密码:");
            //saving.Password = Console.ReadLine();
            //Console.WriteLine("password:" + saving.Password+" ");
            //saving.IncreaseRate = 0.1;
            //Console.WriteLine("存款:" + saving.Balance);
            //Console.WriteLine("存款利息" + saving.IncreaseRate);           
            //CreditBank credit = new CreditBank();
            //Console.WriteLine("信用卡额度" + credit.CreditLimit);
            //Console.WriteLine("信用卡利息:" + credit.CreditRate);

            //Random random = new Random();                     //游戏角色
            //Magicer magicer = new Magicer();
            //magicer.Level = random.Next(1,11);
            //Console.WriteLine(magicer.attack());
            //Soldier soldier = new Soldier();
            //soldier.Atk = 100;
            //Console.WriteLine(soldier.Atk);

            //Rectangular rectangular = new Rectangular(9,6);           //抽象类动态多态性(方法覆写);
            //Square square = new Square(9);

            //Ticket ticket = new Ticket(int.Parse(Console.ReadLine()));              //运费
            //Console.WriteLine("{0}公里的运费是:{1}",ticket.Distance,ticket.Price);

            //FlyTiger flyTiger = new FlyTiger();           //接口
            //flyTiger.fly();

            //Student student = new Student();              //抽象类抽象属性只用创建空的访问器;派生类对访问器进行覆写并创建1相应属性;
            //Console.WriteLine(student.Age);

 //class Car
    //{
    //    private string name;
    //    private int currentSpeed;

    //    public string Name
    //    {
    //        get { return name; }
    //        set { name = value; }
    //    }
    //    public int CurrentSpeed
    //    {
    //        get { return currentSpeed; }
    //        set { currentSpeed = value; display(); }
    //    }
    //    void display()
    //    {
    //        Console.WriteLine("{0}当前的行驶速度是{1}Km/h", name, currentSpeed);
    //    }
    //}

//class Student
    //{
    //    private string name;
    //    private int weight;
    //    public string Name
    //    {
    //        set { name = value; }
    //        get { return name; }
    //    }
    //    public int Weight
    //    {
    //        set { weight = value; }
    //        get { return weight; }
    //    }

    //}

//class Bank
    //{
    //    private long id = 6217888888888888888;
    //    private double balance = 9999999999;
    //    private string password;
    //    public double Balance { get => balance; }
    //    public string Password
    //    {
    //        get { return "******"; }
    //        set
    //        {
    //            bool b = true;
    //            while (b)
    //            {
    //                if (value.Length != 6)
    //                {
    //                    Console.Write("不符合修改规则,重新输入:");
    //                    value = Console.ReadLine();
    //                }
    //                else
    //                {
    //                    password = value;
    //                    b = false;
    //                }
    //            }
    //        }
    //    }
    //    public long Id { get => id; }
    //}

 //class savingBank : Bank
    //{
    //    private long id = 6217111111111111111;
    //    private double increaseRate;
    //    public double IncreaseRate
    //    {
    //        get { return increaseRate; }
    //        set
    //        {
    //            if (value > 0 && value <= 0.1)
    //            {
    //                increaseRate = value;
    //            }
    //        }
    //    }
    //    public new long Id { get => id;}
    //}

//class CreditBank:Bank
    //{
    //    private long id = 6217333333333333333;
    //    private long creditLimit = 10000;
    //    private double creditRate = 0.25;

    //    public double CreditRate { get => creditRate; }
    //    public new long Id { get => id; }
    //    public long CreditLimit { get => creditLimit; }
    //}

 //class Magicer
    //{
    //    private int level;
    //    public int Level
    //    {
    //        get { return level; }
    //        set
    //        {
    //            if (1 <= value && value <= 10)
    //            {
    //                level = value;
    //            }
    //        }
    //    }
    //    public int attack()
    //    {
    //        return level * 5;
    //    }
    //}

//class Soldier
    //{
    //    private int atk;

    //    public int Atk { get => atk; set => atk = value; }

    //    public int attack()
    //    {
    //        return Atk;
    //    }
    //}

//abstract class Area
    //{
    //    public abstract void S();
    //}

 //class Rectangular : Area
    //{
    //    private int length;
    //    private int width;
    //    public Rectangular(int length, int width)
    //    {
    //        this.length = length;
    //        this.width = width;
    //        S();
    //    }
    //    public override void S()
    //    {
    //        Console.WriteLine("长:{0} 宽:{1}的长方形的面积:{2}",length,width,length*width);
    //    }
    //}

//class Square:Area
    //{
    //    private int length;
    //    public Square(int length)
    //    {
    //        this.length = length;
    //        S();
    //    }

    //    public override void S()
    //    {
    //        Console.WriteLine("边长:{0}的正方形的面积:{1}",length,length*length);
    //    }
    //}

//interface Ifly
    //{
    //    void fly();
    //}

//interface Itiger:Ifly
    //{
    //    void eat();
    //}

 //class FlyTiger : Itiger
    //{
    //    public void eat()
    //    {
    //        Console.WriteLine("实现接口Itiger.eat()方法,猛虎王吃蓝毒兽");
    //    }

    //    public void fly()
    //    {
    //        Console.WriteLine("实现接口Itiger:Ifly Ifly.fly()方法,猛虎王能飞");
    //    }
    //}

//class Ticket
    //{
    //    private int distance;
    //    private float price;

    //    public int Distance { get => distance; }
    //    public float Price { get => price;  }

    //    public Ticket(int distance)
    //    {
    //        this.distance = distance;
    //        if (distance<=100)
    //        {
    //            price = distance;
    //            Console.WriteLine("{0}公里的运费是:{1}",distance,price);
    //        }
    //        else if (101<=distance&&distance<=200)
    //        {
    //            price = distance * 9.5f;
    //        }
    //        else if (201<=distance&&distance<=300)
    //        {
    //            price = distance * 0.9f;
    //        }
    //        else
    //        {
    //            price = distance * 0.8f;
    //        }
    //    }   
    //}

//abstract class Person
    //{
    //    public abstract string Name { get; set; }
    //    public abstract int Age { set; get; }
    //}

//class Student : Person
    //{
    //    private string name;
    //    private int age;

    //    public override string Name { get { return name; } set { name = value; } }
    //    public override int Age { get { return age;} set { age = value; } }
    //}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值