Answer to Question #200415 in C# for Pule Mokone

Question #200415





  • Question 1 of 2  
  •  Moving to another question will save this response.

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:

 

  • Deposit an amount into the account.
  • Withdraw an amount from the account.
  • View the current balance of the account.
  • Cancel a transaction.

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:




1
Expert's answer
2021-05-30T07:10:49-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q200415
{
    class Program
    {
        class Account
        {
            private double balance;


            public Account(double amt)
            {
                balance = amt;
            }


            public void Deposit(double amt)
            {
                balance += amt;
                Console.WriteLine("The amount has been deposited.");


            }


            public void Withdraw(double amt)
            {
                balance -= amt;
                Console.WriteLine("The amount has been withdrawed.");
            }


            public void displayCurrentBalance()
            {
                Console.WriteLine("The current balance of the account is: R{0}", balance);
            }
        }


        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int userChoice = -1;
            double amt;
            Account userAccount = new Account(10000.00);
            while (userChoice != 4)
            {
                //Main menu
                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("Your choice: ");
                userChoice = int.Parse(Console.ReadLine());
                //Deposit an amount into the account
                if (userChoice == 1)
                {
                    Console.Write("Enter the amount to deposit: ");
                    double.TryParse(Console.ReadLine(), out amt);
                    userAccount.Deposit(amt);
                }
                else if (userChoice == 2)//Withdraw an amount from the account.
                {
                    Console.Write("Enter the amount to withdraw: ");
                    double.TryParse(Console.ReadLine(), out amt);
                    userAccount.Withdraw(amt);
                }
                else if (userChoice == 3)//View the current balance of the account
                {
                    userAccount.displayCurrentBalance();
                }
                else if (userChoice == 4)
                {
                    //Cancel a transaction
                }
                else
                {
                    Console.WriteLine("Wrong menu item.");
                }
            }
        }
    }
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS