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();
}
}
品牌名称: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();
}
}
相关文章推荐
- 简单编程(三)编写一个程序,要求用户输入两个整数,然后计算并输出他们的和、差、积、商。
- 4.构造方法与重载:定义一个网络用户类,要处理的信息有用户 ID、用户密码、 email 地址。在建立类的实例时把以上三个信息都作为构造函数的参数输入, 其中用户 ID 和用户密码时必须缺省时 ema
- 3.2 设计一个程序,要求用户输入 5 个字符,然后将这 5 个字符按相反的顺序显示出 来。例如,假设输入 abcde,则输出为 edcba
- 8.不断 要求用户输入一个数字,然后打印这个数字的二倍,当用户输入q的时候程序退出(return)
- 冰编程对派出类的功能进行验证。。 轿车类等 派生出自行车类 停车等方法。然后从该类为基类 最大速度。重量等字段以及开车 要求具有速度 定义一个车辆类
- 习题2:编写一个控制台应用程序,要求用户输入5个大写字母,如果用户输入的信息不满足要求,提示帮助信息并要求重新输入。
- 使用jQuery匹配文档中所有的li元素,返回一个jQuery对象,然后通过数组下标的方式读取jQuery集合中第1个DOM元素,此时返回的是DOM对象,然后调用DOM属性innerHTML,读取该元素 包含的文本信息
- 编写一个程序,要求用户输入下限整数和一个上限整数,然后,依次计算从下限到上限的每一个整数的平方的加和,最后显示结果
- 黑马程序员之C#编程基础学习笔记:不断要求用户输入一个数字,然后打印这个数字的二倍,当用户输入q的时候程序退出。
- 编写一个程序,其main()调用一个用户定义的函数(以光年值为参数,并返回对应天文单位 的值).该程序按下面的格式要求用户输入光年值
- 编写一个程序,要求用户输入最多10个高尔夫成绩,并将其存储在一个数组中。 程序允许用户提早结束输入,并在一行上显示所有成绩,然后报告平均成绩。 请使用3个数组处理函数来分别进行输入、显示和计算
- 用户输入年龄,然后输出,要求用类操作
- loner_li 机试题 由用户输入一个字符串,使用foreach循环遍历出此字符串中有多个字母,多少个数字,多少个标点
- C语言初级练习——编写一个乘法表,呈倒三角形、输入一串字符,要求输出这串字符中的数字最多的那段的位置以及这段数字的个数
- C#--第2周实验--任务2(1)--用户输入一个字符,并用Console类的Readkey()方法读取该字符,并在控制台上输出该字符
- loner_li 机试题 一个文本文件含有如下内容,分别表示姓名和成绩:张三 90 ..提供用户一个控制台界面,允许用户输入要查询的姓名,输入姓名并且按回车以后,打印出此人的成绩...
- 编写一函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数,在主函数中输入字符串以及输出上述结果。 只要结果,别输出什么提示信息。
- 字符串数组 输入3个字符串,要求按由小到大的字母顺序输出; 输入n个学生的姓名和学号到字符串数组中,在输入一个姓名,如果班级有该生则返回其信息,否则返回本班无此人
- 'VB编程 编写一个竞赛评分的函数过程。评委打分为参数(数组参数),选手得分为函数值。记分规则为:去掉一个最高分,去掉一个最低分,然后求平均。调用该函数,由键盘输入5个评委的打分(存放在数组中),输出
- C#--第2周实验--任务2(1)--用户输入一个字符,并用Console类的Readkey()方法读取该字符,并在控制台上输出该字符(改进版)