System Background
A company approached you to develop a Software Application to handle transactions performed by a user on their accounts. Each user has a balance that indicates the current amount of money in the account. The following transaction operations can be performed by a user:
System Requirements
The company asked you to develop a C# Console Application prototype to simulate the transactions for one user.
This user should have an initial (hard-coded) balance of R 10 000.00
The user should be presented with the following options to choose a specific transaction that needs to be performed:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Q200414
{
class Program
{
class Account
{
private double balance;
//property
public double Balance
{
get { return balance; }
set { balance = value; }
}
/// <summary>
/// Constructor
/// </summary>
public Account()
{
this.balance = 10000.00;
}
/// <summary>
/// Deposit amount
/// </summary>
/// <param name="amount"></param>
public void Deposit(double amount)
{
if (amount > 0)
{
this.balance += amount;
Console.WriteLine("\nThe amount has been deposited.\n");
}
else
{
Console.WriteLine("\nThe amount is negative.\n");
}
}
/// <summary>
/// Withdraw amount
/// </summary>
/// <param name="amount"></param>
public void Withdraw(double amount)
{
if (this.balance >= amount)
{
this.balance -= amount;
Console.WriteLine("\nThe amount has been withdrawed.\n");
}
else
{
Console.WriteLine("\nBalance < amount\n");
}
}
}
static void Main(string[] args)
{
int ch = -1;
Account account = new Account();
while (ch != 4)
{
Console.WriteLine("1. Deposit an amount into the account.");
Console.WriteLine("2. Withdraw an amount from the account.");
Console.WriteLine("3. View the current balance of the account.");
Console.WriteLine("4. Cancel a transaction.");
Console.Write("> ");
ch = int.Parse(Console.ReadLine());
switch (ch)
{
case 1:
{
//Deposit an amount into the account
Console.Write("Enter the amount to deposit: ");
double amount = double.Parse(Console.ReadLine());
account.Deposit(amount);
}
break;
case 2:
{
//Withdraw an amount from the account
Console.Write("Enter the amount to withdraw: ");
double amount = double.Parse(Console.ReadLine());
account.Withdraw(amount);
}
break;
case 3:
{
//View the current balance of the account
Console.WriteLine("\nThe current balance of the account {0}\n", account.Balance);
}
break;
case 4:
{
//exit
}
break;
}
}
}
}
}
Comments
Leave a comment