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

I need a tutorial on how to do the following: Using C#, create a Windows Present

ID: 3692225 • Letter: I

Question

I need a tutorial on how to do the following:

Using C#, create a Windows Presentation Foundation (WPF) application that accepts the total cost of a sale and the amount submitted by the customer. Calculate and display the correct change. If the cost exceeds the amount submitted, post a message to the user that they have not submitted enough money. The program should accept both the cost and the amount submitted and then calculate and display the results. The program should use Try/Catch statements to keep the program from crashing. The windows presentation foundation application should look like the following:

I need you to explain to me how to do everything, including creating the actual form itself and how to link the code, or post a link to an uploaded solution. Thank you!

Explanation / Answer

Ans;

.xmal source code

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Calculate change" Height="350" Width="525">
<Grid>
<Label Content="Enter Amount" HorizontalAlignment="Left" Margin="117,51,0,0" VerticalAlignment="Top"/>
<Label Content="Total Cost" HorizontalAlignment="Left" Margin="117,82,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="textAmount" HorizontalAlignment="Left" Height="23" Margin="225,51,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" PreviewTextInput="AmountTextInputHandler"
DataObject.Pasting="AmountHandler" />
<TextBox x:Name="textCost" HorizontalAlignment="Left" Height="23" Margin="225,85,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" PreviewTextInput="CostTextInputHandler"
DataObject.Pasting="CostHandler" />
<Label Content="Correct Change" HorizontalAlignment="Left" Margin="117,132,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="textChange" HorizontalAlignment="Left" Height="23" Margin="225,132,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" IsReadOnly="True"/>
<Button x:Name="btnCalculate" Content="Calculate" HorizontalAlignment="Left" Margin="225,183,0,0" VerticalAlignment="Top" Width="75" Click="btnCalculate_Click_1"/>

</Grid>
</Window>

.cs source code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btnCalculate_Click_1(object sender, RoutedEventArgs e)   
{
try
{
if (textAmount.Text =="")
{
MessageBox.Show("Please enter amount");
textAmount.Focus();
return;
}
if (textCost.Text=="")
{
MessageBox.Show("Please enter cost");
textCost.Focus();
return;
}
else
{
double amount = Convert.ToDouble(textAmount.Text);
double Cost = Convert.ToDouble(textCost.Text);
if (Cost < amount)
{
double totalCharge = amount - Cost;
textChange.Text = totalCharge.ToString();
}
else
{
MessageBox.Show("You have not submitted enough money");
textCost.Focus();
}
}

}
catch (Exception EX)
{

MessageBox.Show(EX.InnerException.ToString());
}
  
}
private void AmountTextInputHandler(Object sender, TextCompositionEventArgs e)
{
e.Handled = !IsTextAllowed(e.Text);
}   
private void AmountHandler(object sender, DataObjectPastingEventArgs e)
{
if (e.DataObject.GetDataPresent(typeof(String)))
{
String text = (String)e.DataObject.GetData(typeof(String));
if (!IsTextAllowed(text)) e.CancelCommand();
}
else e.CancelCommand();
}
private void CostTextInputHandler(Object sender, TextCompositionEventArgs e)
{
e.Handled = !IsTextAllowed(e.Text);
}   
private void CostHandler(object sender, DataObjectPastingEventArgs e)
{
if (e.DataObject.GetDataPresent(typeof(String)))
{
String text = (String)e.DataObject.GetData(typeof(String));
if (!IsTextAllowed(text)) e.CancelCommand();
}
else e.CancelCommand();
}
private Boolean IsTextAllowed(String text)
{
return Array.TrueForAll<Char>(text.ToCharArray(),
delegate(Char c) { return Char.IsDigit(c) || Char.IsControl(c); });
}
}
}

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