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

Help me fix this please!!!! USING C# for this program: Here is my program code f

ID: 3863747 • Letter: H

Question

Help me fix this please!!!! USING C# for this program:

Here is my program code for C#:

Program0.cs:

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;


namespace Program0
{
public class Transactions
{
private double numberOfTransactions;

public Transactions(double numberOfTransactions)
{
this.numberOfTransactions = numberOfTransactions;
}

public Transactions()
{
}

public String type { get; set; }
public double amount { get; set; }
}

public class Account
{
public double starting_balance { get; set; }
//public double numberOfTransactions { get; set; }

//array of objects of transaction class
Transactions[] Transactions = new Transactions[50];
private int numberOfTransactions;

//Parameterized constructor with one argument for starting balance
public Account(double bal)
{
starting_balance = 500.00;
}

public void deposit(double amt)
{
Transactions[0] = new Transactions();
Transactions[0].type = "Deposit";
Transactions[0].amount = amt;
numberOfTransactions++;
}

public double getBalance()
{
double balance = starting_balance;
for (int i = 0; i < Transactions.Length; i++)
{
if (Transactions[i].type == "Deposit")
balance += Transactions[i].amount;
else if (Transactions[i].type == "Withdrawal")
balance -= Transactions[i].amount;
else
balance += Transactions[i].amount;
}
return balance;
}

public void withdraw(double amt)
{
Transactions[1] = new Transactions();
Transactions[1].type = "Withdrawal";
Transactions[1].amount = amt;
numberOfTransactions++;
}

public void addInterest()
{
Transactions[3] = new Transactions(numberOfTransactions);
Transactions[3].type = "Adding Interest";
Transactions[3].amount = (0.05 * this.getBalance()) / 100;
numberOfTransactions++;
}

public void showTransactions()
{
Console.WriteLine("Opening Balance: ", starting_balance);
for (int i = 0; i < Transactions.Length;)
{
Console.WriteLine("Transaction type: ", Transactions[i].type);
Console.WriteLine("Transaction amount: ", Transactions[i].amount);
}
Console.WriteLine("Current Balance: ", this.getBalance());
}
}
public static class Bank_Account
{
static void Main(string[] args)
{
Account acc = new Account(1200);
char input = ' ';
char c = Console.ReadLine()[0];
while (true)
{
Console.WriteLine("MENU");
Console.WriteLine("Please choose an action to perform:");
Console.WriteLine("(D)eposit");
Console.WriteLine("(W)ithdraw");
Console.WriteLine("(C)alculateInterest");
Console.WriteLine("(S)howBalance");
Console.WriteLine("(Q)uit");
char choice = char.Parse(Console.ReadLine());
switch (choice)
{
case 'D':
case 'd':
double amount = 0;
Console.WriteLine("Enter an amount to deposit");
String s1 = Console.ReadLine();
double d1 = Double.Parse(s1);
acc.deposit(d1);
break;
case 'W':
case 'w':
Console.WriteLine("Enter an amount to withdraw");
String s2 = Console.ReadLine();
double d2 = Double.Parse(s2);
acc.withdraw(d2);
break;
case 'C':
case 'c':
Console.WriteLine("Calculate the interest");
acc.addInterest();
break;
case 'S':
case 's':
Console.WriteLine("Transaction History");
Console.WriteLine("-------------------");
acc.showTransactions();
break;
case 'Q':
case 'q':
Console.WriteLine("exit");
break;
}
}
}
}
}

I am so close to getting it correct but I need to fix a couple things. The following is what I need to fix:

This close. A few things that might get it working better.

Execpt for Main, nothing should be static.

You should not redeclare numberOfTransactions in the withdraw method.

The transactions should be placed in Transactions[numberOfTransactions], not 0, 1 and 2.

When you use your array of transactions, stop at numberOfTransactions, not length.

Can someone please show me how I am suppose to do this off of the code that I posted towards the top.

Thank you in advance.

Explanation / Answer

Modified code as per your requirements:

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;


namespace Program0
{
    public class Transactions
    {
        private double numberOfTransactions;

        public Transactions(double numberOfTransactions)
        {
            this.numberOfTransactions = numberOfTransactions;
        }

        public Transactions()
        {
        }

        public String type { get; set; }
        public double amount { get; set; }
    }

    public class Account
    {
       public double starting_balance { get; set; }
        //public double numberOfTransactions { get; set; }

        //array of objects of transaction class
        Transactions[] transactions = new Transactions[50];
        private int numberOfTransactions;

        //Parameterized constructor with one argument for starting balance
        public Account(double bal)
        {
            starting_balance = 500.00;
        }

        public void deposit(double amt)
        {
            transactions[numberOfTransactions] = new Transactions();
            transactions[numberOfTransactions].type = "Deposit";
            transactions[numberOfTransactions].amount = amt;
            Console.WriteLine("Transaction type: {0}", transactions[0].type);
            numberOfTransactions++;
        }

        public double getBalance()
        {
            double balance = starting_balance;
            for (int i = 0; i < numberOfTransactions; i++)
            {
                if (transactions[i].type == "Deposit")
                    balance += transactions[i].amount;
                else if (transactions[i].type == "Withdrawal")
                    balance -= transactions[i].amount;
                else
                    balance += transactions[i].amount;
            }
            return balance;
        }

        public void withdraw(double amt)
        {
            transactions[numberOfTransactions] = new Transactions();
            transactions[numberOfTransactions].type = "Withdrawal";
            transactions[numberOfTransactions].amount = amt;
            numberOfTransactions++;
        }

        public void addInterest()
        {
            transactions[numberOfTransactions] = new Transactions(numberOfTransactions);
            transactions[numberOfTransactions].type = "Adding Interest";
            transactions[numberOfTransactions].amount = (0.05 * this.getBalance()) / 100;
            numberOfTransactions++;
        }

        public void showTransactions()
        {
            Console.WriteLine("Opening Balance: ", starting_balance);
          
            for (int i = 0; i < numberOfTransactions;i++)
            {
                Console.WriteLine("Transaction type: {0}", transactions[i].type);
                Console.WriteLine("Transaction amount: {0}", transactions[i].amount);
            }
            Console.WriteLine("Current Balance: {0}", this.getBalance());
        }
    }
    public static class Bank_Account
    {
        static void Main(string[] args)
        {
            Account acc = new Account(1200);
            char input = ' ';
            char c = Console.ReadLine()[0];
            while (true)
            {
                Console.WriteLine("MENU");
                Console.WriteLine("Please choose an action to perform:");
                Console.WriteLine("(D)eposit");
                Console.WriteLine("(W)ithdraw");
                Console.WriteLine("(C)alculateInterest");
                Console.WriteLine("(S)howBalance");
                Console.WriteLine("(Q)uit");
                char choice = char.Parse(Console.ReadLine());
                switch (choice)
                {
                    case 'D':
                    case 'd':
                        double amount = 0;
                        Console.WriteLine("Enter an amount to deposit");
                        String s1 = Console.ReadLine();
                        double d1 = Double.Parse(s1);
                        acc.deposit(d1);
                        break;
                    case 'W':
                    case 'w':
                        Console.WriteLine("Enter an amount to withdraw");
                        String s2 = Console.ReadLine();
                        double d2 = Double.Parse(s2);
                        acc.withdraw(d2);
                        break;
                    case 'C':
                    case 'c':
                        Console.WriteLine("Calculate the interest");
                        acc.addInterest();
                        break;
                    case 'S':
                    case 's':
                        Console.WriteLine("Transaction History");
                        Console.WriteLine("-------------------");
                        acc.showTransactions();
                        break;
                    case 'Q':
                    case 'q':
                        Console.WriteLine("exit");
                        break;
                }
            }
        }
    }
}