0% found this document useful (0 votes)
19 views

Program

The document defines a Product class with properties for ID, name and price, and a Display method to output those properties. It then creates a Program class with a Main method that gets user input for a product and calls the Display method.

Uploaded by

Vamsi Gembali
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)
19 views

Program

The document defines a Product class with properties for ID, name and price, and a Display method to output those properties. It then creates a Program class with a Main method that gets user input for a product and calls the Display method.

Uploaded by

Vamsi Gembali
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/ 2

using System;

public class Product{

private int productId;


private string productName;
private double price =0;

public int ProductId{


get{return productId;}
set{productId = value;}
}
public string ProductName{
get{return productName;}
set{
productName = value;
}
}
public double Price{
get{return price;}
set{
if(value<0)
{
price = 0;
}
else
{
price = value;
}
}
}

public void Display()


{
Console.WriteLine("Product ID : "+ ProductId); //this.productId
Console.WriteLine("Product Name : "+ ProductName);
Console.WriteLine("Product Price : "+ Price);
}
}

public class Program{


public static void Main(string[] arg)
{
Product p = new Product();
// Product p1 = new Product();

Console.WriteLine("Enter product id");


int id = Convert.ToInt32(Console.ReadLine());
p.ProductId = id;

Console.WriteLine("Enter product name");


string name = Console.ReadLine();
p.ProductName=name;

Console.WriteLine("Enter product price");


double price = Convert.ToDouble(Console.ReadLine());
if(price < 0)
{
price = 0;
}
p.Price = price;

p.Display();
}
}

You might also like