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

USING VISUAL STUDIO PLEASE PROVIDE THE CODE IN C# LANGUAGE IN CONSOLE APPLICATIO

ID: 3586194 • Letter: U

Question

USING VISUAL STUDIO PLEASE PROVIDE THE CODE IN C# LANGUAGE IN CONSOLE APPLICATION. PLEASE FOLLOW THE INSTRUCTIONS CAREFULLY.

Create 5 classes

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.

Explanation / Answer

Solution to problem is given below. Sample execution output is also provided for reference.

File: Accounts.cs

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

namespace Accounts
{
public class Account
{
protected string name;
protected int accountNumber;
protected double balance;
  
public Account(string n, int an, double b)
{
name = n;
accountNumber = an;
balance = b;
}
}
  
public class Savings : Account
{
protected double interestRate;
  
public Savings(string n, int an, double b, double ir) : base(n, an, b)
{
interestRate = ir;
}

public void displayHeader()
{
Console.WriteLine("Savings Accounts");
Console.WriteLine("| {0,-25} | {1,-10} | {2,-10} | {3,-10} |", "Name", "A/C No", "Balance", "Rate");
}

public void display()
{
Console.WriteLine("| {0,-25} | {1,-10} | {2,-10} | {3,-10} |", name, accountNumber, balance, interestRate);
}
}
  
public class Checkings : Account
{
protected double overdraftLimit;
  
public Checkings(string n, int an, double b, double ol) : base(n, an, b)
{
overdraftLimit = ol;
}

public void displayHeader()
{
Console.WriteLine("Checkings Accounts");
Console.WriteLine("| {0,-25} | {1,-10} | {2,-10} | {3,-10} |", "Name", "A/C No", "Balance", "OD Limit");
}

public void display()
{
Console.WriteLine("| {0,-25} | {1,-10} | {2,-10} | {3,-10} |", name, accountNumber, balance, overdraftLimit);
}
}
  
public class CreditCard : Checkings
{
protected int cardNumber;
  
public CreditCard(string n, int an, double b, double ol, int cn) : base(n, an, b, ol)
{
cardNumber = cn;
}

new public void displayHeader()
{
Console.WriteLine("Credit Card Accounts");
Console.WriteLine("| {0,-25} | {1,-10} | {2,-10} | {3,-10} | {4, -16} |", "Name", "A/C No", "Balance", "OD Limit", "Card No");
}

new public void display()
{
Console.WriteLine("| {0,-25} | {1,-10} | {2,-10} | {3,-10} | {4, -16} |", name, accountNumber, balance, overdraftLimit, cardNumber);
}
}
  
public class Program
{
public static void Main(string[] args)
{
Savings[] savingsAccounts = new Savings[3];
Checkings[] checkingsAccounts = new Checkings[3];
CreditCard[] creditCardAccounts = new CreditCard[3];

String line = "";
int index = 0;
using (StreamReader sr = new StreamReader("Savings.txt"))
{
while ((line = sr.ReadLine()) != null)
{
string[] values = line.Spilt(",");
if (values.Length >= 4)
{
savingsAccounts[index++] = new Savings(values[0],
Int32.Parse(values[1]),
double.Parse(values[2]),
double.Parse(values[3]));
}
}
}

index = 0;
using (StreamReader sr = new StreamReader("Checkings.txt"))
{
while ((line = sr.ReadLine()) != null)
{
string[] values = line.Spilt(",");
if (values.Length >= 4)
{
checkingsAccounts[index++] = new Checkings(values[0],
Int32.Parse(values[1]),
double.Parse(values[2]),
double.Parse(values[3]));
}
}
}

index = 0;
using (StreamReader sr = new StreamReader("CreditCards.txt"))
{
while ((line = sr.ReadLine()) != null)
{
string[] values = line.Spilt(",");
if (values.Length >= 5)
{
creditCardAccounts[index++] = new CreditCard(values[0],
Int32.Parse(values[1]),
double.Parse(values[2]),
double.Parse(values[3]),
Int32.Parse(values[4]));
}
}
}

for (index = 0; index < 3; index++) {
if (index == 0)
{
savingsAccounts[index].displayHeader();
}
savingsAccounts[index].display();
}
Console.WriteLine();

for (index = 0; index < 3; index++) {
if (index == 0)
{
checkingsAccounts[index].displayHeader();
}
checkingsAccounts[index].display();
}
Console.WriteLine();

for (index = 0; index < 3; index++) {
if (index == 0)
{
creditCardAccounts[index].displayHeader();
}
creditCardAccounts[index].display();
}
Console.WriteLine();
}
}
}

Sample Execution Output:

Savings Accounts
| Name | A/C No | Balance | Rate |
| John Doe | 100 | 100.5 | 0.06 |
| Jane Smith | 101 | 200.5 | 0.07 |
| Bob Dylan | 102 | 300.5 | 0.08 |

Checkings Accounts
| Name | A/C No | Balance | OD Limit |
| John Doe | 200 | 100.5 | 1000.0 |
| Jane Smith | 201 | 200.5 | 2000.0 |
| Bob Dylan | 202 | 300.5 | 3000.0 |

Credit Card Accounts
| Name | A/C No | Balance | OD Limit | Card No |
| John Doe | 300 | 100.5 | 1000.0 | 1234567890123456 |
| Jane Smith | 301 | 200.5 | 2000.0 | 1234567890123457 |
| Bob Dylan | 302 | 300.5 | 3000.0 | 1234567890123458 |