Answer to Question #185785 in C# for CHANDRASENA REDDY CHADA

Question #185785

Write a program to create Product class name and products are tv Boolean is Smart and mobile Boolean is 5G with

productID > 0,

name > 3,

MFGDate < Today,

ExpDate add 2 years,

price > 0,

Quantity > 0,

Tax > 1 and < 30 ,

Discount > 1 and < 50,

struct price GST -> Basic

Enume GST5 or GST8

override display()


in outpu:-

display

productID,

name,

mfgDate,

ExpDate,

price,

ActualPrice = price + Tax - Discount,

TotalCost = ActualPrice * Quantity

Price.Get GSTPrice * Discount * Quantity


1
Expert's answer
2021-04-26T10:32:28-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace C_SHARP
{
    enum GST_TYPE { GST5, GST8 }
    abstract class Product
    {
        private int ID{get;set;}
        private string Name { get; set; }
        private DateTime MFGDate { get; set; }
        private DateTime ExpDate { get; set; }
        private double Price { get; set; }
        private int Quantity { get; set; }
        private double Tax { get; set; }
        private double Discount { get; set; }
        private GST_TYPE Type { get; set; }


        /// <summary>
        /// Constructor
        /// </summary>
        public Product() { }


        /// <summary>
        ///  Constructor
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="MFGDate"></param>
        /// <param name="price"></param>
        /// <param name="quantity"></param>
        /// <param name="tax"></param>
        /// <param name="discount"></param>
        /// <param name="type"></param>
        public Product(int id, string name, DateTime MFGDate, double price, int quantity, double tax, double discount, GST_TYPE type)
        {
            this.ID = id;
            this.Name = name;
            this.MFGDate = MFGDate;
            this.ExpDate = MFGDate.AddYears(2);//ExpDate add 2 years
            this.Price = price;
            this.Quantity = quantity;
            this.Tax = tax;
            this.Discount = discount;
            this.Type = type;
        }


        public virtual void display()
        {
            Console.WriteLine("Product ID: {0}", this.ID);
            Console.WriteLine("Product name: {0}", this.Name);
            Console.WriteLine("Product MFGDate: {0}", this.MFGDate.ToShortDateString());
            Console.WriteLine("Product ExpDate: {0}", this.ExpDate.ToShortDateString());
            Console.WriteLine("Product price: {0}", this.Price.ToString("C"));
            Console.WriteLine("Product quantity: {0}", this.Quantity);
            double actualPrice = Price + Tax - Discount;
            Console.WriteLine("Actual price: {0}", actualPrice.ToString("C"));
            double totalCost = actualPrice * Quantity;
            Console.WriteLine("Total cost: {0}", totalCost.ToString("C"));
            //Price. Get GSTPrice * Discount * Quantity;
            double GSTPrice=5;
            if (Type == GST_TYPE.GST5) {
                GSTPrice = 10;
            }
            double priceGST=GSTPrice * Discount * Quantity;
            Console.WriteLine("Price GST: {0}", priceGST.ToString("C"));
        }


    }
    class TV : Product
    {
        private bool isSmart;
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="MFGDate"></param>
        /// <param name="price"></param>
        /// <param name="quantity"></param>
        /// <param name="tax"></param>
        /// <param name="discount"></param>
        /// <param name="type"></param>
        /// <param name="isSmart"></param>
        public TV(int id, string name, DateTime MFGDate, double price, int quantity, double tax, double discount, GST_TYPE type, bool isSmart)
            : base(id, name, MFGDate, price, quantity, tax,  discount, type)
        {
            this.isSmart = isSmart;
        }


        public override void display()
        {
            Console.WriteLine("Is smart TV: {0}", this.isSmart);
            base.display();
        }
    }
    class Mobile : Product
    {
        private bool Has5G { get; set;}
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="MFGDate"></param>
        /// <param name="price"></param>
        /// <param name="quantity"></param>
        /// <param name="tax"></param>
        /// <param name="discount"></param>
        /// <param name="type"></param>
        /// <param name="has5G"></param>
        public Mobile(int id, string name, DateTime MFGDate, double price, int quantity, double tax, double discount, GST_TYPE type, bool has5G)
            : base(id, name, MFGDate, price, quantity, tax,  discount, type)
        {
            this.Has5G = has5G;
        }


        public override void display(){
            Console.WriteLine("Has 5G: {0}",this.Has5G);
            base.display();
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            Product[] products = new Product[2];
            products [0]= new Mobile(1, "Sumsung X5", new DateTime(2015,2,2), 400, 3, 10, 25, GST_TYPE.GST5, true);
            products[1] = new TV(2, "LG", new DateTime(2018,5,8), 400, 2, 30, 15, GST_TYPE.GST8, false);


            for (int i = 0; i < products.Length; i++) {
                products[i].display();
                Console.WriteLine();
            }


                Console.ReadLine();
        }
    }
}

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