C# - Console Applications - Visual Studios You are to write a program which is g
ID: 3588211 • Letter: C
Question
C# - Console Applications - Visual Studios
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
namespace Assignment5 { class Account { //variables private double balance; private string accountName; private int accountNumber; public Account(string acctName, int acctNum, double acctBal) { //what is the purpose of doing this? accountName = acctName; accountNumber = acctNum; balance = acctBal; } //gets and sets public double Balance { get { return balance; } set { if (value >= 0) balance = value; else balance = 0; } } public string AccountName { get { return accountName; } } public int AccountNumber { get { return accountNumber; } } //credit, debit and print methods public void Credit(double a) { balance += a; } public void Debit(double a) { if (a > balance) Console.WriteLine("Insufficient Funds."); else balance -= a; } public void PrintAccount() { Console.WriteLine("Account Name : {0} Account Number : {1) Balance : {2:C}", accountName, accountNumber, balance); } class SavingsAccount : Account //this is how the derived class inherits from the base class, right? { public SavingsAccount(string acctName, int acctNum, double acctBal, double interest) : base(acctName, acctNum, acctBal) { accountName = acctName; accountNumber = acctNum; balance = acctBal; interestRate = interest; } private double interestRate; public double InterestRate { get { return interestRate; } set { if (value < 0) interestRate = 0; else interestRate = value; } } public void CalculateInterest() { balance = balance * interestRate; Console.WriteLine("Account Name: {0} Account Number: {1} Balance: {2:C} Interest Rate: {3:P2}", accountName, accountNumber, balance, interestRate); } public override string PrintAccount() { return string.Format("Account Name : {0} Account Number : {1) Balance : {2:C} Interest Rate : {3:P2}", accountName, accountNumber, balance, interestRate); } } class CheckingAccount : Account { public CheckingAccount(string acctName, int acctNum, double acctBal, double fee) : base(acctName, acctNum, acctBal) { accountName = acctName; accountNumber = acctNum; balance = acctBal; feeCharged = fee; } private double feeCharged; public double FeeAmmount { set { if (value < 0) feeCharged = 0; else feeCharged = value; } } //No idea how to "invoke the Account class and use a boolean value to see if //money was withdrawn." //public void Credit(double a) //{ // balance += a; // balance -= feeCharged; //} //public void Debit(double a) //{ // if (a > balance) // Console.WriteLine("Insufficient Funds."); // else // balance -= a; // balance -= feeCharged; //} public override string PrintAccount() { return string.Format("Account Name : {0} Account Number : {1) Balance : {2:C} Fee Charged : {3:C}", accountName, accountNumber, balance, feeCharged); } } class AccountTest { static void Main(string[] args) { //Step 1 & 2 CheckingAccount lemmonsChecking = new CheckingAccount("Lemmons-Checking", 1, 1000, 3); SavingsAccount lemmonsSavings = new SavingsAccount("Lemmons-Savings", 2, 2000, .05); //Step 3 & 4 lemmonsChecking.PrintAccount(); lemmonsSavings.PrintAccount(); //Step 5 & 6 Console.WriteLine(" Deposit $100 into checking."); lemmonsChecking.Credit(100); lemmonsChecking.PrintAccount(); //Step 7 & 8 Console.WriteLine(" Withdraw $50 from checking."); lemmonsChecking.Debit(50); lemmonsChecking.PrintAccount(); //Step 9 & 10 Console.WriteLine(" Withdraw $6000 from checking."); lemmonsChecking.Debit(6000); lemmonsChecking.PrintAccount(); //Step 11 & 12 Console.WriteLine(" Deposit $3000 into savings."); lemmonsSavings.Credit(3000); lemmonsSavings.PrintAccount(); //Step 13 & 14 Console.WriteLine(" Withdraw $200 from savings."); lemmonsSavings.Debit(200); lemmonsSavings.PrintAccount(); //Step 15 & 16 Console.WriteLine(" Calculate interest on savings."); lemmonsSavings.CalculateInterest(); //Step 17 & 18 Console.WriteLine(" Withdraw $10,000 from savings."); lemmonsSavings.Debit(10000); lemmonsSavings.PrintAccount(); Console.WriteLine(" Press the [ENTER] key to continue."); Console.ReadLine(); //I keep receiving errors based around the override I placed on the PrintAccount() } } } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.