C# (Basic)
#1 C#: Team Interface
Implement inheritance as described below.
Create a class Team that has the following:
A member variable teamName [string]
A member variable noOfPlayers [integer]
A constructor function:
It takes 2 parameters and assigns them to teamName and noOfPlayers respectively.
A member function AddPlayer(count):
It takes an integer count as a parameter and increases noOfPlayers by count.
A member function RemovePlayer(count):
It takes an integer count as a parameter and tries to decrease noOfPlayers by count.
If decreasing makes noOfPlayers negative, then this function simply returns false.
Else, decrease noOfPlayers by count and return true.
Create a class Subteam that inherits from the above class Team. It has the following:
A constructor function:
It takes 2 parameters, teamName and noOfPlayers, and calls the base class constructor with these parameters.
A member function ChangeTeamName(name):
It takes a string name as a parameter and changes teamName to name.
Note: Declare all the members as public so that they are accessible by the stubbed code.
#2 C#: Notes Store
In this challenge, the task is to implement a class called NotesStore. The class will manage a collection of notes, with each note having a state and a name. Valid states for notes are 'completed', 'active', and 'others'. All other states are invalid.
The class must have the following methods:
AddNote(state, name): adds a note with the given name (string) and state (string) to the collection. In addition to that:
If the passed name is empty, then it throws an Exception with the message 'Name cannot be empty'.
If the passed name is non-empty but the given state is not a valid state for a note, then it throws an Exception with the message 'Invalid state {state}'.
GetNotes(state): returns a list of note names with the given state (string) added so far. The names are returned in the order the corresponding notes were added. In addition to that:
If the given state is not a valid note state, then it throws an Exception with the message 'Invalid state {state}'.
If no note is found in this state, it returns an empty list.
Note: The state names are case-sensitive.
Last updated
Was this helpful?