Abstract type: Difference between revisions
Content deleted Content added
No edit summary |
|||
Line 2,009: | Line 2,009: | ||
(foo) |
(foo) |
||
(bar) )</lang> |
(bar) )</lang> |
||
=={{header|PowerShell}}== |
|||
<lang PowerShell> |
|||
#Requires -Version 5.0 |
|||
Class Player |
|||
{ |
|||
<# |
|||
Properties: Name, Team, Position and Number |
|||
#> |
|||
[string]$Name |
|||
[ValidateSet("Baltimore Ravens","Cincinnati Bengals","Cleveland Browns","Pittsburgh Steelers", |
|||
"Chicago Bears","Detroit Lions","Green Bay Packers","Minnesota Vikings", |
|||
"Houston Texans","Indianapolis Colts","Jacksonville Jaguars","Tennessee Titans", |
|||
"Atlanta Falcons","Carolina Panthers","New Orleans Saints","Tampa Bay Buccaneers", |
|||
"Buffalo Bills","Miami Dolphins","New England Patriots","New York Jets", |
|||
"Dallas Cowboys","New York Giants","Philadelphia Eagles","Washington Redskins", |
|||
"Denver Broncos","Kansas City Chiefs","Oakland Raiders","San Diego Chargers", |
|||
"Arizona Cardinals","Los Angeles Rams","San Francisco 49ers","Seattle Seahawks")] |
|||
[string]$Team |
|||
[ValidateSet("C","G","T","QB","RB","WR","TE","DT","DE","ILB","OLB","CB","S","K","H","LS","P","KOS","R")] |
|||
[string]$Position |
|||
[ValidateRange(0,99)] |
|||
[int]$Number |
|||
<# |
|||
Constructor: Creates a new Player object, with the specified Name, Team, Position and Number. |
|||
#> |
|||
Player([string]$Name, [string]$Team, [string]$Position, [int]$Number) |
|||
{ |
|||
$this.Name = (Get-Culture).TextInfo.ToTitleCase("$Name") |
|||
$this.Team = (Get-Culture).TextInfo.ToTitleCase("$Team") |
|||
$this.Position = $Position.ToUpper() |
|||
$this.Number = $Number |
|||
} |
|||
<# |
|||
Method: Trade the player to a different team and list his jersey number in case it changes. |
|||
(Optional parameters for methods in PowerShell 5 classes are not available. Boo!!) |
|||
#> |
|||
[void] Trade([string]$NewTeam, [int]$NewNumber) |
|||
{ |
|||
$teams = "Baltimore Ravens","Cincinnati Bengals","Cleveland Browns","Pittsburgh Steelers", |
|||
"Chicago Bears","Detroit Lions","Green Bay Packers","Minnesota Vikings", |
|||
"Houston Texans","Indianapolis Colts","Jacksonville Jaguars","Tennessee Titans", |
|||
"Atlanta Falcons","Carolina Panthers","New Orleans Saints","Tampa Bay Buccaneers", |
|||
"Buffalo Bills","Miami Dolphins","New England Patriots","New York Jets", |
|||
"Dallas Cowboys","New York Giants","Philadelphia Eagles","Washington Redskins", |
|||
"Denver Broncos","Kansas City Chiefs","Oakland Raiders","San Diego Chargers", |
|||
"Arizona Cardinals","Los Angeles Rams","San Francisco 49ers","Seattle Seahawks" | |
|||
Where-Object {$_ -notmatch $this.Team} |
|||
if ($NewTeam -in $teams) |
|||
{ |
|||
$this.Team = (Get-Culture).TextInfo.ToTitleCase("$NewTeam") |
|||
} |
|||
else |
|||
{ |
|||
throw "Invalid Team" |
|||
} |
|||
if ($NewNumber -in 0..99) |
|||
{ |
|||
$this.Number = $NewNumber |
|||
} |
|||
else |
|||
{ |
|||
throw "Invalid Number" |
|||
} |
|||
} |
|||
} |
|||
</lang> |
|||
Create a new player: |
|||
<lang PowerShell> |
|||
$player = [Player]::new("sam bradford", "philadelphia eagles", "qb", 7) |
|||
$player |
|||
</lang> |
|||
{{Out}} |
|||
<pre> |
|||
Name Team Position Number |
|||
---- ---- -------- ------ |
|||
Sam Bradford Philadelphia Eagles QB 7 |
|||
</pre> |
|||
Trade the player: |
|||
<lang PowerShell> |
|||
$player.Trade("minnesota vikings", 8) |
|||
$player |
|||
</lang> |
|||
{{Out}} |
|||
<pre> |
|||
Name Team Position Number |
|||
---- ---- -------- ------ |
|||
Sam Bradford Minnesota Vikings QB 8 |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |