Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a C# programming class using Visual Studio and Windows forms. My assignment instructions appear below, and a photo of the form and the

This is a C# programming class using Visual Studio and Windows forms. My assignment instructions appear below, and a photo of the form and the code I have completed so far is attached. I would like feedback on how to store the struct properties in the array (it's one-dimensional) and then use the array to populate the list box.             This pair-programming assignment takes the checking account project and uses a structure and an array to store the data. Your project will use a single form.        Requirements        1. Code a structure called Transaction. Typically, a transaction includes the following data: TransactionDate, Transaction Type, Transaction Amount, Payee, and Check Number. Therefore, your Transactionstructure should have the following data members:        TransactionDate,        TransactionType,        TransactionAmount,        Payee, and        CheckNumber.        2. Include a ToString method that returns the transaction date, type of transaction, and transaction amount as a concatenated string, similar to the following:        "07/02/2003 Deposit $500.00".        3.  A form with the following:        An array based on the Transaction structure with 20 elements.        A decimal variable to hold the account balance.        Controls for entering data about each transaction.        A listbox showing all transactions. When the user clicks on an item in the list box, information aboutthat transaction should be displayed in the appropriate controls.        Include a label for displaying the account balance.        Notify the user if the account is Overdrawn (either by color, label, or messagebox).        A button to add a new transaction, display information in the listbox, and update the account balance label.        A button to clear controls for entering a new transaction.        A button to exit the application.        4. Include the following validation:        The transaction amount must be a positive number.    The transaction date must be readable as a date.    Each transaction must have a transaction type specified (deposit, service fee, withdrawal).    If a transaction is a withdrawal, an entry for payee is required.    EXTRA CREDIT (10 points)    Add a button to remove a transaction from the listbox and the array; make sure to display the revised account balance.                 Code: (I've commented out some things I've tried that haven't worked.)        using System.Runtime.CompilerServices;    using System.Transactions;    using System.Web;    using System.Windows.Forms;    namespace PPBasicCheckingAcount    {       //Program calculates current balance of checking account when user enters a transaction       public partial class FrmBasicChecking : Form       {                  public FrmBasicChecking()           {               InitializeComponent();           }                      //variable to store current balance           decimal balance = 0.0m;           int counter = 0;           public struct Transaction           {               public string type;               public decimal amount;               public DateTime date;               public string payee;               public int checkNumber;               public string ToString(string sep)               {                   //string transactionListItem = (type + amount + date.ToString("d"));                   string line = string.Format("{0,-20} {1,-20:C}{ 2, -20}", type, amount, date.ToString("d"));                   return line;                   //          return date.ToString("d") + sep + type + sep + amount.ToString("c");               }           }           Transaction[] transactionsArray = new Transaction[20];               //Displays the current balance in the label           private void DisplayCurrentBalance()           {               lblCurrentBalance.Text = balance.ToString("c");           }           //Displays zero current balance on the form load           private void FrmBasicChecking_Load(object sender, EventArgs e)           {               DisplayCurrentBalance();               txtDate.Text = DateTime.Now.ToString("d");                        }           //Calculates the new current balance when a transaction is entered           private void btnCalculate_Click(object sender, EventArgs e)           {               //If all entries are valid               if (IsValidEntry())               {                   Transaction transaction = new Transaction();                   //convert amount from string to decimal                   decimal amount = Convert.ToDecimal(txtAmount.Text);                   //declare and initialize type textbox                   string type = txtType.Text;                   //declare date string variable and convert to date                   DateTime date = Convert.ToDateTime(txtDate.Text);                   //Add transaction amount to current balance if type is deposit                   if (type.Equals("deposit", StringComparison.CurrentCultureIgnoreCase))                   {                       //increment balance                       balance += amount;                       counter++;                       //display new balance                       lblCurrentBalance.Text = balance.ToString("c");                       transaction.date = date;                       transaction.amount = amount;                       transaction.type = type;                       transaction.payee = txtPayee.Text;                       transaction.checkNumber = Int32.Parse(txtCheckNumber.Text);                       FillListBox();                       }                   //if transaction is withdrawal or service fee, subtract amount from current balance                   else if ((type.Equals("withdrawal", StringComparison.CurrentCultureIgnoreCase)))                     //  || (type.Equals("service fee", StringComparison.CurrentCultureIgnoreCase)))                   {                       //check if amount will overdraw balance                       if ((amount <= balance) && (txtPayee.Text != ""))                       {                           //subtract amount from balance                           balance -= amount;                           //display new balance                           lblCurrentBalance.Text = balance.ToString("c");                       }                    }                   else if (type.Equals("service fee", StringComparison.CurrentCultureIgnoreCase))                   {                       if ((amount <= balance))                       {                           //subtract amount from balance                           balance -= amount;                           //display new balance                           lblCurrentBalance.Text = balance.ToString("c");                       }                       //if addition or subtraction not performed, display error message                       else                       {                           MessageBox.Show("Account is overdrawn", "Warning!");                       }                   }                   }               }               //Method validates all entries and displays appropriate error messages               public bool IsValidEntry()               {               return                   //validate amount textbox has entry                   IsPresent(txtAmount, "Transaction Amount ") &&                   //validate decimal number                   IsDecimal(txtAmount, "Transaction Amount ", 1) &&                   //validate type textbox has entry                   IsPresent(txtType, "Transaction Type ") &&                   //validate transaction type                   IsCorrectType(txtType, "Transaction Type ") &&                   //validate transaction date text box has entry                   IsPresent(txtDate, "Transaction Date ") &&                   //validate the date                   IsDate(txtDate, "Transaction Date ") &&                   IsPresent(txtPayee, "Payee ");                          }               //Method validates all textboxes have an entry               public bool IsPresent(TextBox textBox, string name)               {                   //if textbox is empty                   if (textBox.Text == "")                   {                       //return an error message                       MessageBox.Show(name + "is a required field.", "Entry Error");                       return false;                   }                   return true;               }               //Method validates decimal number in textbox               private bool IsDecimal(TextBox txtAmount, string name, decimal amount)               {                   //parse string to decimal and display error message if the amount is not a decimal or less than zero                   if (decimal.TryParse(txtAmount.Text, out amount) == false || amount < 0)                   {                       MessageBox.Show(name + "must be a positive number.", "Entry Error");                       txtAmount.Focus();                       return false;                   }                   return true;               }               //validates type texbox for correct entry               private bool IsCorrectType(TextBox textbox, string name)               {                   //declare and initialize type to type textbox                   string type = txtType.Text;                   //if transaction type is not deposit, withdrawal, or service fee                   if ((type != "deposit") &&                       (type != "withdrawal") &&                       (type != "service fee"))                   //display error message                    {                       MessageBox.Show(name + "must be deposit, withdrawal or service fee.", "Entry Error");                       txtType.Focus();                       return false;                   }                   return true;               }               //Validate date is an actual date and check if date is no later than today's date               private bool IsDate(TextBox textbox, string name)               {                   //declare date variable                   DateTime date;                   DateTime.Now.ToString("m/d/yy");                   //convert string date to datetime and check if date is later than today's date                   if (DateTime.TryParse(txtDate.Text, out date)                       == false || date > DateTime.Now)                   {                       //display error message                       MessageBox.Show("Transaction date must be today or earlier.", "Entry Error");                       txtDate.Focus();                       return false;                   }                   return true;               }        /*       private bool IsInt32(TextBox txtCheckNumber, string name, int checkNumber)           {               //parse string to int and display error message if the amount is not a integer               if (Int32.TryParse(txtAmount.Text, out checkNumber))               {                   MessageBox.Show(name + "must be a number.", "Entry Error");                   txtAmount.Focus();                   return false;               }               return true;           }        */           private void FillListBox()               {                   transactionsArray[0].type = txtType.Text;                   transactionsArray[0].amount = Convert.ToDecimal(txtAmount.Text);                   transactionsArray[0].date = DateTime.Parse(txtDate.Text);                   /*                               lstTransactions.Items.Add(transaction);                               lstTransactions.SelectedIndex = 0;                               lstTransactions.Items.Add(txtDate.Text);                               lstTransactions.Items.Add(txtType.Text);                               lstTransactions.Items.Add(txtAmount.Text);*/                   for (int i = 0; i < 20; i++)                   {                       lstTransactions.Items.Add(transactionsArray[i]);                       lstTransactions.Items.Add(i.ToString("\t"));                   }                   //    foreach (Transaction i in transactionsArray)                   {                       //   lstTransactions.Items.Add(transactionsArray[i].ToString()); doesn't work but makes sense                       //  lstTransactions.Items.Add(i.ToString("\t"));                       }               }               //Clear the text boxes               private void btnClear_Click(object sender, EventArgs e)               {                   txtAmount.Text = "";                   txtType.Text = "";                   txtDate.Text = "";                   txtCheckNumber.Text = "";                   txtPayee.Text = "";               }               //Reset the balance               private void btnReset_Click(object sender, EventArgs e)               {                   balance = 0.0m;                   DisplayCurrentBalance();               }               //Method exits the form               private void btnExit_Click(object sender, EventArgs e)               {                   this.Close();               }           }       }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

a To find the value of the coefficient of restitution e we can use the formula e v2final v1final v1initial v2initial Given Particle A mass mA 4 kg Par... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

How is a two - dimensional array mapped in memory?

Answered: 1 week ago

Question

What percent is $1.50 of $11.50?

Answered: 1 week ago