-1

This is what I'm trying to achieve:

If a request is made to withdraw money over and above the allowed overdraft limit ($100), then no money is withdrawn, and a fixed flat fee ($10) is deducted from the balance.

In the code below I have tried my best to do so but it isn't working as when I withdraw an amount over my balance it doesn't give me a failed transaction fee it instead gives me a negative balance. I'm also unsure of how when the user clicks the Account details they want to see I want it to display the failed transaction fee if there is any if the user went over the overdraft.

Any help will be much appreciated. Just cant get my head around it.

class Program
{
    class Customer
    {
        private string firstName;
        private string lastName;
        private int phoneNumber;
        private string address;

        public Customer()
        {
            firstName = "Tayla";
            lastName = "Brown";
            phoneNumber = 027493922;
            address = "55 Grey Rd";
        }

        //client info
        public string ClientInfo()
        {
            string clientinfo = ("Account Holder: " + firstName + " " + lastName + " " + "Phone Number: " + phoneNumber + " " + "Address: " + address);
            return clientinfo;
        }
    }

    class Account : Customer
    {
        // Fields

        private double accountNumber;
        protected string accountType;

        protected double balance;
        protected double deposit;
        protected double withdrawal;
        protected double interest;
        protected double fee;
        protected double overdraft;

        // Properties

        public string AccountType
        {
            get { return this.accountType; }
        }

        public double Withdrawal
        {
            get { return this.withdrawal; }
            set { this.withdrawal = value; }
        }
        public double Deposit
        {
            get { return this.deposit; }
            set { this.deposit = value; }
        }
        public double AcctNumber
        { get { return this.accountNumber; } }

        public double Bal
        { get { return this.balance; } }

        public double f
        { get { return this.fee; } }

        public double od
        { get { return this.overdraft; } }

        // Creating Random Account Number

        public virtual double AccountNumb()
        {
            Random rand = new Random();
            this.accountNumber = rand.Next(100000000, 1000000000);
            return accountNumber;
        }


        public virtual double Fee()                                                                    // Work out Fee
        {
            overdraft = 100;
            fee = 10;

            if (balance < withdrawal)
            {
                balance -= (overdraft + withdrawal);

            }
            else if (balance > withdrawal)
            {
                balance -= withdrawal;
                fee -= balance;
            }
            return balance;
        }

        //Computes General Balance(resets values)
        public virtual double Balance()
        {
            balance = balance + deposit - withdrawal;
            deposit = 0;
            withdrawal = 0;
            return balance;
        }

        //Computers Balance when withdrawal equals zero
        public virtual double DepositBalance(double input)
        {
            deposit = input;
            withdrawal = 0;
            balance = balance + deposit - withdrawal;
            return balance;
        }

        //Computers balance when deposit equals zero
        public virtual double WithBalance(double input)
        {
            withdrawal = input;
            deposit = 0;
            balance = balance + deposit - withdrawal;
            return balance;
        }

        //displays online banking menu
        public virtual void DisplayMenu()
        {
            Console.WriteLine("Welcome to your online bank account\nPlease choose from the options below: ");
            Console.WriteLine("");
            Console.WriteLine("1.View Client Info");
            Console.WriteLine("");
            Console.WriteLine("2. View Account Balance:");
            Console.WriteLine("     2A.Everyday\n     2B.Investment\n     2C.Omni");
            Console.WriteLine("");
            Console.WriteLine("3.Deposit Funds:\n     3A.Everyday\n     3B.Investment\n     3C.Omni");
            Console.WriteLine("");
            Console.WriteLine("4.Withdraw Funds:\n     4A.Everyday\n     4B.Investment\n     4C.Omni");
            Console.WriteLine("");
            Console.WriteLine("5.View Everyday Banking Details");
            Console.WriteLine("6.View Investment Banking Details");
            Console.WriteLine("7.View Omni Banking details");
            Console.WriteLine("");
            Console.WriteLine("8.Exit");
        }
    }

    // Everyday Account

    class Everyday : Account
    {
        //field

        private double minBalance;
        private double maxBalance;

        //properties
        public double MinBalance
        { get { return this.minBalance; } }

        public double MaxBalance
        { get { return this.maxBalance; } }

        //constructors

        public Everyday(double balance) : base()
        {
            this.minBalance = 0;
            this.maxBalance = 1000000000000;
            this.balance = balance;
            accountType = "Everyday Account";
        }

        //methods
    }

    // Investment Account

    class Investment : Account
    {
        //fields
        private int investmentInterest;
        private int feeInvestment;

        //properties
        public int InterestInvestment
        {
            get { return this.investmentInterest; }                                  // Sets Interest
            set { investmentInterest = 4; }
        }

        public int FeeInvestment
        {
            get { return this.feeInvestment; }                                  // Sets Fee
            set { feeInvestment = 10; }
        }

        //constructors
        public Investment(double balance) : base()
        {
            this.balance = balance;
            accountType = "Investment Account";

        }
        //methods
    }

    // Omni Account

