Written in C# - Console Applications - Visual Studios 2012 You are to write a pr
ID: 3588558 • Letter: W
Question
Written in C# - Console Applications - Visual Studios 2012
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*
Make sure to include 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace bank
{
using System;
public class Account
{
public string name { get; set; }
public int accountnumber { get; set; }
public double balance { get; set; }
}
public class Savings : Account
{
public double interestrate { get; set; }
}
public class Checkings : Savings
{
public double overdraftlimit { get; set; }
}
public class CreditCard : Checkings
{
public int cardnumber { get; set; }
}
public class Program
{
public static void Main()
{
Savings[] objSavings = new Savings[3];
StreamWriter writer = new StreamWriter("E:\Savings.txt",true);
for (int i=0;i<3;i++)
{
Console.WriteLine("Enter the savings name");
objSavings[i] = new Savings();
objSavings[i].name=Console.ReadLine().ToString();
Console.WriteLine("Enter the savings account number");
objSavings[i].accountnumber= Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the savings account balance");
objSavings[i].balance = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the savings account Intrest rate");
objSavings[i].interestrate= Convert.ToDouble(Console.ReadLine());
writer.Write(objSavings[i].name);
writer.Write(objSavings[i].accountnumber);
writer.Write(objSavings[i].accountnumber);
writer.Write(objSavings[i].interestrate);
writer.WriteLine(" ");
}
writer.Close();
Checkings[] objCheckings = new Checkings[3];
StreamWriter swchekings = new StreamWriter("E:\Savings.txt",true);
for (int i = 0; i < 3; i++)
{
Console.WriteLine("Enter the Checkings name");
objCheckings[i] = new Checkings();
objCheckings[i].name = Console.ReadLine().ToString();
Console.WriteLine("Enter the Checkings account number");
objCheckings[i].accountnumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Checkings account balance");
objCheckings[i].balance = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the Checkings account Intrest rate");
objCheckings[i].interestrate = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the Checkings account overdraftlimit");
objCheckings[i].overdraftlimit = Convert.ToDouble(Console.ReadLine());
swchekings.Write(objCheckings[i].name);
swchekings.Write(objCheckings[i].accountnumber);
swchekings.Write(objCheckings[i].accountnumber);
swchekings.Write(objCheckings[i].interestrate);
swchekings.Write(objCheckings[i].overdraftlimit);
swchekings.WriteLine(" ");
}
swchekings.Close();
CreditCard[] objCreditCard = new CreditCard[3];
StreamWriter swCreditCard = new StreamWriter("E:\CreditCard.txt", true);
for (int i = 0; i < 3; i++)
{
Console.WriteLine("Enter the Checkings name");
objCreditCard[i] = new CreditCard();
objCreditCard[i].name = Console.ReadLine().ToString();
Console.WriteLine("Enter the CreditCard account number");
objCreditCard[i].accountnumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the CreditCard account balance");
objCreditCard[i].balance = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the CreditCard account Intrest rate");
objCreditCard[i].interestrate = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the CreditCard account overdraftlimit");
objCreditCard[i].overdraftlimit = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the CreditCard account number");
objCreditCard[i].overdraftlimit = Convert.ToDouble(Console.ReadLine());
swchekings.Write(objCreditCard[i].name);
swchekings.Write(objCreditCard[i].accountnumber);
swchekings.Write(objCreditCard[i].accountnumber);
swchekings.Write(objCreditCard[i].interestrate);
swchekings.Write(objCreditCard[i].overdraftlimit);
swchekings.WriteLine(" ");
}
swCreditCard.Close();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.