You are on page 1of 3

using System;

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);

S1.FullName = "Sura Khamaiseh 20";


Console.WriteLine("FullName = {0}", S1.FullName);
Console.WriteLine("{0}, {1}, {2}",
S1.GetFirstName(), S1.LastName, S1.Age);
*/

Student S4 = new Student(1, "Shehab", "Dwairi", 22);


Console.WriteLine(S4.ID);
//S4.ID = 5;
Console.WriteLine(S4.ReadOnlyPro);
S4.WriteOnlyPro = "test";
//Console.WriteLine(S4.WriteOnlyPro);

Student S5 = new Student();


Console.WriteLine(S5.Age);
Console.WriteLine("last name = {0}", S5.LastName);
S5.SaySomething(2, "I am happy at JUST :)");
S5.SaySomething(1);
S5.SaySomething();
//S5.SaySomething("Welcome to SE310", 3); //CTE
S5.SaySomething(Msg: "Welcome to SE310", Repeat: 3);
string s = "hello";
//Student S6 = new Student(6, "Hudaifah");

}
}
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() :)");
}

public Student(int ID, string FirstName, string LastName, int Age)


{
Console.WriteLine("Custom constructor");
this.ID = ID;
this.FirstName = FirstName;
this.LastName = LastName;
this.Age = Age;
}

//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
{

You might also like