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

Can someone modify this code to use properties instead of accessors and mutators

ID: 3684380 • Letter: C

Question

Can someone modify this code to use properties instead of accessors and mutators? Please do this for all three classes below.

Class 1 Program.cs:

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

namespace BankApplication
{
class Program
{
static void Main(string[] args)
{
string lastName;
string firstName;
int accountNumber;
double initialBalance = 0;
double finalBalance = 0;
double transactionType;

//Set up try catch for errors from user input
try
{
Console.Write("Enter your last name: ");
lastName = Console.ReadLine();

Console.Write("Enter your first name: ");
firstName = Console.ReadLine();

Console.Write("Enter your account number: ");
accountNumber = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter your initial account balance: $");
initialBalance = Convert.ToDouble(Console.ReadLine());

transactionType = transactionDecision(initialBalance);

//Create an Acccount class object
Account act = new Account(lastName, firstName, accountNumber, initialBalance, transactionType);

if (transactionType >= 0)
{
//Call deposit method
finalBalance = act.deposit(initialBalance, transactionType);
}
else
{
//Call withdraw method
finalBalance = act.withdraw(initialBalance, transactionType);
}

//Call display
act.display();
//Call display with account number
act.display(accountNumber);
//Call display with account number and balance
act.display(accountNumber, finalBalance);
}
catch (System.Exception e)
{
Console.WriteLine("An error has occurred.");
Console.WriteLine("The eror was: {0}", e.Message);
Console.ReadLine();
}

Console.Write("Press any key to continue.");
Console.ReadKey();
}

public static double transactionDecision(double initialBalance)
{
string transactionDecision;
double depositAmount = 0;
double withdrawAmount = 0;
double transactionType = 0;

Console.Write("Would you like to make a deposit (D) or withdraw (W): ");
transactionDecision = Convert.ToString(Console.ReadLine());
switch (transactionDecision.ToUpper())
{
case ("D"):
Console.Write("Enter the amount you are depositing: $");
depositAmount = Convert.ToDouble(Console.ReadLine());
transactionType = depositAmount;
break;

case ("W"):
Console.Write("Enter the amount you are withdrawing: $");
withdrawAmount = Convert.ToDouble(Console.ReadLine());
if (withdrawAmount > initialBalance)
{
Console.Write("Insufficient funds. Your transaction could not be completed.");
Console.ReadKey();
Environment.Exit(0);
}
transactionType -= withdrawAmount;
break;

default:
Console.WriteLine("You did not make an appropriate selection.");
break;
}

return transactionType;
}
}
}

Class 2 Customer.cs:

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

namespace BankApplication
{
class Customer
{
private Int32 accountNumber;
private String firstName;
private String lastName;

//Constructor to set the first name, the last name, and the account number
public Customer(String firstName, String lastName, Int32 accountNumber)
{
this.firstName = firstName;
this.lastName = lastName;
this.accountNumber = accountNumber;
}

//Returns first name
public string getFirstName()
{
return firstName;
}

//Returns last name
public string getLastName()
{
return lastName;
}

//Returns account number
public int getAccountNumber()
{
return accountNumber;
}
}
}

Class 3 Account.cs:

/*
The Account class inherits the properties from the Customer class and overloads the display method
*/

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

namespace BankApplication
{
class Account : Customer
{
  
private double transactionType;
private double finalBalance;

//Constructor
public Account(string firstName, string lastName, int accountNumber, double initialBalance, double transactionType) : base(firstName, lastName, accountNumber)
{
this.transactionType = transactionType;
}

public double deposit(double initialBalance, double transactionType)
{
finalBalance = initialBalance + transactionType;
return finalBalance;
}

public double withdraw(double initialBalance, double transactionType)
{
finalBalance = initialBalance - transactionType;
return finalBalance;
}

//Overloaded methods

public void display()
{
Console.WriteLine("Account Number : {0} Name : {1} {2} Balance: {3}", getAccountNumber(), getFirstName(), getLastName(), finalBalance);
}

//One argument method that takes the account number as an input argument and prints the account number with the account holder's name and balance
public void display(int accountNumber)
{
Console.WriteLine("Account Number : {0} Name : {1} {2} Balance: {3}", getAccountNumber(), getFirstName(), getLastName(), finalBalance);
}

//One argument method that takes the account number and the final balance as input arguments and prints the account number with the accound holder's name and balance
public void display(int accountNumber, double finalBalance)
{
Console.WriteLine("Account Number : {0} Name : {1} {2} Balance: {3}", getAccountNumber(), getFirstName(), getLastName(), finalBalance);
}
}
}

Explanation / Answer

//Customer.cs

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

namespace BankApplication
{
    class Customer
    {
        private Int32 _accountNumber;
        private String _firstName;
        private String _lastName;

        //Constructor to set the first name, the last name, and the account number
        public Customer(String firstName, String lastName, Int32 accountNumber)
        {
            this._firstName = firstName;
            this._lastName = lastName;
            this._accountNumber = accountNumber;
        }

        //FirstName property defintion
        public String FirstName
        {
            //get method
            get{
                return _firstName;
            }
            //set method
            set{
                _firstName=value;
            }
                      
        }

        //LastName property defintion
        public String LastName
        {
            //get method
            get
            {
                return _lastName;
            }
            //set method
            set
            {
                _lastName=value;
            }
        }

        //AccountNumber property defintion
        public int AccountNumber
        {
            //get method
            get
            {
                return _accountNumber;
            }
            //set method
            set
            {
                _accountNumber=value;
            }
        }
    }
}

-------------------------------------------------------------------------------------------------------------------------------------------------------

//Customer.cs

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

namespace BankApplication
{
    class Account : Customer
    {
        private   double _transactionType;
        private double _finalBalance;

        //Constructor
        public Account() :
            base("", "", 0)
        {
            this._transactionType =0;
            this._finalBalance = 0;
        }

        //Constructor
        public Account(string firstName, string lastName, int accountNumber, double initialBalance, double transactionType):
            base(firstName, lastName, accountNumber)
        {
            this._transactionType = transactionType;
        }


        //TransactionType property defintion
        public double TransactionType
        {
            set {
                _transactionType = value ;
            }

            get {
                return _transactionType ;
            }
        }

        //FinalBalance property defintion
        public double FinalBalance
        {
            set
            {
                _finalBalance = value;
            }

            get
            {
                return _finalBalance;
            }
        }

        public double deposit(double initialBalance, double transactionType)
        {
            _finalBalance = initialBalance + transactionType;
            return _finalBalance;
        }

        public double withdraw(double initialBalance, double transactionType)
        {
            _finalBalance = initialBalance - transactionType;
            return _finalBalance;
        }

        //Overloaded methods

        public void display()
        {
            //replace all accessor methods with properites of Account class
            Console.WriteLine("Account Number : {0} Name : {1} {2} Balance: {3}",
                AccountNumber, FirstName, LastName, FinalBalance);
        }

        //One argument method that takes the account number as an input argument and prints the account number with the account holder's name and balance
        public void display(int accountNumber)
        {
            //replace all accessor methods with properites of Account class
            Console.WriteLine("Account Number : {0} Name : {1} {2} Balance: {3}",
                AccountNumber, FirstName, LastName, FinalBalance);
        }

        //One argument method that takes the account number and the final balance as input arguments and prints the account number with the accound holder's name and balance
        public void display(int accountNumber, double finalBalance)
        {
            //replace all accessor methods with properites of Account class
            Console.WriteLine("Account Number : {0} Name : {1} {2} Balance: {3}",
                AccountNumber, FirstName, LastName, finalBalance);
        }
    }
}

Note: Account.cs and Customer.cs are modified to have Properties for instance variables of the classes.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote