Question
Here is the existing code from the invoiceTotal Application: 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;
Here is the existing code from the invoiceTotal Application:
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 InvoiceTotal
{
public partial class frmInvoiceTotal : Form
{
public frmInvoiceTotal()
{
InitializeComponent();
}
// TODO: declare class variables for array and list here
private void btnCalculate_Click(object sender, EventArgs e)
{
try
{
if (txtSubtotal.Text == "")
{
MessageBox.Show(
"Subtotal is a required field.", "Entry Error");
}
else
{
decimal subtotal = Decimal.Parse(txtSubtotal.Text);
if (subtotal > 0 && subtotal
{
decimal discountPercent = 0m;
if (subtotal >= 500)
discountPercent = .2m;
else if (subtotal >= 250 & subtotal
discountPercent = .15m;
else if (subtotal >= 100 & subtotal
discountPercent = .1m;
decimal discountAmount = subtotal * discountPercent;
decimal invoiceTotal = subtotal - discountAmount;
discountAmount = Math.Round(discountAmount, 2);
invoiceTotal = Math.Round(invoiceTotal, 2);
txtDiscountPercent.Text = discountPercent.ToString("p1");
txtDiscountAmount.Text = discountAmount.ToString();
txtTotal.Text = invoiceTotal.ToString();
}
else
{
MessageBox.Show(
"Subtotal must be greater than 0 and less than 10,000.",
"Entry Error");
}
}
}
catch (FormatException)
{
MessageBox.Show(
"Please enter a valid number for the Subtotal field.",
"Entry Error");
}
txtSubtotal.Focus();
}
private void btnExit_Click(object sender, EventArgs e)
{
// TODO: add code that displays dialog boxes here
this.Close();
}
}
}
Chapter 8 How to use arrays and collections 257 xercise 8-1 Use an array and a list This exercise will guide you through the process of adding an array and a list to the Invoice Total application that you enhanced in the last chapter Open the Invoice Total application I, Open the Invoice Total application that's in the CNC# 2015,Chapter 081 Invoice Total directory. Use an array to store invoice totals 2. Declare two class variables: (1) an array that can hold up to five invoice totals and (2) an index that you can use to work with that array. Add code that adds the invoice total to the next element in the array each time the user clicks the Calculate button. Add code that displays all the invoice totals in the array in a message box when the user clicks the Exit button. To do that, use a foreach loop to loop through the totals and format the message for the message box. Within this loop, you should include an if statement so you only display totals that are not equal to zero. Test the program by entering subtotals for up to five invoices and then clicking the Exit button. This should display a dialog box like this one: 3. 4. 5. Order Totals $90.00 5180.00 $255.00 OK Test the program by entering more than five invoices. When you do, an IndexOutOfRangeException should be thrown. Then, modify the try-catch statement so it handles this exception. 6. Sort the invoice totals 7. Add code to sort the invoice totals in the array. Test the program again to be sure that the message box displays the invoice totals in the correct sequence lodify the program so it uses a list 9. Without changing any of the current code, repeat steps 2 through 8 but use a list to hold the totals and add a second foreach loop to format and display the totals stored in the list in a second message box. In other words, display two message boxes: one for the array and one for the list. hen you've got this working right, close the solution. Chapter 8 How to use arrays and collections 257 xercise 8-1 Use an array and a list This exercise will guide you through the process of adding an array and a list to the Invoice Total application that you enhanced in the last chapter Open the Invoice Total application I, Open the Invoice Total application that's in the CNC# 2015,Chapter 081 Invoice Total directory. Use an array to store invoice totals 2. Declare two class variables: (1) an array that can hold up to five invoice totals and (2) an index that you can use to work with that array. Add code that adds the invoice total to the next element in the array each time the user clicks the Calculate button. Add code that displays all the invoice totals in the array in a message box when the user clicks the Exit button. To do that, use a foreach loop to loop through the totals and format the message for the message box. Within this loop, you should include an if statement so you only display totals that are not equal to zero. Test the program by entering subtotals for up to five invoices and then clicking the Exit button. This should display a dialog box like this one: 3. 4. 5. Order Totals $90.00 5180.00 $255.00 OK Test the program by entering more than five invoices. When you do, an IndexOutOfRangeException should be thrown. Then, modify the try-catch statement so it handles this exception. 6. Sort the invoice totals 7. Add code to sort the invoice totals in the array. Test the program again to be sure that the message box displays the invoice totals in the correct sequence lodify the program so it uses a list 9. Without changing any of the current code, repeat steps 2 through 8 but use a list to hold the totals and add a second foreach loop to format and display the totals stored in the list in a second message box. In other words, display two message boxes: one for the array and one for the list. hen you've got this working right, close the solutionStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started