{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Classes and OOP"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Dog():\n",
    "    \n",
    "    # Class object attribute\n",
    "    species = 'mammal'\n",
    "    \n",
    "    def __init__(self,breed,name,spots):\n",
    "        self.breed = breed\n",
    "        self.name = name\n",
    "        # Expecting a boolean for spots\n",
    "        self.spots = spots\n",
    "        \n",
    "    def bark(self,number):\n",
    "        print ('Woof! My name is {} and my number is {}'.format(self.name,number))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "my_dog = Dog(breed='Beagle',name='Mowgli',spots=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Beagle'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_dog.breed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Mowgli'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_dog.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_dog.spots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'mammal'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_dog.species"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Woof! My name is Mowgli and my number is 4\n"
     ]
    }
   ],
   "source": [
    "my_dog.bark(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Circle():\n",
    "    pi = 3.14\n",
    "    \n",
    "    def __init__(self,radius=1):\n",
    "        self.radius = radius\n",
    "        self.area = radius**2 * Circle.pi\n",
    "        \n",
    "    #Method\n",
    "    def get_circumference(self):\n",
    "        return 2*Circle.pi*self.radius"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "my_circle = Circle(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_circle.radius"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "50.24"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_circle.area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25.12"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_circle.get_circumference()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Inheritance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Area():\n",
    "    def __init__(self,radius):\n",
    "        self.radius = radius\n",
    "    \n",
    "    def diameter(self):\n",
    "        return 2*self.radius"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Circle(Area):\n",
    "    \n",
    "    pi = 3.14\n",
    "    \n",
    "    def __init__(self,radius):\n",
    "        Area.__init__(self,radius)\n",
    "    \n",
    "    def circumference(self):\n",
    "        return 2*Circle.pi*self.radius"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "myarea = Area(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myarea.diameter()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "mycircle = Circle(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "31.400000000000002"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mycircle.circumference()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mycircle.diameter()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### OOP Homework"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Line:\n",
    "    \n",
    "    def __init__(self,coor1,coor2):\n",
    "        self.coor1 = coor1\n",
    "        self.coor2 = coor2\n",
    "    \n",
    "    def distance(self):\n",
    "        return ((self.coor2[0]-self.coor1[0])**2 + (self.coor2[1]-self.coor1[1])**2)**0.5\n",
    "    \n",
    "    def slope(self):\n",
    "        return ((self.coor2[1]-self.coor1[1])/(self.coor2[0]-self.coor1[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "coordinate1 = (3,2)\n",
    "coordinate2 = (8,10)\n",
    "\n",
    "li = Line(coordinate1,coordinate2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9.433981132056603"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li.distance()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.6"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li.slope()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Cylinder:\n",
    "    \n",
    "    pi = 3.14\n",
    "    \n",
    "    def __init__(self,height=1,radius=1):\n",
    "        self.height = height\n",
    "        self.radius = radius\n",
    "        \n",
    "    def volume(self):\n",
    "        return Cylinder.pi*self.radius**2*self.height\n",
    "    \n",
    "    def surface_area(self):\n",
    "        return (2*Cylinder.pi*self.radius)*(self.height+self.radius)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "c = Cylinder(2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "56.52"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.volume()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "94.2"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.surface_area()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Challenge"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For this challenge, create a bank account class that has two attributes:\n",
    "\n",
    "* owner\n",
    "* balance\n",
    "\n",
    "and two methods:\n",
    "\n",
    "* deposit\n",
    "* withdraw\n",
    "\n",
    "As an added requirement, withdrawals may not exceed the available balance.\n",
    "\n",
    "Instantiate your class, make several deposits and withdrawals, and test to make sure the account can't be overdrawn."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Account:\n",
    "    \n",
    "    def __init__(self,owner,balance):\n",
    "        self.owner = owner\n",
    "        self.balance = balance\n",
    "        \n",
    "    def __str__(self):\n",
    "        return f'Account Owner : {self.owner}\\nAccount Balance : ${self.balance}'\n",
    "        \n",
    "    def deposit(self,amount):\n",
    "        self.balance += amount\n",
    "        print ('Deposit Accepted')\n",
    "        \n",
    "    def withdraw(self,amount):\n",
    "        if amount > self.balance:\n",
    "            print('Funds Unavilable!')\n",
    "        else:\n",
    "            self.balance -= amount\n",
    "            print('Withdrawal Accepted')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. Instantiate the class\n",
    "acct1 = Account('Jose',100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Account Owner : Jose\n",
      "Account Balance : $100\n"
     ]
    }
   ],
   "source": [
    "# 2. Print the object\n",
    "print(acct1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jose'"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3. Show the account owner attribute\n",
    "acct1.owner"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4. Show the account balance attribute\n",
    "acct1.balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deposit Accepted\n"
     ]
    }
   ],
   "source": [
    "# 5. Make a series of deposits and withdrawals\n",
    "acct1.deposit(50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Withdrawal Accepted\n"
     ]
    }
   ],
   "source": [
    "acct1.withdraw(75)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Funds Unavilable!\n"
     ]
    }
   ],
   "source": [
    "# 6. Make a withdrawal that exceeds the available balance\n",
    "acct1.withdraw(500)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "75"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acct1.balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
