Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Total beginner in C# and Visual Studios and Windows Forms. I don\'t have issues

ID: 3920199 • Letter: T

Question

Total beginner in C# and Visual Studios and Windows Forms. I don't have issues designing the forms themselves but am struggling with coding the event handlers for control buttons using C#. Please leave comments with the code to help me understand the process. Here are the text box names and button names:

Text box names/variables: txtSingles, txtAlbums, txtSubtotal, txtTax, txtShipping, txtTotalDue.

Constants- singles cost($12.98), albums cost($20.98), shipping cost for singles($1.00), shipping cost for albums($1.50), tax rate(6.25%)

GroupText box names: txtTotalOrders, txtOrdersTotalDue, txtSmallestOrder, txtAverageOrder, txtLargestOrder.

Control Button names: btnCalculate, btnClear, btnExit, btnResetTotals

The following button control event handlers information:

Calculate button (btnCalculate):

if user doesn't want to order and Albums/Singles they should enter a zero.

Only after valid values are attained: Sub total should be calculated as follows:

       Number of Singles ordered   *$12.98 = charge for singles

       Number of Albums ordered   *$20.98 = charge for albums

       Charge of singles + charge of albums = sub total

       Sub total should display as deciimal number with 2 decimal positions.

      Tax rate of 6.25% should be applied to sub total and round to the nearest cent and be displayed as a       decimal with 2 decimal places.

   Cost of shipping should be calculated as:

            Number of singles ordered   * $1.00 = shipping for singles

            Number of albums ordered * $1.50 = shipping for albums

            shipping for singles + shipping for albums = total shipping //display as decimal with 2 decimal positions.

            total should refelct accumulation of sub total, tax, and shipping //display as decimal with 2 position

In addition to calculating the total due for transaction, total transaction counter should be incremented to show total number of orders for this session, also accumulate all total due by adding total due for this order to total due for all orders. Average order placed should be calculated as total due for all orders divided by total orders(average should be rounded to nearest cent). Display as follows:

              Total number of orders as a whole number

              total due for all orders as dollar amount with 2 decimal places

              average order as a dollar amount with 2 decimal places

Determine smalles invoice total and largest invoice total and display amount as currency.

Focus should return to the txtSingles box

Clear Button (btnClear):

all text box values (excluding the totals Group Box) should be removed and set focus back to txtSingles

Reset Totals button (btnResetTotals):

reset totals for the sessions. txtTotalOrders, txtOrdersTotalDue, txtSmallestOrder, txtAverageOrder, txtLargestOrder should be cleared and accumulators reset to their initial values. Focus return to txtSingle and entry should be highlighted or selected.

Thank you so much for the help.

Order Total Vinyl by Linyl Inu Totals Number of Singles: Total Orders: Number of Albums: Total Due: Smallest Order Average Order: Largest Order: Subtotal: Tax: Shipping Charge: Total Due: Reset Totals Calculate Total Clear Exit

Explanation / Answer

private static int totalOrders = 0;

private static double totalDueOverall = 0;

private static double smallestOrderAmnt = 0;

private static double largestOrderAmnt = 0;

private void Calculate()

{

int singlesCount = Convert.ToInt32(txtSingles.Text);

int albumsCount = Convert.ToInt32(txtAlbums.Text);

double singlesAmnt = singlesCount * 12.98;

double albumsAmnt = albumsCount * 20.98;

double subTotal = singlesAmnt + albumsAmnt;

// Assign value to sub total text box

subTotal = Math.Round(subTotal, 2);

txtSubtotal.Text = subTotal.ToString();

double tax = (subTotal * 6.25) / 100;

tax = Math.Round(tax, 2);

txtTax.Text = tax.ToString();

double shpCharge = (singlesCount * 1) + (albumsCount * 1.5);

shpCharge = Math.Round(shpCharge, 2);

txtShipping.Text = shpCharge.ToString();

double totalDue = subTotal + tax + shpCharge;

totalDue = Math.Round(totalDue, 2);

txtTotalDue.Text = totalDue.ToString();

if(totalOrders == 0)

{

smallestOrderAmnt = totalDue;

largestOrderAmnt = totalDue;

}

totalOrders++;

totalDueOverall += totalDue;

if(totalDue < smallestOrderAmnt)

{

smallestOrderAmnt = totalDue;

}

if(totalDue > largestOrderAmnt)

{

largestOrderAmnt = totalDue;

}

txtTotalOrders.Text = totalOrders.ToString();

txtOrdersTotalDue = totalDueOverall.ToString();

txtSmallestOrder.Text = smallestOrderAmnt.ToString();

txtAverageOrder.Text = totalOrders == 0 ? "0" : (totalDueOverall / totalOrders).ToString();

txtLargestOrder.Text = largestOrderAmnt.ToString();

txtSingles.Focus();

}

private void Clear()

{

txtSingles.Text = string.Empty;

txtAlbums.Text = string.Empty;

txtSubtotal.Text = string.Empty;

txtTax.Text = string.Empty;

txtShipping.Text = string.Empty;

txtTotalDue.Text = string.Empty;

txtSingles.Focus();

}

private void Reset()

{

txtTotalOrders.Text = string.Empty;

txtOrdersTotalDue.Text = string.Empty;

txtSmallestOrder.Text = string.Empty;

txtAverageOrder.Text = string.Empty;

txtLargestOrder.Text = string.Empty;

totalOrders = 0;

totalDueOverall = 0;

smallestOrderAmnt = 0;

largestOrderAmnt = 0;

txtSingles.Focus();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote