Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace getters_setters
{

class Itemtype
{
private string name = "N.A";
private int deposit = 0;
private int costperday = 0;

// Declare a Code property of type string:


public void SetName(String name)
{
this.name = name;
}
public String GetName()
{
return this.name;
}
public void SetDeposit(int deposit)
{
this.deposit = deposit;
}
public int GetDeposit()
{
return this.deposit;
}

public void SetCostperday(int costperday)


{
this.costperday = costperday;
}
public int GetCostperday()
{
return this.costperday;
}

public void Display()


{
Console.WriteLine("Itemname : {0}", GetName());
Console.WriteLine("DepositAmount : {0}", GetDeposit());
Console.WriteLine("Costperday : {0}", GetCostperday());
Console.ReadKey();

}
}

class Program
{
static void Main()
{

Itemtype i = new Itemtype();


i.SetName("Electronics");
i.SetDeposit(25000);
i.SetCostperday(1000);
i.Display();

Console.ReadKey();

}
}
}

//exercise2//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace getter
{
class StallCategory
{
private string name;
private string details;
public StallCategory()
{
Console.Write("Using Default constructor");
Console.WriteLine("\nDetails of the stall category:");
Console.WriteLine("Name:Book");
Console.WriteLine("Details:All latest books are available under this
category");

}
public StallCategory(string name,string details)
{
this.name = name;
this.details = details;
}

public void Display()


{
Console.WriteLine("\nUsing Parameterised Constructor ");
Console.WriteLine("Details of the stall category:");
Console.WriteLine("Name:{0}", name);
Console.WriteLine("Details:{0}", details);
}

}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the name of the stall category:");
string name = Console.ReadLine();
Console.WriteLine("Enter the details of the stall category:");
string details = Console.ReadLine();
StallCategory stall = new StallCategory();
StallCategory stall1 = new StallCategory(name, details);
stall1.Display();
Console.ReadLine();
}
}
}

//exercise3//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace getter
{
class Addition
{
private string name;
public int a;
public int b;
public Addition()
{
Console.Write("Using Default constructor");

}
public Addition(string name)
{
this.name = name;
Console.WriteLine("\nName:{0}", name);

}
public Addition(int a,int b)
{
a = a + b;
Console.WriteLine("Addition of two numbers : {0}", a);
}
~Addition()
{
Console.WriteLine("Destructor was called");
}

}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter name:");
string name = Console.ReadLine();
Console.WriteLine("Enter the numbers");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
Addition add = new Addition();
Addition add2 = new Addition(name);
Addition add1 = new Addition(a,b);
Console.ReadLine();
}
}
}

You might also like