Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' Design a class named Stock to represent a company's stock.
- It contains:
- symbol
- name
- previousClosingPrice
- currentPrice
- '''
- import math
- class Stock:
- def __init__(self, a, b, c, d):
- self.__symbol = a
- self.__name = b
- self.__previousClosingPrice = c
- self.__currentPrice = d
- def getStockName(self):
- return self.__name
- def getStockSymbol(self):
- return self.__symbol
- def seteazaStocAnterior(self, stockAnterior):
- self.__previousClosingPrice = stockAnterior
- def veziStocAnterior(self):
- return self.__previousClosingPrice
- def seteazaPretCurent(self, pretCurent):
- self.__currentPrice = pretCurent
- print("Procentul nou setat este: ", self.__currentPrice)
- def veziPretCurent(self):
- return self.__currentPrice
- def getChangeProcent(self):
- return (self.__currentPrice - self.__previousClosingPrice) / self.__previousClosingPrice * 100
- class Account:
- def __init__(self, id=0, balance=100, annualInterestRate=0):
- self.__id = id
- self.__balance = balance
- self.__annualInterestRate = annualInterestRate
- def setId(self, newId):
- self.__id = newId
- def getId(self):
- return self.__id
- def setBalance(self, newBalance):
- self.__balance = newBalance
- def getBalance(self):
- return self.__balance
- def setAnnualInterestRate(self, newAnnualInterestRate):
- self.__annualInterestRate = newAnnualInterestRate
- def getAnnualInterestRate(self):
- return self.__annualInterestRate
- def getMonthlyInterest(self):
- return self.__balance * ((self.__annualInterestRate/100) / 12)
- def withdraw(self, withdrawAmmount):
- self.__balance -= withdrawAmmount
- def deposit(self, depositAmmount):
- self.__balance += depositAmmount
- class RegularPolygon:
- def __init__(self, n=3, side=1, x=0, y=0):
- self.__n = n #number of sides
- self.__side = side #length of the side
- self.__x = x #coordinate x for the center of the polygon
- self.__y = y #coordinate y for the center of the polygon
- def setN(self, newN):
- self.__n = newN
- def getN(self):
- return self.__n
- def setSide(self, newSide):
- self.__side = newSide
- def getSide(self):
- return self.__side
- def setX(self, newX):
- self.__x = newX
- def getX(self):
- return self.__x
- def setY(self, newY):
- self.__n = newY
- def getY(self):
- return self.__y
- def getPerimeter(self):
- return self.__side * self.__n
- def getArea(self):
- return round((self.__n * (self.__side ** 2)) / (4 * math.tan((3.14/self.__n))),2)
- print("---------------Clasa Polygon----------------------")
- Obiectul1 = RegularPolygon()
- Obiectul2 = RegularPolygon(6, 4)
- Obiectul3 = RegularPolygon(10, 4, 5.6, 7.8)
- print("Perimetru Obiect 1: ", Obiectul1.getPerimeter())
- print("Arie Obiect 1: " + str(Obiectul1.getArea()))
- print("Perimetru Obiect 2: ", Obiectul2.getPerimeter())
- print("Arie Obiect 2: ", str(Obiectul2.getArea()))
- print("Perimetru Obiect 3: ", Obiectul3.getPerimeter())
- print("Arie Obiect 3: ", Obiectul3.getArea())
- print("---------------Clasa Account----------------------")
- Cont = Account(1122, 20000, 4.5)
- print(Cont.getBalance())
- Cont.withdraw(2500)
- print(Cont.getBalance())
- Cont.deposit(3000)
- print(Cont.getBalance())
- print(Cont.getId())
- print(Cont.getMonthlyInterest())
- print(Cont.getAnnualInterestRate())
- print("-------------------------------------")
- IntelCorporation = Stock("INTC", "Intel Corporation", 20.5, 20.35)
- print("Numele stocului este: " + str(IntelCorporation.getStockName()))
- print("Simbolul stocului este: " + str(IntelCorporation.getStockSymbol()))
- print("Pretul anterior este: " + str(IntelCorporation.veziStocAnterior()))
- print("Pretul curent este: " + str(IntelCorporation.veziPretCurent()))
- print("Procent de crestere: " + str(round(IntelCorporation.getChangeProcent(),2)) + "%")
- IntelCorporation.seteazaPretCurent(30)
- print("Procent de crestere: " + str(round(IntelCorporation.getChangeProcent(),2)) + "%")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement