So, I have the following program: Class 1: Program.cs using System; using System
ID: 3683610 • Letter: S
Question
So, I have the following program:
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 int accountNumber;
private String firstName;
private double initialBalance;
private String lastName;
//Constructor to set first name and last name
public Customer(String firstName, String lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}
public Customer(string firstName, string lastName, int accountNumber, double initialBalance) : this(firstName, lastName)
{
this.accountNumber = accountNumber;
this.initialBalance = initialBalance;
}
//Returns first name
public string getFirstName()
{
return firstName;
}
//Returns last name
public string getLastName()
{
return lastName;
}
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Class 3: Account.cs
/**The Account class inherits the properties from the Customer class
and overloades display methods */
//Account.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankApplication
{
class Account : Customer
{
private int accountNumber;
private double initialBalance;
private double transactionType;
private double finalBalance;
//constructor that sets the values id and balance and calls the base class Customer with
//first and last name
public Account(string firstName, string lastName, int accountNumber, double initialBalance, double transactionType) : base(firstName, lastName, accountNumber, initialBalance)
{
this.accountNumber = accountNumber;
this.initialBalance = initialBalance;
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}", accountNumber, getFirstName(), getLastName(), finalBalance);
}
//One argument method that takes the account number as 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}", accountNumber, 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}", accountNumber, getFirstName(), getLastName(), finalBalance);
}
}
}
So, I need the program to be added to/modified. I want the user to be able to input whether or not they are doing a transaction for a business account/personal account and then I want a business class and a personal class created. I want the Account.cs to inherit from the business acount/personal account. Add comments as necessary. The code has to meet the following requirements:
Create a C# console program that implements Object-Oriented techniques:
1.- Develop a generic class object with at least two properties, and one method. 2.- The method for the class must accomplish some calculation. 3.- Develop a class that inherits from the first class (create a derived class). 4.- Add at least two properties and at least one method that accomplish a calculation and displays the result to the derived class. 5.- Develop three overloaded constructors for the derived class (one with no parameters, one with a parameter for one of the properties, one with parameters for both properties). 6.- User interface should provide access to all derived class properties and methods.
Explanation / Answer
//Develop a class that inherits from the first class (create a derived class).
//Add at least two properties and at least one method that accomplish a calculation and displays the result to the derived class.
//Develop three overloaded constructors for the derived class (one with no parameters, one with a parameter for one of the properties, one with parameters for both properties)
public class DerivedClass : customer {
// properties of class
private int accountNumber;
private double initialBalance;
private double transactionType;
private double finalBalance;
private double existBalance;
//Default Constructor
public DerivedClass(){
}
// one properties of Constructor
public DerivedClass(double initialBalance){
this.initialBalance = initialBalance;
}
// two properties of Constructor
public DerivedClass(double initialBalance,double existBalance){
this.initialBalance = initialBalance;
this.existBalance = existBalance;
}
//method
public double calculateBalance(double initialBalance,double existBalance){
finalBalance = existBalance+initialBalance;
}}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.