Hi this program is for C Create a HockeyPlayer class that

***** Hi, this program is for C# *******

Create a HockeyPlayer class that player’s name, jersey number, and goal scored. Your HockeyPlayer class needs to include two constructors, one accepts parameters for name and jersey number; the other accepts parameters for name, jersey number and goal scored. Make sure that the goal scored be positive number.

Solution

Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Hockey // NameSpace Hockey
{
class HockeyPlayer // Class Name HockeyPlayer
{
string name; // Attributes name,jersey and score
int jerseyNumber;
   int score;

//First Parameterized Constructor
public HockeyPlayer(string name, int jerseyNumber)
{
this.name = name; // Assigning attributes using this object to refer current class
this.jerseyNumber = jerseyNumber;
Console.WriteLine(\"The player with jersey number \"+jerseyNumber+\" named \"+name);
}

   //Second Parameterized Constructor
public HockeyPlayer(string name, int jerseyNumber, int score)
{
this.name = name;
this.jerseyNumber = jerseyNumber;
   if(score>0){
   this.score = score;
Console.WriteLine(\"The player with jersey number \"+jerseyNumber+\" named \"+name+\" has scored \"+score+\" goals\");
}else{
Console.WriteLine(\"Please enter positive goals\");
}
}
}

class Program // Main Class
{
public static void Main(string[] args)
{ // CReating objects to call two constructors
HockeyPlayer hp1 = new HockeyPlayer(\"James\",666); //First Constructor Called
HockeyPlayer hp2 = new HockeyPlayer(\"James\",666,3); //Second Constructor
   HockeyPlayer hp3 = new HockeyPlayer(\"James\",666,-3);
}
}
}

Output:

***** Hi, this program is for C# ******* Create a HockeyPlayer class that player’s name, jersey number, and goal scored. Your HockeyPlayer class needs to includ

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site