summaryrefslogtreecommitdiff
path: root/Data_Structures_and_Algorithms_in_Java/ch1.ipynb
blob: 8973ccb0b7c0e4dff5cc9de8e5fe13321f054ab7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
 "metadata": {
  "name": "",
  "signature": "sha256:85fd10a5846b5256e76a45973450cd001c1aeb110532e77b6ab379820dba7274"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 1  : Overview"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 1.1 Page No : 17"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "class BankAccount:\n",
      "    def __init__(self,openingBalance): # constructor\n",
      "        self.balance = openingBalance\n",
      "\n",
      "    def deposit(self,amount): # makes deposit\n",
      "        self.balance = self.balance + amount; \n",
      "    \n",
      "    def withdraw(self,amount): # makes withdrawal\n",
      "        self.balance = self.balance - amount; \n",
      "\n",
      "    def display(self):\n",
      "        # displays balance \n",
      "        print 'balance=' , self.balance\n",
      "\n",
      "# end class BankAccount\n",
      "\n",
      "ba1 = BankAccount(100.00) # create acct\n",
      "print 'Before transactions, ',\n",
      "ba1.display()\n",
      "# display balance\n",
      "ba1.deposit(74.35)\n",
      "ba1.withdraw(20.00)\n",
      "print 'After transactions, ' ,\n",
      "ba1.display()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Before transactions,  balance= 100.0\n",
        "After transactions,  balance= 154.35\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}