    class Omni : Account    // If a request is made to withdraw money over and above the allowed overdraft limit, then no money is withdrawn and 
                            // a fixed flat fee is deducted from the balance
    {
        //fields
        private int interestOmni;
        private int overdraft;


        //properties
        public int InterestOmni
        {
            get { return this.interestOmni; }    // Get interest 
            set { interestOmni = 4; }
        }
        public int OverDraftOmni
        {
            get { return this.overdraft; }     // Get overdraft
        }

        //constructors
        public Omni(double balance) : base()
        {
            interestOmni = 4;
            overdraft = 1000;                         // Overdraft same as min balance?
            this.balance = balance;
            accountType = "Omni Account";

        }
    }

    static void Main(string[] args)
    {

        // Object Insantiating

        Account client = new Account(); // Our one client

        Everyday everyday = new Everyday(2000);
        everyday.AccountNumb();
        Investment investment = new Investment(500);
        investment.AccountNumb();
        Omni omni = new Omni(1000);
        omni.AccountNumb();


        string streamEverydayAccount = ("Account Number: " + everyday.AcctNumber);
        string streamInvestmentAccount = ("Account Number: " + investment.AcctNumber);
        string streamOmniAccount = ("Account Number: " + omni.AcctNumber);

        string streamClientInfo = (client.ClientInfo());

        string everydayAccountType = (everyday.AccountType);
        string investmentAccountType = (everyday.AccountType);
        string omniAccountType = (everyday.AccountType);

        // StreamWriter Everyday Account

        using (StreamWriter everydaysummary = new StreamWriter(@"EverydaySummary.txt", true))
        {
            everydaysummary.WriteLine(everydayAccountType);
            everydaysummary.WriteLine(streamClientInfo);
            everydaysummary.WriteLine(streamEverydayAccount);
        }

        // StreamWriter Investment Account

        using (StreamWriter investmentsummary = new StreamWriter(@"InvestmentSummary.txt", true))
        {
            investmentsummary.WriteLine(investmentAccountType);
            investmentsummary.WriteLine(streamClientInfo);
            investmentsummary.WriteLine(streamInvestmentAccount);
        }

        // StreamWriter Omni Account

        using (StreamWriter omnisummary = new StreamWriter(@"OmniSummary.txt", true))
        {
            omnisummary.WriteLine(omniAccountType);
            omnisummary.WriteLine(streamClientInfo);
            omnisummary.WriteLine(streamOmniAccount);
        }

        bool test = false;

        do
        {
            string everydayDepositPara = ($"Transaction: +${everyday.Deposit} at {DateTime.Now.ToString()} Current Balance: ${everyday.Bal}");
            string everdayWithdrawalPara = ($"Transaction: -${everyday.Withdrawal} at {DateTime.Now.ToString()} Current Balance: ${everyday.Bal}");
            string investmentDepositPara = ($"Transaction: +${investment.Deposit} at {DateTime.Now.ToString()} Current Balance: ${investment.Bal}");
            string investmentWithdrawalPara = ($"Transaction: -${investment.Withdrawal} at {DateTime.Now.ToString()} Current Balance: ${investment.Bal}");
            string omniDepositPara = ($"Transaction: +${omni.Deposit} at {DateTime.Now.ToString()} Current Balance: ${omni.Bal}");
            string omniWithdrawalPara = ($"Transaction: -${omni.Withdrawal} at {DateTime.Now.ToString()} Current Balance: ${omni.Bal}");

            //INSTANTIATING STREAMWRITER FILES

            // Everyday

            using (StreamWriter everdayAccountStreamSummary = new StreamWriter("EverdaySummary.txt", true))
            {
                if (everyday.Deposit > 0)
                {
                    everdayAccountStreamSummary.WriteLine(everydayDepositPara);
                    everyday.Deposit = 0;
                }
                if (everyday.Withdrawal > 0)
                {
                    everdayAccountStreamSummary.WriteLine(everdayWithdrawalPara);
                    everyday.Withdrawal = 0;
                }
            }
            //Investment

            using (StreamWriter investmentAccountStreamSummary = new StreamWriter("InvestmentSummary.txt", true))
            {
                if (investment.Deposit > 0)
                {
                    investmentAccountStreamSummary.WriteLine(investmentDepositPara);
                    investment.Deposit = 0;
                }
                if (investment.Withdrawal > 0)
                {
                    investmentAccountStreamSummary.WriteLine(investmentWithdrawalPara);
                    investment.Withdrawal = 0;
                }
            }
            //Omni

            using (StreamWriter omniAccountStreamSummary = new StreamWriter("OmniSummary.txt", true))
            {
                if (omni.Deposit > 0)
                {
                    omniAccountStreamSummary.WriteLine(omniDepositPara);
                    omni.Deposit = 0;
                }
                if (omni.Withdrawal > 0)
                {
                    omniAccountStreamSummary.WriteLine(omniWithdrawalPara);
                    omni.Withdrawal = 0;
                }
            }

            client.DisplayMenu();//the online banking menu
            string userchoice = Console.ReadLine();//user input from menu options

            switch (userchoice.ToUpper())
            {
                case "1": // Display Client Info
                    Console.Clear();
                    Console.WriteLine(client.ClientInfo());
                    break;
                case "2A": // Display Everday Account Balance
                    Console.Clear();
                    everyday.Balance();
                    Console.WriteLine("Everyday Account Balance: $" + everyday.Bal);
                    break;
                case "2B": // Display Investment Account Balance
                    Console.Clear();
                    investment.Balance();
                    Console.WriteLine("Investment Account Balance: $" + investment.Bal);
                    break;
                case "2C": // Display Omni Account Balance
                    Console.Clear();
                    omni.Balance();
                    Console.WriteLine("Omni Account Balance: $" + omni.Bal);
                    break;
                case "3A": // Everyday Account Deposit
                    Console.Clear();
                    Console.WriteLine("How much would you like to deposit?");
                    everyday.Deposit = double.Parse(Console.ReadLine());
                    Console.WriteLine("You deposited: $" + everyday.Deposit);
                    everyday.DepositBalance(everyday.Deposit);
                    break;
                case "3B":
                    Console.Clear(); // Investment Account Deposit
                    Console.WriteLine("How much would you like to deposit?");
                    investment.Deposit = double.Parse(Console.ReadLine());
                    Console.WriteLine("You deposited: $" + investment.Deposit);
                    investment.DepositBalance(investment.Deposit);
                    break;
                case "3C":
                    Console.Clear(); // Omni Account Deposit
                    Console.WriteLine("How much would you like to deposit?");
                    omni.Deposit = double.Parse(Console.ReadLine());
                    Console.WriteLine("You deposited: $" + omni.Deposit);
                    omni.DepositBalance(omni.Deposit);
                    break;
                case "4A": // Everyday account Withdrawal
                    Console.Clear();
                    Console.WriteLine("How much would you like to withdraw?");
                    everyday.Withdrawal = double.Parse(Console.ReadLine());
                    Console.WriteLine("You withdrew: $" + everyday.Withdrawal);
                    everyday.WithBalance(everyday.Withdrawal);
                    break;
                case "4B":
                    Console.Clear(); // Investment Account Withdrawal
                    Console.WriteLine("How much would you like to withdraw?");
                    investment.Withdrawal = double.Parse(Console.ReadLine());
                    Console.WriteLine("You withdrew: $" + investment.Withdrawal);
                    investment.WithBalance(investment.Withdrawal);
                    break;
                case "4C":
                    Console.Clear(); // Omni Account Withdrawal
                    Console.WriteLine("How much would you like to withdraw?");
                    omni.Withdrawal = double.Parse(Console.ReadLine());
                    Console.WriteLine("You withdrew: $" + omni.Withdrawal);
                    omni.WithBalance(omni.Withdrawal);
                    break;
                case "5":
                    Console.Clear(); // Everyday Details
                    Console.WriteLine("Everyday Banking Details");
                    everyday.Balance();
                    Console.WriteLine("Everyday Account Balance: $" + everyday.Bal);
                    break;
                case "6":
                    Console.Clear(); // Investment Details
                    Console.WriteLine("Investment Banking Details");
                    everyday.Balance();
                    Console.WriteLine("Investment Account Balance: $" + investment.Bal);                                                    // Add Interest Rate and Fee
                    Console.WriteLine("Interest Rate: " + investment.InterestInvestment + "%");
                    Console.WriteLine("Fee: "
                        );
                    break;
                case "7":
                    Console.Clear(); // Omni Details
                    Console.WriteLine("Omni Banking Details");
                    everyday.Balance();
                    Console.WriteLine("Omni Account Balance: $" + omni.Bal);
                    Console.WriteLine("Interest Rate: " + omni.InterestOmni + "%");
                    Console.WriteLine("Fee: ");
                    break;
                case "8":
                    Console.Clear(); // Exit Banking
                    Console.WriteLine("You have chosen to exit the online banking. Thanks and come again!");
                    Environment.Exit(0);
                    break;
                default: // catch all, breaks the loop
                    Console.Clear();
                    test = false;
                    break;
            }
        } while (!test);
    }
}
Enigmativity
  • 113,464
  • 11
  • 89
  • 172
Tayla B
  • 1
  • 5
  • _"In the code below I have tried my best to do so but it isn't working"_ - please provide details of what you expect to happen, and what actually happens. You can edit your question to do this. – ProgrammingLlama Jul 15 '21 at 03:26
  • I've edited my description. Sorry about that, didn't explain what was happening. – Tayla B Jul 15 '21 at 03:32
  • @TaylaB - Your code is really broken. Can you please post your actual code? – Enigmativity Jul 15 '21 at 03:37
  • @Enigmativity Ive updated my code and inserted by entire project – Tayla B Jul 15 '21 at 03:47
  • An initial thought. `Account` should not inherit from `Customer`. They are two different things. An account can have a customer, but an account is not a customer. – Enigmativity Jul 15 '21 at 04:04
  • 1
    Don't have default data in the constructor for `Customer`. You've introduced a bug with that and having `Account` inherit from `Customer`. You should instantiate `Customer` once and pass in the data to the constructor and then make `Account` take `Customer` in its constructor. – Enigmativity Jul 15 '21 at 04:08
  • Awesome thanks for the pointers @Enigmativity Do you know how I could get the withdrawal fee working? – Tayla B Jul 15 '21 at 04:11
  • `DisplayMenu` should not be part of `Account`. – Enigmativity Jul 15 '21 at 04:15
  • @TaylaB - I'm trying to get your code in a state that makes sense to me before I try to work out the withdrawal fee. – Enigmativity Jul 15 '21 at 04:15
  • @Enigmativity thank you I'm new to this think I just kept adding unnecessary things and making it even harder for myself. – Tayla B Jul 15 '21 at 04:17
  • @TaylaB - Yes, you are. I can't finish this now, but will be back later. Perhaps in about 4 hours. – Enigmativity Jul 15 '21 at 04:25
  • @Enigmativity if you could that would be amazing thank you so much. – Tayla B Jul 15 '21 at 04:29
  • @TaylaB - Are you meant to write out a list of the transactions on the account with a running total of the balance? – Enigmativity Jul 15 '21 at 06:47
  • @TaylaB - Are you meant to write out a list of the transactions on the account with a running total of the balance? – Enigmativity Jul 16 '21 at 02:29
  • @Enigmativity Yes I am in the process of adding another case where the user can see a list of the previous transactions, but am currently struggling. – Tayla B Jul 18 '21 at 22:12
  • You're going to need a `class Transaction` with a `List`. Having a `enum TransactionType { Deposit, Withdrawal, Fee, Interest }` might be useful. – Enigmativity Jul 18 '21 at 23:43
  • @TaylaB - I've added a version with transactions. – Enigmativity Jul 19 '21 at 00:18

