Loner_li 面向对象 实例练习--要求:用户输入上述四个字段的值,实例化一个Computer类,然后调用类中方法输出电脑详细信息

1.Computer类:
品牌名称:Brand
系列:Model
价格:price
颜色:color

方法:输出电脑的相信信息(就是这4个属性的值)

要求:用户输入上述四个字段的值,实例化一个Computer类,然后调用类中方法输出电脑详细信息

 

Computer类

 

   public class computer
    {
        //private string ComputerName;

        //public string Name
        //{
        //    get { return ComputerName; }
        //    set { ComputerName = value; }
        //}
       public computer() { }
       public computer(string model,string brand,double price,string color)
       { this.ComModel = model;
           this.ComBrand = brand;
         
           this.ComPrice = price;
           this.ComColor = color;
       }
        private string Model;

        public string ComModel
        {
            get { return Model; }
            set { Model = value; }
        }
        private string Brand;

        public string ComBrand
        {
            get { return Brand; }
            set { Brand = value; }
        }
        private double Price;

        public double ComPrice
        {
            get { return Price; }
            set { Price = value; }
        }
        private string Color;

        public string ComColor
        {
            get { return Color; }
            set { Color = value; }
        }

        public string writeComputer()
        {
            return string.Format("品牌为:{0},系列为:{1},价格为:{2},颜色为:{3}",ComModel,ComBrand,ComPrice,ComColor);
        }
    }

Program.cs  主程序

    class Program
    {
        static void Main(string[] args)
        {
            computer com = new computer();
          
          
            Console.WriteLine("请输入品牌名称:");
            string ppmc = Console.ReadLine();
            com.ComModel = ppmc;
            Console.WriteLine("请输入系列名称:");
            string brand = Console.ReadLine();

            com.ComBrand = brand;
            Console.WriteLine("请输入价格:");

            double price = Convert.ToDouble(Console.ReadLine());
            com.ComPrice = price;
            Console.WriteLine("请输入颜色:");

            string color = Console.ReadLine();
            com.ComColor = color;

           string info= com.writeComputer();

           Console.WriteLine(info);

           Console.ReadKey();
        }
       
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值