Advertisement
Braber01

Stupid Logic Errors

Feb 17th, 2017
1,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Raber_assignment3
  8. {
  9.     public class BankAccount
  10.     {
  11.         public string AccountNum { get; set; }
  12.         public string FirstName { get; set; }
  13.         public string LastName { get; set; }
  14.         public virtual string Owner {
  15.             get {
  16.                 return $"Account #{AccountNum} -- {FirstName} {LastName}";
  17.             }
  18.         }
  19.         public bool Overdraft { get; set; }
  20.         public decimal Balance {
  21.             get {
  22.                 return m_balance;
  23.             }
  24.         }
  25.  
  26.         protected decimal m_balance = 0m;
  27.  
  28.         public BankAccount() { }
  29.        
  30.         public BankAccount(string accountNumber,
  31.                 string firstName,string lastName){
  32.             AccountNum = accountNumber;
  33.             FirstName = firstName;
  34.             LastName = lastName;
  35.  
  36.         }
  37.  
  38.         void DepositAmount(decimal amount){
  39.             m_balance += amount;
  40.         }
  41.  
  42.         public virtual bool WithdrawAmount(decimal amount,int? accountType = 1) {
  43.             switch (accountType) {
  44.                 case null:
  45.                     //Savings account do stuff here
  46.                     break;
  47.                 case 0:
  48.                     //Cannont make overdrafts
  49.                     if (amount > m_balance) {
  50.                         throw new ArgumentOutOfRangeException("amount", "Insufficient funds. Please enter a smaller amount");
  51.  
  52.                     } else if (amount < 0) {
  53.                         throw new ArgumentOutOfRangeException("amount", "No negitive withdrawal amounts are allowed. Please enter a valid amount");
  54.                     } else {
  55.                         m_balance -= amount;
  56.                         return false;
  57.                     }
  58.                 case 1:
  59.                     //Can make overdraft charges
  60.                     if (amount > m_balance) {
  61.                         m_balance -= amount;
  62.                         return true;
  63.                     } else if (amount < 0) {
  64.                         throw new ArgumentOutOfRangeException("amount", "No negtive amounts are allowed. Please enter a smaller amount");
  65.                     }else if(amount > 300m) {
  66.                         throw new ArgumentOutOfRangeException("amount", "Your daily maximun withdrawl is $300 dollars or less. Please enter a smaller amount");
  67.                     } else {
  68.                         m_balance -= amount;
  69.                         return false;
  70.                     }
  71.             }
  72.             return false;
  73.         }
  74.        
  75.     }
  76. }
  77. using System;
  78. using System.Collections.Generic;
  79. using System.Linq;
  80. using System.Text;
  81. using System.Threading.Tasks;
  82.  
  83. namespace Raber_assignment3 {
  84.     public class CheckingAccount : BankAccount,IPrintable{
  85.         public CheckingAccount() { }
  86.  
  87.         public CheckingAccount(string accountNum,string fName,string lName) : base(accountNum,fName,lName) {
  88.            
  89.         }
  90.  
  91.         enum CheckingAccountType {
  92.             Basic,
  93.             Premier
  94.         }
  95.  
  96.  
  97.  
  98.         public override string Owner {
  99.             get {
  100.                 return base.Owner;
  101.             }
  102.         }
  103.  
  104.         CheckingAccountType AccountType { get; set; }
  105.  
  106.         decimal OverDraftFee {
  107.             get {
  108.                 return 10m * numOverdrafts;
  109.             }
  110.         }
  111.  
  112.         private int numOverdrafts = 0;
  113.  
  114.         int NumberOfOverdrafts {
  115.             get {
  116.                 return numOverdrafts;
  117.             }
  118.         }
  119.  
  120.         public override bool WithdrawAmount(decimal amount,int? accountType=1) {
  121.             return base.WithdrawAmount(amount);
  122.  
  123.         }
  124.  
  125.         public string PrintStatement() {
  126.             string statement = $"Statement Date as of Today's Date for {Owner}.\n";
  127.             statement += $"Checking Account Balance is {Balance.ToString("c")}.\n";
  128.             statement += $"Amount of OverDraft fee for the month is {OverDraftFee.ToString("c")}\n";
  129.             statement += $"The number of overdrafts for the month is {NumberOfOverdrafts}";
  130.             return statement;
  131.  
  132.         }
  133.         public string ShowBallance() {
  134.             return $"Customer {Owner} has {Balance} in Checking Account";
  135.         }
  136.     }
  137. }
  138.  
  139. using System;
  140. using System.Collections.Generic;
  141. using System.Linq;
  142. using System.Text;
  143. using System.Threading.Tasks;
  144.  
  145. namespace Raber_assignment3 {
  146.     public class SavingsAccount : BankAccount, IPrintable {
  147.         const decimal INTREST = 0.02m;
  148.         const decimal BALANCE_CHECK = 100m;
  149.  
  150.         public SavingsAccount() { }
  151.         public SavingsAccount(string accountNum,string fName,string lName) : base(accountNum,fName,lName) {
  152.             this.AccountNum = accountNum;
  153.             this.FirstName = fName;
  154.             this.LastName = lName;
  155.          
  156.         }
  157.  
  158.         public override string Owner {
  159.             get {
  160.                 return $"Savings -- {base.Owner}";
  161.             }
  162.         }
  163.  
  164.         public decimal AddIntrest() {
  165.             if(m_balance > BALANCE_CHECK) {
  166.                 return m_balance * INTREST;
  167.             }else {
  168.                 return 0m;
  169.             }
  170.         }
  171.  
  172.         public string PrintStatement() {
  173.             string statement = $"Statement Date as of Today's date for {Owner}\n";
  174.             statement += $"Savings Account Balance is {Balance}\n";
  175.             statement += $"Intrest earned for the month is {AddIntrest()}\n";
  176.             statement += $"Total Savings Account balance including intrested earned is {AddIntrest() + m_balance}\n";
  177.             return statement;
  178.         }
  179.  
  180.         public string ShowBallance() {
  181.             return $"Customer {Owner} has {Balance.ToString("c")} in Savings Account";
  182.             //throw new NotImplementedException();
  183.         }
  184.     }
  185. }
  186. //Ben Raber
  187. //simulates an Atm part 1
  188. //Created 2-1-2017
  189.  
  190.  
  191. using System;
  192. using System.Collections.Generic;
  193. using System.ComponentModel;
  194. using System.Data;
  195. using System.Drawing;
  196. using System.Linq;
  197. using System.Text;
  198. using System.Threading.Tasks;
  199. using System.Windows.Forms;
  200.  
  201. namespace Raber_assignment3 {
  202.     public partial class Form1 : Form {
  203.  
  204.         /*
  205.          * Program specifications (business requirements):  Customer bank account
  206.          * Create a Windows application that shows a customer account information.
  207.          * This will be the Windows stub for the next couple of programming assignments.
  208.          * Remember to think about the programming process when developing your solution:
  209.          * INPUT
  210.          * PROCESS/LOGIC/COMPUTATION/ALGORITHM
  211.          * OUTPUT
  212.          * Program requirements:
  213.          * The Show Balance button should display a message box with an
  214.          * Information icon, message box title “Customer Balance” and the OK button with the following message:
  215.          * “Customer <<value from text box>> has $500 in the <<account combo value>> “.
  216.          *  The hard coded dollar value in the message box will remain the same.
  217.          *  The Welcome, Deposit, Withdrawal and Print Payment buttons should display the appropriate message
  218.          *  based on these buttons design constraints below.
  219.          *  The program should populate the accounts combo box with the following values of
  220.          *  Checking, Savings, Money Market, Certificate of Deposit showing the default value of
  221.          *  “---Select an Account Type—“.
  222.          *  The program should check to see if an account has been selected from the accounts dropdown list
  223.          *  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.
  224.          *  The Clear button clears all UI fields and resets the accounts combo box to the first item in the combo box.
  225.          *  The Exit button closes the application.
  226.  
  227.  
  228.  
  229.  
  230.  
  231. */
  232.         public Form1() {
  233.             InitializeComponent();
  234.  
  235.         }
  236.  
  237.         private CheckingAccount cAccount;
  238.         private SavingsAccount sAccount;
  239.  
  240.         private void PopulateCombo() {
  241.             cboAccount.Items.Add("--Select an Account--");
  242.             cboAccount.Items.Add("Checking");
  243.             cboAccount.Items.Add("Savings");
  244.             cboAccount.Items.Add("Money Market");
  245.             cboAccount.Items.Add("Certificate of Deposit");
  246.         }
  247.  
  248.  
  249.         private void ClearUI() {
  250.             cboAccount.SelectedIndex = 0;
  251.             txtDeposit.Clear();
  252.             txtFisrtName.Clear();
  253.             txtLastName.Clear();
  254.             txtWithdrawl.Clear();
  255.             grpCust.Enabled = true;
  256.             txtDeposit.Enabled = false;
  257.             txtFisrtName.Enabled = true;
  258.             txtLastName.Enabled = true;
  259.             txtWithdrawl.Enabled = false;
  260.             btnDeposit.Enabled = false;
  261.             btnWithdrawl.Enabled = false;
  262.             mtxtAccountNumber.Clear();
  263.         }
  264.  
  265.         private void MethodNotImplementedException() {
  266.             throw new NotImplementedException();
  267.         }
  268.         private void Form1_Load(object sender, EventArgs e) {
  269.             PopulateCombo();
  270.             btnDeposit.Enabled = false;
  271.             btnWithdrawl.Enabled = false;
  272.             btnBalance.Enabled = false;
  273.             btnPrintStatement.Enabled = false;
  274.             txtDeposit.Enabled = false;
  275.             txtWithdrawl.Enabled = false;
  276.             cboAccount.SelectedIndex = 0;
  277.            
  278.         }
  279.  
  280.         private void btnWelcome_Click(object sender, EventArgs e) {
  281.  
  282.             if (ValadateUI()) {
  283.                 grpCust.Enabled = false;
  284.                 grpTransaction.Enabled = true;
  285.                 btnDeposit.Enabled = true;
  286.                 btnWithdrawl.Enabled = true;
  287.                 btnBalance.Enabled = true;
  288.                 btnPrintStatement.Enabled = true;
  289.                 txtDeposit.Enabled = true;
  290.                 txtWithdrawl.Enabled = true;
  291.                 btnWelcome.Enabled = false;
  292.             }
  293.  
  294.  
  295.             /*try {
  296.                 MethodNotImplementedException();
  297.             }catch(NotImplementedException ex) {
  298.                 MessageBox.Show("Implementation is Pending", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
  299.             }*/
  300.  
  301.         }
  302. //I need cAccount to be Availible to both btnDeposit and btnWithdrawl_Click
  303. //I don't know how to do that h
  304.  
  305.         private void btnDeposit_Click(object sender, EventArgs e) {
  306.             if(txtDeposit.Text == String.Empty) {
  307.                 MessageBox.Show("Please enter an amount to Deposit in your account", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
  308.             }else {
  309.  
  310.             }
  311.  
  312.             /*try {
  313.                 MethodNotImplementedException();
  314.             } catch (NotImplementedException ex) {
  315.                 MessageBox.Show("Implementation is Pending", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
  316.             }*/
  317.         }
  318.  
  319.         private void btnWithdrawl_Click(object sender, EventArgs e) {
  320.             if (txtWithdrawl.Text == string.Empty) {
  321.                 MessageBox.Show("Please enter an amount to withdraw.", "Mearmac Online Banking System", MessageBoxButtons.OK, MessageBoxIcon.Error);
  322.             } else {
  323.                 switch (cboAccount.SelectedIndex) {
  324.                     case 0:
  325.                         break;
  326.                     case 1: //Checking Account
  327.                         cAccount = new CheckingAccount(mtxtAccountNumber.Text, txtFisrtName.Text, txtLastName.Text);
  328.                         decimal amount;
  329.                         bool result = decimal.TryParse(txtWithdrawl.Text, out amount);
  330.                         if (result) {
  331.                             cAccount.WithdrawAmount(amount);
  332.                         }
  333.                         break;
  334.                     case 2: //Savings Account
  335.                         sAccount = new SavingsAccount(mtxtAccountNumber.Text, txtFisrtName.Text, txtLastName.Text);
  336.                         result = decimal.TryParse(txtWithdrawl.Text, out amount);
  337.  
  338.                         if (result) {
  339.                             sAccount.WithdrawAmount(amount);
  340.                         }
  341.                         break;
  342.                 }
  343.  
  344.                 /*try {
  345.                     MethodNotImplementedException();
  346.                 } catch (NotImplementedException ex) {
  347.                     MessageBox.Show("Implementation is Pending", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
  348.                 }
  349.                 */
  350.             }
  351.         }
  352.  
  353.         private bool ValadateUI() {
  354.             if (cboAccount.SelectedIndex == -1) {
  355.                 MessageBox.Show("Please select an Account Type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  356.                 return false;
  357.             }
  358.             if (!(mtxtAccountNumber.MaskFull)) {
  359.                 MessageBox.Show("Please enter an account ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  360.                 return false;
  361.             }
  362.             if(txtFisrtName.Text == String.Empty) {
  363.                 MessageBox.Show("Customer 1st name is Blank", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  364.                 return false;
  365.             }
  366.             if(txtLastName.Text == String.Empty) {
  367.                 MessageBox.Show("Customer last name is Blank", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  368.                 return false;
  369.             }
  370.             return true;
  371.  
  372.         }
  373.  
  374.  
  375.  
  376.         private void btnBalance_Click(object sender, EventArgs e) {
  377.             //bool allValidationPassed = false;
  378.             if (ValadateUI()) {
  379.                 MessageBox.Show($"{txtFisrtName.Text} {txtLastName.Text} has $500 in {cboAccount.SelectedItem.ToString()}");
  380.             }
  381.         }
  382.  
  383.         private void btnPrintStatement_Click(object sender, EventArgs e) {
  384.             switch (cboAccount.SelectedIndex) {
  385.                 case 0:
  386.                     break;
  387.                 case 1:
  388.                     //Checking Account
  389.                     cAccount.PrintStatement();
  390.                     break;
  391.                 case 2:
  392.                     sAccount.PrintStatement();
  393.                     break;
  394.             }
  395.  
  396.             /*try {
  397.                 MethodNotImplementedException();
  398.             } catch (NotImplementedException ex) {
  399.                 MessageBox.Show("Implementation is Pending", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
  400.             }*/
  401.         }
  402.  
  403.         private void btnExit_Click(object sender, EventArgs e) {
  404.             this.Close();
  405.             Application.Exit();
  406.         }
  407.  
  408.         private void btnClear_Click(object sender, EventArgs e) {
  409.             ClearUI();
  410.         }
  411.     }
  412. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement