Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Raber_assignment3
- {
- public class BankAccount
- {
- public string AccountNum { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public virtual string Owner {
- get {
- return $"Account #{AccountNum} -- {FirstName} {LastName}";
- }
- }
- public bool Overdraft { get; set; }
- public decimal Balance {
- get {
- return m_balance;
- }
- }
- protected decimal m_balance = 0m;
- public BankAccount() { }
- public BankAccount(string accountNumber,
- string firstName,string lastName){
- AccountNum = accountNumber;
- FirstName = firstName;
- LastName = lastName;
- }
- void DepositAmount(decimal amount){
- m_balance += amount;
- }
- public virtual bool WithdrawAmount(decimal amount,int? accountType = 1) {
- switch (accountType) {
- case null:
- //Savings account do stuff here
- break;
- case 0:
- //Cannont make overdrafts
- if (amount > m_balance) {
- throw new ArgumentOutOfRangeException("amount", "Insufficient funds. Please enter a smaller amount");
- } else if (amount < 0) {
- throw new ArgumentOutOfRangeException("amount", "No negitive withdrawal amounts are allowed. Please enter a valid amount");
- } else {
- m_balance -= amount;
- return false;
- }
- case 1:
- //Can make overdraft charges
- if (amount > m_balance) {
- m_balance -= amount;
- return true;
- } else if (amount < 0) {
- throw new ArgumentOutOfRangeException("amount", "No negtive amounts are allowed. Please enter a smaller amount");
- }else if(amount > 300m) {
- throw new ArgumentOutOfRangeException("amount", "Your daily maximun withdrawl is $300 dollars or less. Please enter a smaller amount");
- } else {
- m_balance -= amount;
- return false;
- }
- }
- return false;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Raber_assignment3 {
- public class CheckingAccount : BankAccount,IPrintable{
- public CheckingAccount() { }
- public CheckingAccount(string accountNum,string fName,string lName) : base(accountNum,fName,lName) {
- }
- enum CheckingAccountType {
- Basic,
- Premier
- }
- public override string Owner {
- get {
- return base.Owner;
- }
- }
- CheckingAccountType AccountType { get; set; }
- decimal OverDraftFee {
- get {
- return 10m * numOverdrafts;
- }
- }
- private int numOverdrafts = 0;
- int NumberOfOverdrafts {
- get {
- return numOverdrafts;
- }
- }
- public override bool WithdrawAmount(decimal amount,int? accountType=1) {
- return base.WithdrawAmount(amount);
- }
- public string PrintStatement() {
- string statement = $"Statement Date as of Today's Date for {Owner}.\n";
- statement += $"Checking Account Balance is {Balance.ToString("c")}.\n";
- statement += $"Amount of OverDraft fee for the month is {OverDraftFee.ToString("c")}\n";
- statement += $"The number of overdrafts for the month is {NumberOfOverdrafts}";
- return statement;
- }
- public string ShowBallance() {
- return $"Customer {Owner} has {Balance} in Checking Account";
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Raber_assignment3 {
- public class SavingsAccount : BankAccount, IPrintable {
- const decimal INTREST = 0.02m;
- const decimal BALANCE_CHECK = 100m;
- public SavingsAccount() { }
- public SavingsAccount(string accountNum,string fName,string lName) : base(accountNum,fName,lName) {
- this.AccountNum = accountNum;
- this.FirstName = fName;
- this.LastName = lName;
- }
- public override string Owner {
- get {
- return $"Savings -- {base.Owner}";
- }
- }
- public decimal AddIntrest() {
- if(m_balance > BALANCE_CHECK) {
- return m_balance * INTREST;
- }else {
- return 0m;
- }
- }
- public string PrintStatement() {
- string statement = $"Statement Date as of Today's date for {Owner}\n";
- statement += $"Savings Account Balance is {Balance}\n";
- statement += $"Intrest earned for the month is {AddIntrest()}\n";
- statement += $"Total Savings Account balance including intrested earned is {AddIntrest() + m_balance}\n";
- return statement;
- }
- public string ShowBallance() {
- return $"Customer {Owner} has {Balance.ToString("c")} in Savings Account";
- //throw new NotImplementedException();
- }
- }
- }
- //Ben Raber
- //simulates an Atm part 1
- //Created 2-1-2017
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Raber_assignment3 {
- public partial class Form1 : Form {
- /*
- * Program specifications (business requirements): Customer bank account
- * Create a Windows application that shows a customer account information.
- * This will be the Windows stub for the next couple of programming assignments.
- * Remember to think about the programming process when developing your solution:
- * INPUT
- * PROCESS/LOGIC/COMPUTATION/ALGORITHM
- * OUTPUT
- * Program requirements:
- * The Show Balance button should display a message box with an
- * Information icon, message box title “Customer Balance” and the OK button with the following message:
- * “Customer <<value from text box>> has $500 in the <<account combo value>> “.
- * The hard coded dollar value in the message box will remain the same.
- * The Welcome, Deposit, Withdrawal and Print Payment buttons should display the appropriate message
- * based on these buttons design constraints below.
- * The program should populate the accounts combo box with the following values of
- * Checking, Savings, Money Market, Certificate of Deposit showing the default value of
- * “---Select an Account Type—“.
- * The program should check to see if an account has been selected from the accounts dropdown list
- * before attempting to show the customer balance info via the Show Balance button. If no account has been selected, the following error message “No account selected. Please select an account” should be displayed in a Message Box with the error icon, message box title “Error” and the OK button.
- * The Clear button clears all UI fields and resets the accounts combo box to the first item in the combo box.
- * The Exit button closes the application.
- */
- public Form1() {
- InitializeComponent();
- }
- private CheckingAccount cAccount;
- private SavingsAccount sAccount;
- private void PopulateCombo() {
- cboAccount.Items.Add("--Select an Account--");
- cboAccount.Items.Add("Checking");
- cboAccount.Items.Add("Savings");
- cboAccount.Items.Add("Money Market");
- cboAccount.Items.Add("Certificate of Deposit");
- }
- private void ClearUI() {
- cboAccount.SelectedIndex = 0;
- txtDeposit.Clear();
- txtFisrtName.Clear();
- txtLastName.Clear();
- txtWithdrawl.Clear();
- grpCust.Enabled = true;
- txtDeposit.Enabled = false;
- txtFisrtName.Enabled = true;
- txtLastName.Enabled = true;
- txtWithdrawl.Enabled = false;
- btnDeposit.Enabled = false;
- btnWithdrawl.Enabled = false;
- mtxtAccountNumber.Clear();
- }
- private void MethodNotImplementedException() {
- throw new NotImplementedException();
- }
- private void Form1_Load(object sender, EventArgs e) {
- PopulateCombo();
- btnDeposit.Enabled = false;
- btnWithdrawl.Enabled = false;
- btnBalance.Enabled = false;
- btnPrintStatement.Enabled = false;
- txtDeposit.Enabled = false;
- txtWithdrawl.Enabled = false;
- cboAccount.SelectedIndex = 0;
- }
- private void btnWelcome_Click(object sender, EventArgs e) {
- if (ValadateUI()) {
- grpCust.Enabled = false;
- grpTransaction.Enabled = true;
- btnDeposit.Enabled = true;
- btnWithdrawl.Enabled = true;
- btnBalance.Enabled = true;
- btnPrintStatement.Enabled = true;
- txtDeposit.Enabled = true;
- txtWithdrawl.Enabled = true;
- btnWelcome.Enabled = false;
- }
- /*try {
- MethodNotImplementedException();
- }catch(NotImplementedException ex) {
- MessageBox.Show("Implementation is Pending", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }*/
- }
- //I need cAccount to be Availible to both btnDeposit and btnWithdrawl_Click
- //I don't know how to do that h
- private void btnDeposit_Click(object sender, EventArgs e) {
- if(txtDeposit.Text == String.Empty) {
- MessageBox.Show("Please enter an amount to Deposit in your account", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }else {
- }
- /*try {
- MethodNotImplementedException();
- } catch (NotImplementedException ex) {
- MessageBox.Show("Implementation is Pending", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }*/
- }
- private void btnWithdrawl_Click(object sender, EventArgs e) {
- if (txtWithdrawl.Text == string.Empty) {
- MessageBox.Show("Please enter an amount to withdraw.", "Mearmac Online Banking System", MessageBoxButtons.OK, MessageBoxIcon.Error);
- } else {
- switch (cboAccount.SelectedIndex) {
- case 0:
- break;
- case 1: //Checking Account
- cAccount = new CheckingAccount(mtxtAccountNumber.Text, txtFisrtName.Text, txtLastName.Text);
- decimal amount;
- bool result = decimal.TryParse(txtWithdrawl.Text, out amount);
- if (result) {
- cAccount.WithdrawAmount(amount);
- }
- break;
- case 2: //Savings Account
- sAccount = new SavingsAccount(mtxtAccountNumber.Text, txtFisrtName.Text, txtLastName.Text);
- result = decimal.TryParse(txtWithdrawl.Text, out amount);
- if (result) {
- sAccount.WithdrawAmount(amount);
- }
- break;
- }
- /*try {
- MethodNotImplementedException();
- } catch (NotImplementedException ex) {
- MessageBox.Show("Implementation is Pending", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- */
- }
- }
- private bool ValadateUI() {
- if (cboAccount.SelectedIndex == -1) {
- MessageBox.Show("Please select an Account Type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
- if (!(mtxtAccountNumber.MaskFull)) {
- MessageBox.Show("Please enter an account ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
- if(txtFisrtName.Text == String.Empty) {
- MessageBox.Show("Customer 1st name is Blank", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
- if(txtLastName.Text == String.Empty) {
- MessageBox.Show("Customer last name is Blank", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
- return true;
- }
- private void btnBalance_Click(object sender, EventArgs e) {
- //bool allValidationPassed = false;
- if (ValadateUI()) {
- MessageBox.Show($"{txtFisrtName.Text} {txtLastName.Text} has $500 in {cboAccount.SelectedItem.ToString()}");
- }
- }
- private void btnPrintStatement_Click(object sender, EventArgs e) {
- switch (cboAccount.SelectedIndex) {
- case 0:
- break;
- case 1:
- //Checking Account
- cAccount.PrintStatement();
- break;
- case 2:
- sAccount.PrintStatement();
- break;
- }
- /*try {
- MethodNotImplementedException();
- } catch (NotImplementedException ex) {
- MessageBox.Show("Implementation is Pending", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }*/
- }
- private void btnExit_Click(object sender, EventArgs e) {
- this.Close();
- Application.Exit();
- }
- private void btnClear_Click(object sender, EventArgs e) {
- ClearUI();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement