Object: Methods and properties
๐ Car Properties โ๏ธ Car Methods
๐ Car Properties
Properties are the nouns that describe a car. They are the characteristics or attributes that define a specific car’s state. Think of them as the data associated with a car object.
Examples:
- ๐จ
color: The color of the car (e.g.,red,blue,black). - ๐ญ
make: The brand of the car (e.g.,Toyota,Ford,Honda). - ๐ท๏ธ
model: The specific model of the car (e.g.,Corolla,Mustang,Civic). - ๐
year: The year the car was manufactured (e.g.,2025). - โก
speed: The current speed of the car (e.g.,0 mph,60 mph). - ๐
is_engine_on: A state that tells you if the engine is running (TrueorFalse). - โฝ
fuel_level: The amount of gas in the tank (e.g.,75%).
โ๏ธ Car Methods
Methods are the verbs that describe what a car can do. They are the actions or functions that operate on the car’s properties. Methods often change the state of the car.
Examples:
- โถ๏ธ
start_engine(): This method changes theis_engine_onproperty fromFalsetoTrue. - ๐
accelerate(): This method increases the car’sspeedproperty. - ๐
brake(): This method decreases the car’sspeedproperty. - โน๏ธ
turn_off_engine(): This method changes theis_engine_onproperty fromTruetoFalse. - เนเธเธดเธก
refuel(amount): This method takes anamountas input and increases thefuel_levelproperty. - ๐
honk_horn(): This method performs an action (makes a sound).
Bank Account Properties Methods
๐ฆ Bank Account Properties
Properties are the nouns that describe a bank account. They represent the data and characteristics that make each account unique. Think of them as the information you see on your bank statement.
Examples:
- ๐ข
account_number: A unique number assigned to the account. This property is crucial because it identifies the specific account. - ๐ค
account_holder_name: The name of the person or business that owns the account. - ๐ฐ
balance: The current amount of money in the account. This is the most important property as it changes with every transaction. - ๐ณ
account_type: The kind of account it is, such assavings,checking, orcurrent. - ๐ฒ
currency: The type of currency the account holds (e.g.,USD,EUR,INR).
๐ธ Bank Account Methods
Methods are the verbs that describe what you can do with a bank account. They are the actions or functions that allow you to interact with the account’s properties, particularly its balance.
Examples:
- ๐ฅ
deposit(amount): This method adds money to the account. When you deposit money, thebalanceproperty increases. - ๐ค
withdraw(amount): This method removes money from the account. It also checks if there is enough money in thebalancebefore allowing the withdrawal. - โน๏ธ
get_balance(): This method returns the current value of thebalanceproperty without allowing you to change it directly. This is a common way to see how much money is in the account. - โก๏ธ
transfer(target_account, amount): This method is a bit more complex. It first calls thewithdraw()method from the current account and then calls thedeposit()method on thetarget_account. - ๐
check_transactions(): This method provides a history of all deposits and withdrawals that have occurred on the account.
๐ Food Order Properties And Methods
๐ Food Order Properties
Properties are the nouns that describe a food order. They represent the data and characteristics that make each order unique. Think of them as the details on a receipt.
Examples:
- ๐
order_id: A unique number assigned to the order. This is like a ticket number. - ๐งโ๐ณ
customer_name: The name of the person who placed the order. - ๐
items: A list of the food items included in the order (e.g.,['burger', 'fries', 'soda']). - ๐ฒ
total_price: The total cost of the order, calculated from the items. - ๐
delivery_address: The location where the food needs to be delivered. - โฑ๏ธ
status: The current state of the order, such aspending,in_progress,delivered, orcancelled.
๐ฒ Food Order Methods
Methods are the verbs that describe what can be done with a food order. They are the actions or functions that allow the system to manage the order’s properties.
Examples:
- โ
add_item(item_name, price): This method adds a new food item to theitemslist and updates thetotal_priceproperty. - โ
remove_item(item_name, price): This method removes an item from theitemslist and reduces thetotal_price. - โ
confirm_order(): This method changes thestatusof the order frompendingtoin_progressand sends a confirmation to the customer. - ๐
dispatch_delivery(): This method changes thestatustodispatchedand assigns a delivery driver. - โ
cancel_order(): This method changes thestatustocancelledand might trigger a refund process.
๐ Book Properties & Methods
A book can be an object with properties that describe it and methods that allow you to interact with it.
๐ Book Properties
Properties are the nouns that describe a book’s characteristics.
title: The name of the book (e.g.,'The Hitchhiker's Guide to the Galaxy').author: The person who wrote the book (e.g.,'Douglas Adams').page_count: The total number of pages in the book (e.g.,42).current_page: The page number the reader is currently on.is_open: A state that tells you if the book is currently open or closed (TrueorFalse).
๐ Book Methods
Methods are the verbs that describe what a book can do or what you can do with it.
open(): Changes theis_openproperty toTrue.close(): Changes theis_openproperty toFalse.turn_page(): Increases thecurrent_pageproperty by one.read(pages): Advances thecurrent_pageby a specified number ofpages.get_progress(): Calculates and returns the percentage of the book you have read.
๐ป Laptop Properties & Methods
A laptop can also be an object with its own unique properties and methods.
๐ป Laptop Properties
Properties are the nouns that describe a laptop’s state and hardware.
brand: The manufacturer of the laptop (e.g.,'Dell','Apple').model: The specific model name (e.g.,'XPS 15','MacBook Air').battery_level: The current battery charge percentage (e.g.,85%).is_on: A state that tells you if the laptop is powered on (TrueorFalse).screen_brightness: The current brightness level of the display.
๐ฅ๏ธ Laptop Methods
Methods are the verbs that describe what a laptop can do or how a user can control it.
power_on(): Changes theis_onproperty toTrueand performs a startup routine.shut_down(): Changes theis_onproperty toFalse.increase_brightness(): Increases thescreen_brightnessproperty.run_program(program_name): Launches a specific application.charge(): Increases thebattery_levelproperty over time.