Program
Output1
Enter name and score
Suresh
8
800001 Suresh 8 Selected
Output2
Enter name and score
3
The name field can't be empty...
800001 Not_Given 3 Not Selected
Output3
Enter name and score (max 10)
Syed
12
Invalid score entered...
800001 Syed 0 Fail
Output4
Enter name and score (max 10)
Pavan
-1
Invalid score entered..
800001 Pavan 0 Fail
using System;
namespace AboutClasses
{
class ClassWithProperties
{
class trainee
{
static int ID =
800001;
private int
_traineeID;
private string
_traineeName;
private int _score;
private string _result;
public trainee()
{
//Assigning
new ID...
_traineeID = ID;
//Incrementing
ID for next upcoming trainee object...
ID++;
_traineeName = "";
_score = 0;
_result = "Fail";
}
//Property for
_traineeID
public int
TraineeID
{
get
{
return _traineeID;
}
}
//Property for
_traineeName
public string
TraineeName
{
get
{
return _traineeName;
}
set
{
if (value.Length == 0)
{
Console.WriteLine("The name field can't be empty...");
_traineeName = "Not_Given";
}
else
_traineeName = value;
}
}
//Property for
_Score
public int Score
{
get
{
return _score;
}
set
{
int ReceivedValue = Convert.ToInt16(value);
if (ReceivedValue > 10 ||
ReceivedValue < 0)
{
Console.WriteLine("Invalid score entered...");
_score = 0;
}
else
{
_score = ReceivedValue;
_result = _score >=
7 ? "Selected" : "Not Selected";
}
}
}
//Property for
_Result
public string Result
{
get
{
return _result;
}
}
public void
GetEmpDetails(string name, int score)
{
TraineeName = name;
Score = score;
}
public void
displayEmpDetails()
{
Console.Write(TraineeID + "\t");
Console.Write(TraineeName + "\t");
Console.Write(Score + "\t");
Console.WriteLine(Result);
}
};
static void Main(string[] args)
{
trainee t1 = new trainee();
Console.WriteLine("Enter name and score (max
10)");
String Name = Console.ReadLine();
int Score = int.Parse(Console.ReadLine());
t1.GetEmpDetails(Name,Score);
t1.displayEmpDetails();
Console.ReadKey();
}
} //class
} //namespace
Enter name and score
Suresh
8
800001 Suresh 8 Selected
Output2
Enter name and score
3
The name field can't be empty...
800001 Not_Given 3 Not Selected
Output3
Enter name and score (max 10)
Syed
12
Invalid score entered...
800001 Syed 0 Fail
Output4
Enter name and score (max 10)
Pavan
-1
Invalid score entered..
800001 Pavan 0 Fail
No comments:
Post a Comment