编辑代码

//20190401031杨小可
//练习5
struct BasketballPlayer {
    var name: String
    var threePointShot: Int
    var twoPointShot: Int
    var score: Int {
        get {
            return 2*twoPointShot+3*threePointShot
        }
    }
    mutating func  shot(point: Int)  {
        if point == 3 {
            threePointShot += 1
        } else if point == 2 {
            twoPointShot += 1
        }
    }
    func description() {
        print("Player \(name) has \(threePointShot) three point shot and \(twoPointShot) two point shot, the total socre is \(score)")
    }
}

var player = BasketballPlayer(name: "YaoMing", threePointShot: 0, twoPointShot: 0)
player.name = "YaoMing"
player.description()
player.shot(point: 2)
player.shot(point: 2)
player.shot(point: 3)
player.shot(point: 2)
player.shot(point: 2)
player.description()