Professional Documents
Culture Documents
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sec2_MyFirstApp
{
class Program
{
static void Main(string[] args)
{
/*
string input = Console.ReadLine();
Console.WriteLine("input: {0}", input);
int x = int.Parse(Console.ReadLine());
Console.WriteLine("x = {0}", x);
*/
/*
Console.WriteLine("Welcome to SE310!");
int Id = 5;
string Name = "Mahmoud";
string Course = "SE310";
Console.WriteLine("Welcome "+ Name+" with Id "+Id);
Console.WriteLine("Welcome {0} with Id {1}", Name, Id);
Console.WriteLine("Welcome to the {0} course", Course);
Student S1;
S1 = new Student();
S1.SetFirstName("Mahmoud");
Console.WriteLine("FirstName = {0}", S1.GetFirstName());
S1.LastName = "Hammad";
Console.WriteLine("LastName = {0}", S1.LastName);
S1.Age = 15;
Console.WriteLine("Age = {0}", S1.Age);
}
}
public class Student
{
//instance variables
public const double PI = 22 / 7;
public readonly int ID;
private string FirstName;
public string LastName { set; get; }
private int age;
public int Age {
set {
if (value < 10)
{
Console.WriteLine("Too young!");
this.age = -1;
}
else
{
this.age = value; // + 10;
}
}
get { return 2*this.age; }
}
public string FullName
{
get
{
//return this.FirstName + " " + this.LastName + " " + this.age;
return string.Format("{0} {1} {2}",
this.FirstName, this.LastName, this.age);
//return string.Format("{0} {1} {2}", this.FirstName,
this.LastName, this.Age);
}
set
{
string[] values = value.Split(' ');
this.FirstName = values[0];
this.LastName = values[1];
//this.age = int.Parse(values[2]);
this.Age = int.Parse(values[2]);
}
}
public string ReadOnlyPro { get; private set; }
public string WriteOnlyPro { private get; set; }
//constructors
public Student() : this(0, "NA", "NA", 20)
{
/*
this.ID = 0;
this.FirstName = "NA";
this.LastName = "NA";
this.Age = 0;
*/
Console.WriteLine("Hello new student() :)");
}
//operations (methods)
public void SetFirstName(string FirstName)
{
if (FirstName.Length < 5)
{
Console.WriteLine("Too short!");
}
else
{
this.FirstName = FirstName;
}
}
public string GetFirstName()
{
return this.FirstName;
}
public void SaySomething(int Repeat = 1, string Msg = "Hello")
{
for (int i=0; i < Repeat; i++){
Console.WriteLine("{0} {1} {2}", this.FirstName, this.LastName,
Msg);
}
}
}
public class JUSTStudent : Student
{