GithubHelp home page GithubHelp logo

banking-system-using-traits's Introduction

banking-system-using-Traits

Hands-on Task - Creating a basic banking system using Traits

The program will allow users to create accounts, deposit and withdraw money, and view their account balance.

Steps

  1. Create a Trait called Account that defines the methods deposit, withdraw, and balance. These methods should take a mutable reference to self as an argument.
  2. Implement the Account Trait for a struct called BankAccount. The BankAccount struct should have the fields account_number, holder_nam, and balance.
  3. In the implementation of the deposit method for BankAccount, add the deposit amount to the balance.
  4. In the implementation of the withdraw method for BankAccount, subtract the withdraw amount from the balance.
  5. In the implementation of the balance method for BankAccount, return the current balance.
  6. In the main function, create two BankAccount instances with different account numbers and holder names.
  7. Call the deposit method on one of the accounts, passing in a deposit amount.
  8. Call the withdraw method on the other account, passing in a withdraw amount.
  9. Call the balance method on both accounts and print the result to the console.
  10. Compile and run the program to ensure it works as expected.

Checklist

  1. Create a Trait called Account with the methods deposit, withdraw, and balance.
  2. Implement the Account Trait for a struct called BankAccount with the fields account_number, holder_name, and balance.
  3. In the implementation of the deposit method for BankAccount, add the deposit amount to the balance.
  4. In the implementation of the withdraw method for BankAccount, subtract the withdraw amount from the balance.
  5. In the implementation of the balance method for BankAccount, return the current balance.
  6. Create two BankAccount instances in the main function with different account numbers and holder names.
  7. Call the deposit method on one of the accounts, passing in a deposit amount.
  8. Call the withdraw method on the other account, passing in a withdraw amount.
  9. Call the balance method on both accounts and print the result to the console.
  10. Compile and run the program to test its functionality.

How to Run:

Run the program:

cargo run

banking-system-using-traits's People

Contributors

sachincoder1 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.