Do the following tasks:

Task 1
Create an enumerated type named AccountType for representing different types of bank accounts (checking and savings). You will create two variables by using this enum type, and set the values of the variables to Checking and Deposit.


Task 2
Design a class named BankAccount that includes the following members:
• A string value contains account number.
• A decimal value contains account balance.
• An AccountType variable contains account type. AccountType is enumeration that is defined in the previous task.
• Populate() method to set value for each instance variable. This method will return void and expect two parameters: a string (the account number) and a decimal (the account balance). The accType field will be set to AccountType.Checking.
• Properties to get value of each instance variable.
• Withdraw() method will take a decimal parameter and will deduct the given amount from the balance. However, it will check first to ensure that sufficient funds are available, since accounts are not allowed to become overdrawn. It will return a bool value indicating whether the withdrawal was successful.
• Deposit() method will also take a decimal parameter whose value it will add to the balance in the account. It will return the new value of the balance.

Task 3
Create a class named CreateAccount that includes the following static methods:
• NewBankAccount() returns a new instance of BankAccount class. The method will write a prompt to the console prompting the user for the account number and account balance, and then call the Populate() method, passing the account number and account balance as arguments.
• Write() displays information of a BankAccount object. This method will return void and expect one parameter: a BankAccount object.
• TestWithdraw() returns void and expect a BankAccount parameter. The method will write a prompt to the console prompting the user for the amount to withdraw, capture the entered value amount as a decimal, and then call the Withdraw() method on the BankAccount parameter, passing the amount as an argument. The method will capture the bool result returned by Withdraw and write a message to the console if the withdrawal failed.
• TestDeposit() returns void and expect a BankAccount parameter. The method will write a prompt to the console prompting the user for the amount to deposit, capture the entered amount as a decimal, and then call the Deposit() method on the BankAccount parameter, passing the amount as an argument.

Using the following Main() method to test your tasks.
BankAccount berts = CreateAccount.NewBankAccount();
CreateAccount.Write(berts);
Console.WriteLine();
CreateAccount.TestDeposit(berts);
CreateAccount.TestWithdraw(berts);
Console.ReadLine();


Thanks so much !

Dani AI

Generated

A compact, correct implementation that finishes Tasks 1–3 and builds on ’s skeleton. The code below focuses on safe input parsing, clear property accessors, and simple guards (no negative deposits/withdrawals, withdrawal checks for sufficient funds). and were right to recommend breaking the work into small parts; this is a complete example of those parts wired together.

using System;

enum AccountType { Checking, Savings }

class BankAccount
{
    private string accountNumber;
    private decimal balance;
    private AccountType accType;

    public void Populate(string number, decimal amount)
    {
        if (string.IsNullOrWhiteSpace(number)) throw new ArgumentException("Account number required");
        accountNumber = number;
        balance = amount;
        accType = AccountType.Checking;
    }

    public string AccountNumber { get { return accountNumber; } }
    public decimal Balance { get { return balance; } }
    public AccountType Type { get { return accType; } }

    public bool Withdraw(decimal amount)
    {
        if (amount <= 0) return false;
        if (amount > balance) return false;
        balance -= amount;
        return true;
    }

    public decimal Deposit(decimal amount)
    {
        if (amount <= 0) throw new ArgumentException("Deposit must be positive");
        balance += amount;
        return balance;
    }
}

static class CreateAccount
{
    public static BankAccount NewBankAccount()
    {
        Console.Write("Account number: ");
        var num = Console.ReadLine();
        Console.Write("Starting balance: ");
        decimal bal;
        while (!decimal.TryParse(Console.ReadLine(), out bal))
            Console.Write("Invalid amount. Enter decimal value: ");
        var a = new BankAccount();
        a.Populate(num, bal);
        return a;
    }

    public static void Write(BankAccount a)
    {
        Console.WriteLine("Number: {0}  Type: {1}  Balance: {2:C}", a.AccountNumber, a.Type, a.Balance);
    }

    public static void TestWithdraw(BankAccount a)
    {
        Console.Write("Withdraw amount: ");
        decimal amt;
        if (!decimal.TryParse(Console.ReadLine(), out amt)) { Console.WriteLine("Bad input"); return; }
        if (!a.Withdraw(amt)) Console.WriteLine("Withdrawal failed: insufficient funds or invalid amount.");
        else Console.WriteLine("New balance: {0:C}", a.Balance);
    }

    public static void TestDeposit(BankAccount a)
    {
        Console.Write("Deposit amount: ");
        decimal amt;
        if (!decimal.TryParse(Console.ReadLine(), out amt)) { Console.WriteLine("Bad input"); return; }
        Console.WriteLine("New balance: {0:C}", a.Deposit(amt));
    }
}

Notes and cautions: prefer decimal for money (used above). Always validate console input with TryParse to avoid exceptions and guard against negative amounts. The example sets accType to AccountType.Checking inside Populate as required; adjust as needed for savings accounts. This answer is intended to clarify and complete the earlier hints from while following the advice from and to work incrementally.

Recommended Answers

All 4 Replies

Hi, dujdaran, welcome!
We are all friendly girls and boys overhere, but I think nobody of them is prepared to do your homework for you.
Show some effort first, if yoy have some problems on the way, we will try to help. :)

Hi dujdaran,

Keeping ur homework, especially one u aren't very good with, to the last minute is bad practice. Try to get something 'reasonable' done first, post it, the problem u're having and we're willing to help. Be sure to read the rules too... ;-)

Regards,

Seslie.

Hey dujgaran,

I suggest you to work on each module from starting and when some problem comes, you may post again.Please consider me not being rude because I want to help you in a better way by solving your problem and not the whole question.
That's how everything works until you put some efforts by yourself.

Lol here is a start for Task 2

class BankAccount

hope it helps;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.