C# Create an interface Itransaction contain void showTransaction(), double getAmount() ,Create class Transaction that inherit Itransaction and contains private string tCode; private string date; private double amount; add default constructor and parametric constructor to initialize values and implement void showTransaction(), double getAmount()in class.

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

namespace BLOGGER
{
    interface Itransaction
    {
        void showTransaction();
        double getAmount();
    }
    class Transaction : Itransaction
    {
        string tCode;
        string date;
        double amount;
        public Transaction()
        {

        }
        public Transaction(string a, string b, double c)
        {
            this.tCode = tCode;
            this.date = date;
            this.amount = amount;
        }
        public double getAmount()
        {
            Console.WriteLine("Enter amount");
            amount = Convert.ToDouble(Console.ReadLine());
            return amount;
        }
        public void showTransaction()
        {
            Console.WriteLine("Enter transaction code");
            tCode = Console.ReadLine();
            Console.WriteLine("Enter date of transaction");
            date = Console.ReadLine();
        }
        public void show()
        {
            Console.WriteLine("The tcode is " + tCode);
            Console.WriteLine("The date is " + date);
            Console.WriteLine("The amount is " + amount);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Transaction obj = new Transaction();
            obj = new Transaction("0", "0", 0);
            obj.getAmount();
            obj.showTransaction();
            obj.show();
            Console.ReadKey();


        }
    }
}
OUTPUT



No comments:

Post a Comment