C#编写双色球选号程序-双色球类的创建

1.双色球属性设定

双色球类,设定号码,投注方式和双色球价格,依据该三个需求,创建三个属性;使用list类保存双色球号码,双色球号码为string。

//实体类:双色球号码,球有多个,则需要用List保存双色球的号码,双色球号码是string
public List RedBalls { get; set; }       //设置List类,保存双色球号码
public List BlueBalls { get; set; }      //设置List类,保存双色球号码

//双色球投注方式
public string BallType { get; set; }             //投注方式设定
//双色球金额
public double Price { get; set; } = 2;           //单价设定为2元

2.双色球方法设定

首先进行价格计算。

public DoubleChromosphere(List redBalls, List blueBalls)
{ 
 
    this.RedBalls = redBalls;
    this.BlueBalls = blueBalls;
    BallType = blueBalls.Count > 1 || redBalls.Count > 6 ? "复式" : "单式";
    //价格计算,计算价格
    if (BallType.Equals("复式"))
    {
        Price = Factor(redBalls.Count) / (Factor(redBalls.Count - 6) * Factor(6)) * Factor(blueBalls.Count);
    }
    else
    { 
        Price*=blueBalls.Count;          
    }
}
//计算价格阶层
private int Factor(int n)
{
    if (n < 1) return 0;
    if (n == 1) return 1;
    return n*Factor(n-1);
}

其次进行数据显示

 public string BallShow 
 {
     get {
         string nums = string.Join(" ", RedBalls) + "|";
         if (BlueBalls.Count > 0)
         {
           return  nums += " " + string.Join(" ", BlueBalls);
         }
         else
         { 
             return nums+" "+BlueBalls[0];
         }
     }
     set;      
 
 }
 public string PriceShow => Price + "元";

以上,完成双色球类的创建,包含,选择球的号码。球的价格.

你可能感兴趣的:(C#学习,c#,开发语言)