Introduction to Object-Oriented Programming (Python)
Course Overview
Lecture 3 hours; 3 credits; IT required core course.
An introductory course on object-oriented programming that emphasizes problem solving for business
applications. The programming language is Java, Python, or instructor’s choice. Topics include simple data
types, selections, loops, methods, arrays, classes, inheritance, etc.
Course Objectives
- The course will provide students with knowledge and skills to:
- Understand Python programming basics
- Understand object-oriented programming concepts
- Become familiar with a Python development tool
- Be able to develop a desktop app
Assignment
Code example
#This Program is designed to print out personal information
#Create variables for name, address (steetname, city, st, zip), Phone Number, College major
Name = "Justin Prosser"
Address = "1234 Example St."
City = "Bigtown"
State = "VA"
Zip = "12345"
PhoneNum = "123=456-7890"
Major = "Cybersecurity"
Minor = "Information Technology"
#Print out personal info
print("Hello, my name is", Name);
print("I currently live at", Address, City + ",", State, Zip)
print("My major is", Major, "with a minor in", Minor)
#This Application is designed to analyze the stock JD.com and get the Holding-Period Return Value (HPR)
#Import the stock class I made for the program
from stock import Stock
#Def main function
def main(Y):
#inputs for stock symbol and name
A1 = input("Enter the ticker symbol of the stock: ")
A2 = input("Enter the name of the stock: ")
#Init the stock class program
I = Stock(A1,A2)
#Input the beginning and ending prices
A3 = float(input("Enter the adjusted close price at the beginning of the year: "))
B = I.beginning_price(A3) #65.660820
A4 = float(input("Enter the adjusted close price at the end of the year: "))
E = I.ending_price(A4) #55.298244
#Input the cash dividend
A5 = float(input("Enter the dividend [If there isn't a dividend for that year, enter 0]: "))
D = I.dividend(A5) #1.26
#Error checking code (I took out my error checking print statements)
#HPR= float((E - B + D) / B)
#print (HPR)
#Get the HPR Value and round it to the second decimal place
HPR = I.get_holding_period_return(B, E, D)
HPR = round(HPR,2)
#Final output
print ("The Holding-Period Return value for", str(I) + ",", "is:", HPR, "for the calendar year", str(Y) + ".")
#Messages asking client to visit site for necessary info (originally was going to import it from CSV file)
print("Please visit https://finance.yahoo.com/ and look up the stock you want to get a Holding-Period Return for...")
#Give the user 10 attempts to enter y
for i in range(10):
#Ask if the user has a stock
X = input("Do you have a stock you want to get an HPR on? [y] or [n]: ")
if (X == 'y'):
Y = input("Enter the calender year: ") #2022
main(Y)
#Condition to end the program
elif (X == 'n'):
Z = input("Do you want to continue the program? [y] or [n]: ")
if (Z == 'n'):
break
# Car class
class Car:
def __init__(self, year_model, make, speed):
self.__year_model = year_model
self.__make = make
self.__speed = speed
def accelerate(self, speed):
self.__speed = speed + 5
return self.__speed
def brake(self, speed):
self.__speed = speed - 5
return self.__speed
def get_speed(self):
return self.__speed