using System;
public class Phone{}
public class CellPhone:Phone
{
public CellPhone(string color,double price)
{
this._color=color;
this._price=price;
}
public CellPhone(string color,double price,string maxBatterLife):this(color,price)
{
this.maxBatterLife=maxBatterLife;
}
private string _color;
private double _price;
public string maxBatterLife;
public string Color
{
get{return this._color;}
set{this._color=value;}
}
public double Price
{
get{return this._price;}
set{this._price=value;}
}
}
public class Test
{
public static void Main()
{
while(true)
{
Console.WriteLine("------------------------");
Console.Write("请输入手机颜色:");
string color = Console.ReadLine();
Console.Write("请输入手机价格:");
double price = double.Parse(Console.ReadLine());
Console.Write("请输入手机最长使用周期(可选,敲回车跳过):");
string maxBatterLife = Console.ReadLine();
CellPhone phone ;
if(maxBatterLife=="")
{
phone = new CellPhone(color,price);
Console.WriteLine("This phone’s color is {0},price is {1} ",phone.Color,phone.Price);
}
else
{
phone = new CellPhone(color,price,maxBatterLife);
Console.WriteLine("This phone’s color is {0},price is {1},maxBatterLife is {2} ",phone.Color,phone.Price,phone.maxBatterLife);
}
}
}
}