您的位置:首页 > 其它

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

2013-05-28 22:21 567 查看
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();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