Write a C# ATM program using a class for account which must have a name (get thi
ID: 670041 • Letter: W
Question
Write a C# ATM program using a class for account which must have a name (get this from the user), an account # (assigned by you the first time the account name is entered) and a balance. You must search the accounts array to see if the name entered is the same as a previous one and update that balance. You can assume that a new account balance is $100.00. You will need get/set methods for all the attributes. You should loop through multiple transactions until a user opts to logout (ie return to the “enter account name menu”). You will also need one array of transactions for each account# that will record each transaction that is completed for that account. The application must be a GUI. I am having a really hard time making this. If anyone could help me I would appreciate it.
Explanation / Answer
Account.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApplication1
{
public class Account
{
public string name { get; set; }
public static int accountNumbers = 100001;
public int number;
public double balance { get; set; }
public Account(string name)
{
number = accountNumbers;
this.name = name;
balance = 100;
accountNumbers += 1;
}
public override string ToString()
{
return "Name: " + name + ", " + "Acc. No: " + number;
}
}
}
_________________________________________________________________________________________
Details.xaml:
<Window x:Class="WpfApplication1.Details"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Details" Height="300" Width="300">
<Grid>
<Label Content="Account Name:" HorizontalAlignment="Left" Margin="52,57,0,0" VerticalAlignment="Top" Width="102"/>
<Label Content="Account Number:" HorizontalAlignment="Left" Margin="53,83,0,0" VerticalAlignment="Top" Width="101"/>
<Label Content="Balance:" HorizontalAlignment="Left" Margin="53,109,0,0" VerticalAlignment="Top" Width="101"/>
<Label Name="name" Content="" HorizontalAlignment="Left" Margin="159,57,0,0" VerticalAlignment="Top" Width="102"/>
<Label Name="number" Content="" HorizontalAlignment="Left" Margin="159,83,0,0" VerticalAlignment="Top" Width="102"/>
<Label Name="balance" Content="" HorizontalAlignment="Left" Margin="159,109,0,0" VerticalAlignment="Top" Width="102"/>
<Label Content="Deposit:" HorizontalAlignment="Left" Margin="53,175,0,0" VerticalAlignment="Top" Width="101"/>
<Label Content="Withdraw:" HorizontalAlignment="Left" Margin="53,206,0,0" VerticalAlignment="Top" Width="101"/>
<TextBox Name="deposit" HorizontalAlignment="Left" Height="23" Margin="128,179,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" KeyDown="Deposit_TextBox_KeyDown"/>
<TextBox Name="withdraw" HorizontalAlignment="Left" Height="23" Margin="128,206,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" KeyDown="Withdraw_TextBox_KeyDown"/>
<Button Content="Logout" HorizontalAlignment="Left" Margin="102,237,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Grid>
</Window>
________________________________________________________________________________________
Details.xaml.cs:
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.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Details.xaml
/// </summary>
public partial class Details : Window
{
Account account;
public Details(Account account)
{
InitializeComponent();
this.account = account;
name.Content = account.name;
number.Content = account.number;
balance.Content = account.balance;
}
private void Deposit_TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
account.balance += Convert.ToDouble(deposit.Text);
deposit.Text = "";
}
balance.Content = account.balance;
}
private void Withdraw_TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
account.balance -= Convert.ToDouble(withdraw.Text);
withdraw.Text = "";
}
balance.Content = account.balance;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
________________________________________________________________________________________
DetailsWindow.xaml:
<Window x:Class="WpfApplication1.DetailsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DetailsWindow" Height="300" Width="300">
<Grid>
<Label Name="label" Content="" HorizontalAlignment="Left" Margin="10,70,-18,0" VerticalAlignment="Top" Width="250"/>
<TextBox Name="textBox" HorizontalAlignment="Left" Height="23" Margin="31,123,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="137" RenderTransformOrigin="0.835,0.855"/>
<Button Name="button" Content="Submit" HorizontalAlignment="Left" Margin="72,169,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
</Grid>
</Window>
________________________________________________________________________________________
DetailsWindow.xaml.cs:
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.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for DetailsWindow.xaml
/// </summary>
public partial class DetailsWindow : Window
{
public DetailsWindow(string labelContent)
{
InitializeComponent();
label.Content = labelContent;
}
private void button_Click(object sender, RoutedEventArgs e)
{
MainWindow.detail = textBox.Text;
this.Close();
}
}
}
__________________________________________________________________________________________
MainWindow.xaml:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<DockPanel>
<Button Name="login" DockPanel.Dock="Top" Content="Login" Width="200" Click="login_Click"></Button>
<ListView Name="accountsList"></ListView>
</DockPanel>
</Window>
_________________________________________________________________________________________
MainWindow.xaml.cs:
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 static string detail;
List<Account> accounts;
public MainWindow()
{
InitializeComponent();
accounts = new List<Account>();
new DetailsWindow("Number of accounts").ShowDialog();
int num = Convert.ToInt16(detail);
for (int i = 0; i < num; ++i)
{
new DetailsWindow("Account Name(#" + Account.accountNumbers + ")").ShowDialog();
accounts.Add(new Account(detail));
}
accountsList.ItemsSource = accounts;
}
private void login_Click(object sender, RoutedEventArgs e)
{
foreach (Account acc in accounts)
{
new DetailsWindow("Account Name for login").ShowDialog();
if (acc.name == detail)
{
new Details(acc).ShowDialog();
accountsList.ItemsSource = accounts;
break;
}
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.