1 Answers1

0

I've done a refactor of your code - it was really quite difficult to understand what you were trying to do - so it's quite a large change. I have removed a lot of duplication, but I couldn't really complete everything because there was quite a bit missing in your code too.

I can't answer how to fix your one method in your code because the way that you were changing the state in your account classes was really difficult to follow.

In my refactoring I'm always computing the Balance like this:

    public decimal Balance => this.Opening + this.Deposits - this.Withdrawals + this.Interest - this.Fees;

So now it's just a matter of getting the various components of the Balance right.

Here's how Withdraw now works to do that:

    public (decimal Withdrawn, decimal Fee) Withdraw(decimal amount)
    {
        if (amount <= 0m)
        {
            throw new System.InvalidOperationException("Withdrawal amount must be positive");
        }
        decimal fee = 0;
        if (amount > this.Overdraft)
        {
            amount = 0m;
            fee = 10m;
        }
        else if (this.Balance < amount)
        {
            amount = this.Balance;
        }
        this.Withdrawals -= amount;
        return (amount, fee);
    }

If I've understood correctly, when you try to withdraw more that the Overdraft amount then you get a $10 fee and nothing is withdrawn. I've added a check to make sure you can't withdraw more than the balance.

Here's the rest of my refactoring. Let me know what you need to discuss:

class Program
{
    public class Client
    {
        private string _firstName;
        private string _lastName;
        private string _phoneNumber;
        private string _address;

        public Client(string firstName, string lastName, string phoneNumber, string address)
        {
            _firstName = firstName;
            _lastName = lastName;
            _phoneNumber = phoneNumber;
            _address = address;
        }

        public string ClientInfo =>
            $"Account Holder: {_firstName} {_lastName} Phone Number: {_phoneNumber} Address: {_address}";
    }

    public abstract class Account
    {
        private Client _client;

        public Account(Client client, int accountNumber, decimal opening)
        {
            _client = client;
            this.AccountNumber = accountNumber;
            this.Opening = opening;
        }

        public Account(Client client, decimal opening) : this(client, Account.GenerateAccountNumber(), opening)
        { }

        public int AccountNumber { get; private set; }

        public string AccountType => $"{this.GetType().Name} Account";

        public abstract decimal Overdraft { get; protected set; }

        public decimal Opening { get; protected set; }
        public decimal Deposits { get; protected set; }
        public decimal Withdrawals { get; protected set; }
        public decimal Interest { get; protected set; }
        public decimal Fees { get; protected set; }

        public decimal InterestRate { get; protected set; } = 4m;

        public decimal Balance => this.Opening + this.Deposits - this.Withdrawals + this.Interest - this.Fees;

        private static Random _random = new Random();
        public static int GenerateAccountNumber() => _random.Next(100000000, 1000000000);

        public (decimal Withdrawn, decimal Fee) Withdraw(decimal amount)
        {
            if (amount <= 0m)
            {
                throw new System.InvalidOperationException("Withdrawal amount must be positive");
            }
            decimal fee = 0;
            if (amount > this.Overdraft)
            {
                amount = 0m;
                fee = 10m;
            }
            else if (this.Balance < amount)
            {
                amount = this.Balance;
            }
            this.Withdrawals += amount;
            this.Fees += fee;
            return (amount, fee);
        }

        public decimal Deposit(decimal amount)
        {
            if (amount <= 0m)
            {
                throw new System.InvalidOperationException("Deposit amount must be positive");
            }
            this.Deposits += amount;
            return amount;
        }

        public IEnumerable<string> GetTransactions()
        {
            var now = DateTime.Now;
            if (this.Deposits > 0m)
            {
                yield return $"Deposits: +${this.Deposits} at {now.ToString()} Current Balance: ${this.Balance}";
            }
            if (this.Withdrawals > 0m)
            {
                yield return $"Withdrawals: +${this.Withdrawals} at {now.ToString()} Current Balance: ${this.Balance}";
            }
        }

        public string Summary => String.Join(Environment.NewLine, this.AccountType, _client.ClientInfo, "Account Number: " + this.AccountNumber);
    }

    public class Everyday : Account
    {
        public decimal MinBalance { get; private set; } = 0m;
        public decimal MaxBalance { get; private set; } = 1000000000000m;

        public override decimal Overdraft { get; protected set; } = 100m;

        public Everyday(Client client, decimal opening) : base(client, opening)
        { }

        public Everyday(Client client, int accountNumber, decimal opening) : base(client, accountNumber, opening)
        { }
    }

    public class Investment : Account
    {
        public decimal InvestmentFee { get; private set; } = 10m;

        public override decimal Overdraft { get; protected set; } = 100m;

        public Investment(Client client, decimal opening) : base(client, opening)
        { }

        public Investment(Client client, int accountNumber, decimal opening) : base(client, accountNumber, opening)
        { }
    }

    class Omni : Account
    {
        public override decimal Overdraft { get; protected set; } = 1000m;

        public Omni(Client client, decimal opening) : base(client, opening)
        { }

        public Omni(Client client, int accountNumber, decimal opening) : base(client, accountNumber, opening)
        { }
    }

    private static void DisplayBalance(Account account)
    {
        Console.WriteLine($"{account.AccountType} Balance: {account.Balance:$#,##0.00}");
    }

    private static void DepositAmount(Account account)
    {
        Console.WriteLine("How much would you like to deposit?");
        decimal deposited = account.Deposit(decimal.Parse(Console.ReadLine()));
        Console.WriteLine($"You deposited: {deposited:$#,##0.00} into your {account.AccountType}");
    }

    private static void WithdrawAmount(Account account)
    {
        Console.WriteLine("How much would you like to withdraw?");
        var result = account.Withdraw(decimal.Parse(Console.ReadLine()));
        Console.WriteLine($"You withdrew: {result.Withdrawn:$#,##0.00}");
        if (result.Fee != 0m)
        {
            Console.WriteLine($"With fee: {result.Fee:$#,##0.00}");
        }
    }

    private static void DisplayDetails(Everyday account)
    {
        Console.WriteLine("Everyday Banking Details");
        Console.WriteLine($"{account.AccountType} Balance: {account.Balance:$#,##0.00}");
    }

    private static void DisplayDetails(Investment account)
    {
        Console.WriteLine("Investment Banking Details");
        Console.WriteLine($"{account.AccountType} Balance: {account.Balance:$#,##0.00}");
        Console.WriteLine("Interest Rate: " + account.InterestRate + "%");
        Console.WriteLine("Fee: ");
    }

    private static void DisplayDetails(Omni account)
    {
        Console.WriteLine("Omni Banking Details");
        Console.WriteLine($"{account.AccountType} Balance: {account.Balance:$#,##0.00}");
        Console.WriteLine("Interest Rate: " + account.InterestRate + "%");
        Console.WriteLine("Fee: ");
    }

    private static void Main(string[] args)
    {
        bool test = false;

        Client client = new Client("Tayla", "Brown", "027493922", "55 Grey Rd"); // Our one client

        Everyday everyday = new Everyday(client, Account.GenerateAccountNumber(), 2000m);
        Investment investment = new Investment(client, 500m);
        Omni omni = new Omni(client, 1000m);

        File.WriteAllText(@"EverydaySummary.txt", everyday.Summary);
        File.WriteAllText(@"InvestmentSummary.txt", investment.Summary);
        File.WriteAllText(@"OmniSummary.txt", omni.Summary);

        do
        {
            File.WriteAllLines("EverdaySummary.txt", everyday.GetTransactions());
            File.WriteAllLines("InvestmentSummary.txt", investment.GetTransactions());
            File.WriteAllLines("OmniSummary.txt", omni.GetTransactions());

            DisplayMenu();
            string userchoice = Console.ReadLine();//user input from menu options

            switch (userchoice.ToUpper())
            {
                case "1": // Display Client Info
                          //Console.Clear();
                    Console.WriteLine(client.ClientInfo);
                    break;
                case "2A": // Display Everday Account Balance
                           //Console.Clear();
                    DisplayBalance(everyday);
                    break;
                case "2B": // Display Investment Account Balance
                           //Console.Clear();
                    DisplayBalance(investment);
                    break;
                case "2C": // Display Omni Account Balance
                           //Console.Clear();
                    DisplayBalance(omni);
                    break;
                case "3A": // Everyday Account Deposit
                           //Console.Clear();
                    DepositAmount(everyday);
                    break;
                case "3B":
                    //Console.Clear(); // Investment Account Deposit
                    DepositAmount(investment);
                    break;
                case "3C":
                    //Console.Clear(); // Omni Account Deposit
                    DepositAmount(omni);
                    break;
                case "4A": // Everyday account Withdrawal
                           //Console.Clear();
                    WithdrawAmount(everyday);
                    break;
                case "4B":
                    //Console.Clear(); // Investment Account Withdrawal
                    WithdrawAmount(investment);
                    break;
                case "4C":
                    //Console.Clear(); // Omni Account Withdrawal
                    WithdrawAmount(omni);
                    break;
                case "5":
                    //Console.Clear(); // Everyday Details
                    DisplayDetails(everyday);
                    break;
                case "6":
                    //Console.Clear(); // Investment Details
                    DisplayDetails(investment);
                    break;
                case "7":
                    //Console.Clear(); // Omni Details
                    DisplayDetails(omni);
                    break;
                case "8":
                    //Console.Clear(); // Exit Banking
                    Console.WriteLine("You have chosen to exit the online banking. Thanks and come again!");
                    test = true;
                    break;
                default: // catch all, breaks the loop
                         //Console.Clear();
                    test = false;
                    break;
            }
        } while (!test);
    }

    //displays online banking menu
    private static void DisplayMenu()
    {
        Console.WriteLine("Welcome to your online bank account\nPlease choose from the options below: ");
        Console.WriteLine("");
        Console.WriteLine("1.View Client Info");
        Console.WriteLine("");
        Console.WriteLine("2. View Account Balance:");
        Console.WriteLine("     2A.Everyday\n     2B.Investment\n     2C.Omni");
        Console.WriteLine("");
        Console.WriteLine("3.Deposit Funds:\n     3A.Everyday\n     3B.Investment\n     3C.Omni");
        Console.WriteLine("");
        Console.WriteLine("4.Withdraw Funds:\n     4A.Everyday\n     4B.Investment\n     4C.Omni");
        Console.WriteLine("");
        Console.WriteLine("5.View Everyday Banking Details");
        Console.WriteLine("6.View Investment Banking Details");
        Console.WriteLine("7.View Omni Banking details");
        Console.WriteLine("");
        Console.WriteLine("8.Exit");
    }
}

Here's some test code that shows that this should be working now.

private static void Main(string[] args)
{
    Client client = new Client("Tayla", "Brown", "027493922", "55 Grey Rd");
    Everyday everyday = new Everyday(client, Account.GenerateAccountNumber(), 30m);

    Console.WriteLine($"Balance: {everyday.Balance}");
    var r1 = everyday.Withdraw(15m);
    Console.WriteLine($"Withdrawn: {r1.Withdrawn}, Fee: {r1.Fee}, Balance: {everyday.Balance}");
    var r2 = everyday.Withdraw(1000m);
    Console.WriteLine($"Withdrawn: {r2.Withdrawn}, Fee: {r2.Fee}, Balance: {everyday.Balance}");
    var r3 = everyday.Withdraw(10m);
    Console.WriteLine($"Withdrawn: {r3.Withdrawn}, Fee: {r3.Fee}, Balance: {everyday.Balance}");
}

That gives:

Balance: 30
Withdrawn: 15, Fee: 0, Balance: 15
Withdrawn: 0, Fee: 10, Balance: 5
Withdrawn: 5, Fee: 0, Balance: 0

Here's a version with transactions.

class Program
{
    public class Client
    {
        private string _firstName;
        private string _lastName;
        private string _phoneNumber;
        private string _address;

        public Client(string firstName, string lastName, string phoneNumber, string address)
        {
            _firstName = firstName;
            _lastName = lastName;
            _phoneNumber = phoneNumber;
            _address = address;
        }

        public string ClientInfo =>
            $"Account Holder: {_firstName} {_lastName} Phone Number: {_phoneNumber} Address: {_address}";
    }

    public abstract class Account
    {
        private Client _client;

        public Account(Client client, int accountNumber, decimal opening)
        {
            _client = client;
            this.AccountNumber = accountNumber;
            this.Transactions.Add(Transaction.Create(DateTime.Now, opening, TransactionType.Opening));
        }

        public Account(Client client, decimal opening) : this(client, Account.GenerateAccountNumber(), opening)
        { }

        public int AccountNumber { get; private set; }

        public string AccountType => $"{this.GetType().Name} Account";

        public abstract decimal Overdraft { get; protected set; }

        public List<Transaction> Transactions { get; private set; } = new List<Transaction>();

        public decimal InterestRate { get; protected set; } = 4m;

        public decimal Balance => this.Transactions.Sum(t => t.Amount);

        private static Random _random = new Random();
        public static int GenerateAccountNumber() => _random.Next(100000000, 1000000000);

        public (decimal Withdrawn, decimal Fee) Withdraw(decimal amount)
        {
            if (amount <= 0m)
            {
                throw new System.InvalidOperationException("Withdrawal amount must be positive");
            }
            decimal fee = 0;
            if (amount > this.Overdraft)
            {
                amount = 0m;
                fee = 10m;
            }
            else if (this.Balance < amount)
            {
                amount = this.Balance;
            }
            if (amount > 0m)
            {
                this.Transactions.Add(Transaction.Create(DateTime.Now, amount, TransactionType.Withdrawal));
            }
            if (fee > 0m)
            {
                this.Transactions.Add(Transaction.Create(DateTime.Now, fee, TransactionType.Fee));
            }
            return (amount, fee);
        }

        public decimal Deposit(decimal amount)
        {
            if (amount <= 0m)
            {
                throw new System.InvalidOperationException("Deposit amount must be positive");
            }
            this.Transactions.Add(Transaction.Create(DateTime.Now, amount, TransactionType.Deposit));
            return amount;
        }

        public string Summary => String.Join(Environment.NewLine, this.AccountType, _client.ClientInfo, "Account Number: " + this.AccountNumber);
    }

    public class Everyday : Account
    {
        public decimal MinBalance { get; private set; } = 0m;
        public decimal MaxBalance { get; private set; } = 1000000000000m;

        public override decimal Overdraft { get; protected set; } = 100m;

        public Everyday(Client client, decimal opening) : base(client, opening)
        { }

        public Everyday(Client client, int accountNumber, decimal opening) : base(client, accountNumber, opening)
        { }
    }

    public class Investment : Account
    {
        public decimal InvestmentFee { get; private set; } = 10m;

        public override decimal Overdraft { get; protected set; } = 100m;

        public Investment(Client client, decimal opening) : base(client, opening)
        { }

        public Investment(Client client, int accountNumber, decimal opening) : base(client, accountNumber, opening)
        { }
    }

    class Omni : Account
    {
        public override decimal Overdraft { get; protected set; } = 1000m;

        public Omni(Client client, decimal opening) : base(client, opening)
        { }

        public Omni(Client client, int accountNumber, decimal opening) : base(client, accountNumber, opening)
        { }
    }
    
    public class Transaction
    {
        public DateTime When { get; private set; }
        public decimal Amount { get; private set; }
        public TransactionType Type { get; private set; }
        
        public static Transaction Create(DateTime when, decimal amount, TransactionType type)
        {
            if (amount <= 0m)
            {
                throw new System.InvalidOperationException("Transaction amount must be positive");
            }
            return new Transaction(when, (type == TransactionType.Withdrawal || type == TransactionType.Fee) ? -amount : amount, type);
        }
        
        private Transaction(DateTime when, decimal amount, TransactionType type)
        {
            this.When = when;
            this.Amount = amount;
            this.Type = type;
        }
    }

    public enum TransactionType { Opening, Deposit, Withdrawal, Fee, Interest }
    
    private static void DisplayBalance(Account account)
    {
        Console.WriteLine($"{account.AccountType} Balance: {account.Balance:$#,##0.00}");
    }

    private static void DepositAmount(Account account)
    {
        Console.WriteLine("How much would you like to deposit?");
        decimal deposited = account.Deposit(decimal.Parse(Console.ReadLine()));
        Console.WriteLine($"You deposited: {deposited:$#,##0.00} into your {account.AccountType}");
    }

    private static void WithdrawAmount(Account account)
    {
        Console.WriteLine("How much would you like to withdraw?");
        var result = account.Withdraw(decimal.Parse(Console.ReadLine()));
        Console.WriteLine($"You withdrew: {result.Withdrawn:$#,##0.00}");
        if (result.Fee != 0m)
        {
            Console.WriteLine($"With fee: {result.Fee:$#,##0.00}");
        }
    }

    private static void DisplayDetails(Everyday account)
    {
        Console.WriteLine("Everyday Banking Details");
        Console.WriteLine($"{account.AccountType} Balance: {account.Balance:$#,##0.00}");
    }

    private static void DisplayDetails(Investment account)
    {
        Console.WriteLine("Investment Banking Details");
        Console.WriteLine($"{account.AccountType} Balance: {account.Balance:$#,##0.00}");
        Console.WriteLine("Interest Rate: " + account.InterestRate + "%");
        Console.WriteLine("Fee: ");
    }

    private static void DisplayDetails(Omni account)
    {
        Console.WriteLine("Omni Banking Details");
        Console.WriteLine($"{account.AccountType} Balance: {account.Balance:$#,##0.00}");
        Console.WriteLine("Interest Rate: " + account.InterestRate + "%");
        Console.WriteLine("Fee: ");
    }

