Answer to Question #238643 in C# for Gayatri

Question #238643
Create a class named Product with the following private member variables.

Id of type long, ProductName of type string, SupplierName of type string and Include

appropriate

Getters and setters. Include a 3-argument constructor, 2 argument constructor and a default constructor. Assume that most of the products are supplied by "Nivas" suppliers and in the 2-argument constructor set the value of supplier Name to "Nivas".

Include a method named Display. It does not accept any arguments and its return type is void. Display the details of the product in this method. The method prototype is void Display ();

Create another class and write a man method to test the above class.
1
Expert's answer
2021-09-17T13:28:42-0400
using System;
using System.Linq;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var p1 = new Product();
            var p2 = new Product(7568658965498749, "Gin");
            var p3 = new Product(5469836938744987, "Jija", "Jojo");
            p1.Display();
            p2.Display();
            p3.Display();
        }
    }

    class Product
    {
        private long Id { get; }
        private string ProductName { get; }
        private string SupplierName { get; }

        public void Display()
        {
            Console.WriteLine($"Id is {Id}");
            Console.WriteLine($"ProductName is {ProductName}");
            Console.WriteLine($"SupplierName is {SupplierName}");
        }

        public Product(long id, string productName, string supplierName)
        {
            Id = id;
            ProductName = productName;
            SupplierName = supplierName;
        }
        
        public Product(long id, string supplierName)
        {
            Id = id;
            ProductName = "Nivas";
            SupplierName = supplierName;
        }
        
        public Product()
        {
            Id = 0;
            ProductName = "";
            SupplierName = "";
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS