Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,924 questions

51,857 answers

573 users

How to declare and use Interfaces in C#

1 Answer

0 votes
using System;

public interface IBank {
    void printTransaction();
    double getTAmount();
}

public class BTransaction : IBank {
    private long tNumber;
    private string tDate;
    private double tAmount;

    public BTransaction() {
        tNumber = -1;
        tDate = "";
        tAmount = 0.0;
    }

    public BTransaction(long tn, string td, double ta) {
        tNumber = tn;
        tDate = td;
        tAmount = ta;
    }

    public double getTAmount() {
        return tAmount;
    }

    public void printTransaction() {
        Console.WriteLine("Transaction Number: {0}", tNumber);
        Console.WriteLine("Transaction Date: {0}", tDate);
        Console.WriteLine("Transaction Amount: {0}\n", getTAmount());
    }
} 

class TransactionRecords {
    static void Main(string[] args) {
        BTransaction t1 = new BTransaction(30021, "1/9/2024", 23085.00);
        BTransaction t2 = new BTransaction(38941, "1/10/2024", 34912.00);
        BTransaction t3 = new BTransaction(39674, "1/10/2024", 40203.00);

        t1.printTransaction();
        t2.printTransaction();
        t3.printTransaction();
    }
}



/*
run:

Transaction Number: 30021
Transaction Date: 1/9/2024
Transaction Amount: 23085

Transaction Number: 38941
Transaction Date: 1/10/2024
Transaction Amount: 34912

Transaction Number: 39674
Transaction Date: 1/10/2024
Transaction Amount: 40203

*/

 



answered Oct 31, 2024 by avibootz

Related questions

1 answer 167 views
167 views asked Jan 19, 2017 by avibootz
1 answer 148 views
1 answer 135 views
1 answer 126 views
126 views asked Jan 9, 2017 by avibootz
2 answers 240 views
240 views asked Sep 5, 2015 by avibootz
1 answer 167 views
...