Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program is in c#. Please assist You are to write a program which is going to use

ID: 3585672 • Letter: P

Question

Program is in c#. Please assist

You are to write a program which is going to use inheritance. It should start off with the base classes

Account: contains the string name, int accountnumber, double balance.

Savings: Derived from Account class, it should contain double interest rate.

Checkings: Derived from Account class, it should contain double overdraftlimit.

CreditCard: Derived from Checkings class, it should contain int cardnumber.  

Create a program which will create an array of 3 Savings accounts, 3 Checkings accounts and 3 CreditCards.

Create 3 files. Savings.txt, Checkings.txt, CreditCards.txt which contains the information for each and infile the information from the file to the array of the classes. *You will come up with the information in each file*

You will be graded on the method used to infile (make sure to use loops), the way the classes are constructed (inheritance), and the way the the classes are used (make sure the constructor and overloaded constructor is used correctly).

As for the Main, simply do a display of all 3 savings, checkings and creditcards in a neat fashion.

zip the whole project and upload it (make sure the files are already populated with data).

Explanation / Answer

// --- DEBUG OUTPUT SNAPSHOTS --//

//----------- CODE ---------------//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO; // needed for file operations

namespace bank
{
    //
    class Account
    {
        //
        string name;
        //
        int accountNumber;
        //
        double balance;
        //
        public Account()
        {
            //empty default constructor
        }
        //

            // parameterized constructor
        public Account(String nm, int acc, double bal)
        {
            //
            accountNumber = acc;
            //
            name = nm;
            //
            balance = bal;
        }

    }
    //

        // Savings class derived from Accounts class
    class Savings:Account
    {
        //
        double interestRate;
        //

        public Savings()
        {
            // empty default constructor
        }
        //

            // parameterized constructor, initializes the base class constructor as well
        public Savings(String nm, int accnum, double bal, double rate):base(nm, accnum, bal)
        {
            //
          
            interestRate = rate;
        }
        //

    }
    //

        // Checkings class derived from Account class
        class Checkings:Account
    {
        //
        double overDraftLimit;
        //
        public Checkings()
        {
            // empty default constructor
        }
        //

            /// <summary>
            /// Parameterized constructor
            /// </summary>
            /// <param name="oDLimit">Over darft limit value</param>
        public Checkings(String nm, int accnum, double bal, double rate, double oDLimit):base(nm, accnum, bal)
        {
            //
            overDraftLimit = oDLimit;
        }
        //

    }
    //

  
    /// <summary>
    ///
    /// CreditCard class derived from Checkings class
    /// </summary>
        class CreditCard:Checkings
    {
        //
        int cardNumber;
        //
        public CreditCard()
        {
            //empty default constructor
        }
        //

            // parameterized constructor
        public CreditCard(String nm, int accnum, double bal, double rate, double oDLimit, int num):base(nm, accnum, bal, rate, oDLimit)
        {
            //
            cardNumber = num;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //
            Savings[] savingsAccounts = new Savings[3]; // declare an array of 3 Savings objects
            //
            Checkings[] checkingsAccounts = new Checkings[3]; // declare array of 3 Checkings objects
            //
            CreditCard[] cardAccounts = new CreditCard[3]; // declare array of 3 CreditCard objects
            //
            // must provide complete file path
            String[] fnames = { "c:\Users\sambit\documents\visual studio 2015\Projects\bank\Savings.txt", "c:\Users\sambit\documents\visual studio 2015\Projects\bank\CreditCards.txt", "c:\Users\sambit\documents\visual studio 2015\Projects\bank\Checkings.txt" }; // create an array of all file names
            //
            String line; // this will store each line that is read
            //
            int i = 0; // this will be used to index the objects
            //
            // create a loop to iterate over each file name in the list above and read
            foreach (String name in fnames)
            {
                //
                i = 0;
                //
                StreamReader fread = new StreamReader(name); // create a stream reader object using a file and read data
                //
                line = fread.ReadLine();
                //
                String[] substrings;
                //
                // read till we reach the end of current file
                while (line != null)
                {
                    //
                    substrings = line.Split(':');
                    //
                    // verify the file type being currently read and store accordingly in one of the three arrays
                    if (name.Contains("Savings"))
                    {
                        //
                        savingsAccounts[i] = new Savings(substrings[0], Convert.ToInt32(substrings[1]), Convert.ToDouble(substrings[2]), Convert.ToInt32(substrings[3]));
                        //
                        i++;

                    }
                    //
                    if (name.Contains("Checkings"))
                    {
                        //
                        checkingsAccounts[i] = new Checkings(substrings[0], Convert.ToInt32(substrings[1]), Convert.ToDouble(substrings[2]), Convert.ToInt32(substrings[3]), Convert.ToDouble(substrings[4]));
                        //
                        i++;
                    }
                    //
                    if (name.Contains("CreditCards"))
                    {
                        // read each part of the substring into apporpriate parameters of the constructor
                        cardAccounts[i] = new CreditCard(substrings[0], Convert.ToInt32(substrings[1]), Convert.ToDouble(substrings[2]), Convert.ToInt32(substrings[3]), Convert.ToDouble(substrings[4]), Convert.ToInt32(substrings[5]));
                        //
                        i++;
                    }
                    //
                    line = fread.ReadLine();

                }
                //Console.WriteLine(line);
                //

            }
            //
        }
            }
          
            //
         
    }