0% found this document useful (0 votes)
61 views3 pages

Getter

This document contains C# code that defines classes with properties (getters and setters) to encapsulate data. It defines a Itemtype class with private name, deposit, and costperday fields, and public getters and setters to access and modify these properties. A Display method prints the property values. A Program class instantiates an Itemtype object, sets its property values, and calls Display. Two additional classes are defined - StallCategory to represent a market stall with name and details, and Addition to represent adding two numbers, each demonstrating default and parameterized constructors.

Uploaded by

sweda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

Getter

This document contains C# code that defines classes with properties (getters and setters) to encapsulate data. It defines a Itemtype class with private name, deposit, and costperday fields, and public getters and setters to access and modify these properties. A Display method prints the property values. A Program class instantiates an Itemtype object, sets its property values, and calls Display. Two additional classes are defined - StallCategory to represent a market stall with name and details, and Addition to represent adding two numbers, each demonstrating default and parameterized constructors.

Uploaded by

sweda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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