Write a console application for a club to record their member information. For each member to need to store the member’s name and merit points. All new members starts with 0 merit points. Implement class Member which has private attributes for Name and Points. You need to create at a constructor method and the class also needs to have the following methods: public string getName() //Returns the name of the member public int getPoints() //Returns the points of the member public void setPoints(int P) //Sets the points of the member Open and edit your console application to handle the updated requirements. Update the Member class to include the following methods: public void diplayMember() //Display the name and points for a member int IComparable.CompareTo(object obj) //Used to sort the array in ascending order of name
using System;
using System.Collections.Generic;
namespace MemberApp
{
class Member : IComparable
{
private string Name;
private int Points;
public Member(string name, int points = 0)
{
this.Name = name;
this.Points = points;
}
public string getName()
{
return Name;
}
public int getPoints()
{
return Points;
}
public void setPoints(int P)
{
this.Points = P;
}
public void diplayMember()
{
Console.WriteLine("Name: " + Name + "\n" + "Points: " + Points + "\n");
}
int IComparable.CompareTo(object obj)
{
return this.Name.CompareTo(((Member)obj).Name);
}
}
class Program
{
static void Main(string[] args)
{
Console.ReadLine();
}
}
}
Comments
Leave a comment