    private static void Main(string[] args)
    {
        bool test = false;

        Client client = new Client("Tayla", "Brown", "027493922", "55 Grey Rd"); // Our one client

        Everyday everyday = new Everyday(client, Account.GenerateAccountNumber(), 2000m);
        Investment investment = new Investment(client, 500m);
        Omni omni = new Omni(client, 1000m);

        File.WriteAllText(@"EverydaySummary.txt", everyday.Summary);
        File.WriteAllText(@"InvestmentSummary.txt", investment.Summary);
        File.WriteAllText(@"OmniSummary.txt", omni.Summary);

        do
        {
            File.WriteAllLines("EverdaySummary.txt", everyday.Transactions.Select(t => $"{t.When} {t.Type} {t.Amount}"));
            File.WriteAllLines("InvestmentSummary.txt", investment.Transactions.Select(t => $"{t.When} {t.Type} {t.Amount}"));
            File.WriteAllLines("OmniSummary.txt", omni.Transactions.Select(t => $"{t.When} {t.Type} {t.Amount}"));

            DisplayMenu();
            string userchoice = Console.ReadLine();//user input from menu options

            switch (userchoice.ToUpper())
            {
                case "1": // Display Client Info
                          //Console.Clear();
                    Console.WriteLine(client.ClientInfo);
                    break;
                case "2A": // Display Everday Account Balance
                           //Console.Clear();
                    DisplayBalance(everyday);
                    break;
                case "2B": // Display Investment Account Balance
                           //Console.Clear();
                    DisplayBalance(investment);
                    break;
                case "2C": // Display Omni Account Balance
                           //Console.Clear();
                    DisplayBalance(omni);
                    break;
                case "3A": // Everyday Account Deposit
                           //Console.Clear();
                    DepositAmount(everyday);
                    break;
                case "3B":
                    //Console.Clear(); // Investment Account Deposit
                    DepositAmount(investment);
                    break;
                case "3C":
                    //Console.Clear(); // Omni Account Deposit
                    DepositAmount(omni);
                    break;
                case "4A": // Everyday account Withdrawal
                           //Console.Clear();
                    WithdrawAmount(everyday);
                    break;
                case "4B":
                    //Console.Clear(); // Investment Account Withdrawal
                    WithdrawAmount(investment);
                    break;
                case "4C":
                    //Console.Clear(); // Omni Account Withdrawal
                    WithdrawAmount(omni);
                    break;
                case "5":
                    //Console.Clear(); // Everyday Details
                    DisplayDetails(everyday);
                    break;
                case "6":
                    //Console.Clear(); // Investment Details
                    DisplayDetails(investment);
                    break;
                case "7":
                    //Console.Clear(); // Omni Details
                    DisplayDetails(omni);
                    break;
                case "8":
                    //Console.Clear(); // Exit Banking
                    Console.WriteLine("You have chosen to exit the online banking. Thanks and come again!");
                    test = true;
                    break;
                default: // catch all, breaks the loop
                         //Console.Clear();
                    test = false;
                    break;
            }
        } while (!test);
    }

    //displays online banking menu
    private static void DisplayMenu()
    {
        Console.WriteLine("Welcome to your online bank account\nPlease choose from the options below: ");
        Console.WriteLine("");
        Console.WriteLine("1.View Client Info");
        Console.WriteLine("");
        Console.WriteLine("2. View Account Balance:");
        Console.WriteLine("     2A.Everyday\n     2B.Investment\n     2C.Omni");
        Console.WriteLine("");
        Console.WriteLine("3.Deposit Funds:\n     3A.Everyday\n     3B.Investment\n     3C.Omni");
        Console.WriteLine("");
        Console.WriteLine("4.Withdraw Funds:\n     4A.Everyday\n     4B.Investment\n     4C.Omni");
        Console.WriteLine("");
        Console.WriteLine("5.View Everyday Banking Details");
        Console.WriteLine("6.View Investment Banking Details");
        Console.WriteLine("7.View Omni Banking details");
        Console.WriteLine("");
        Console.WriteLine("8.Exit");
    }
}
Enigmativity
  • 113,464
  • 11
  • 89
  • 172
  • Hey thank you so much for this. But when I run this code I am still able to withdraw over the available balance. And yes you are correct about me wanting it to not let the user withdraw over the 100 overdraft limit and if they do so then give them a 20 fee. – Tayla B Jul 15 '21 at 21:52
  • I made a mistake with the line `Everyday everyday = new Everyday(client, 2000, Account.GenerateAccountNumber());` - it should be `Everyday everyday = new Everyday(client, Account.GenerateAccountNumber(), 2000m);`. C# does some implicit conversions that allows for the code to compile wen it shouldn't. – Enigmativity Jul 16 '21 at 01:40
  • @TaylaB - I'm working on making sure the code works for withdrawals. – Enigmativity Jul 16 '21 at 01:40
  • The other mistake I made was in the Withdraw code. It should have done a `this.Withdrawals += amount;`, not `this.Withdrawals -= amount;`. – Enigmativity Jul 16 '21 at 02:28
  • @TaylaB - And I forgot the line `this.Fees += fee;` in the `Withdraw` method. – Enigmativity Jul 16 '21 at 02:33
  • Wow thank you so much @Enigmativity its working now. – Tayla B Jul 18 '21 at 22:11