Advertisement
Poganu

Untitled

Jun 26th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.22 KB | None | 0 0
  1. ''' Design a class named Stock to represent a company's stock.
  2.    It contains:
  3.    symbol
  4.    name
  5.    previousClosingPrice
  6.    currentPrice
  7.  
  8.    '''
  9. import math
  10.  
  11. class Stock:
  12.     def __init__(self, a, b, c, d):
  13.         self.__symbol = a
  14.         self.__name = b
  15.         self.__previousClosingPrice = c
  16.         self.__currentPrice = d
  17.  
  18.     def getStockName(self):
  19.         return self.__name
  20.  
  21.     def getStockSymbol(self):
  22.         return self.__symbol
  23.  
  24.     def seteazaStocAnterior(self, stockAnterior):
  25.         self.__previousClosingPrice = stockAnterior
  26.  
  27.     def veziStocAnterior(self):
  28.         return self.__previousClosingPrice
  29.  
  30.     def seteazaPretCurent(self, pretCurent):
  31.         self.__currentPrice = pretCurent
  32.         print("Procentul nou setat este: ", self.__currentPrice)
  33.  
  34.     def veziPretCurent(self):
  35.         return self.__currentPrice
  36.  
  37.     def getChangeProcent(self):
  38.         return (self.__currentPrice - self.__previousClosingPrice) / self.__previousClosingPrice * 100
  39.  
  40. class Account:
  41.     def __init__(self, id=0, balance=100, annualInterestRate=0):
  42.         self.__id = id
  43.         self.__balance = balance
  44.         self.__annualInterestRate = annualInterestRate
  45.  
  46.     def setId(self, newId):
  47.         self.__id = newId
  48.  
  49.     def getId(self):
  50.         return self.__id
  51.  
  52.     def setBalance(self, newBalance):
  53.         self.__balance = newBalance
  54.  
  55.     def getBalance(self):
  56.         return self.__balance
  57.  
  58.     def setAnnualInterestRate(self, newAnnualInterestRate):
  59.         self.__annualInterestRate = newAnnualInterestRate
  60.  
  61.     def getAnnualInterestRate(self):
  62.         return self.__annualInterestRate
  63.  
  64.     def getMonthlyInterest(self):
  65.         return self.__balance * ((self.__annualInterestRate/100) / 12)
  66.  
  67.     def withdraw(self, withdrawAmmount):
  68.         self.__balance -= withdrawAmmount
  69.  
  70.     def deposit(self, depositAmmount):
  71.         self.__balance += depositAmmount
  72.  
  73.  
  74. class RegularPolygon:
  75.     def __init__(self, n=3, side=1, x=0, y=0):
  76.         self.__n = n #number of sides
  77.         self.__side = side #length of the side
  78.         self.__x = x #coordinate x for the center of the polygon
  79.         self.__y = y #coordinate y for the center of the polygon
  80.  
  81.     def setN(self, newN):
  82.         self.__n = newN
  83.  
  84.     def getN(self):
  85.         return self.__n
  86.  
  87.     def setSide(self, newSide):
  88.         self.__side = newSide
  89.  
  90.     def getSide(self):
  91.         return self.__side
  92.  
  93.     def setX(self, newX):
  94.         self.__x = newX
  95.  
  96.     def getX(self):
  97.         return self.__x
  98.  
  99.     def setY(self, newY):
  100.         self.__n = newY
  101.  
  102.     def getY(self):
  103.         return self.__y
  104.  
  105.     def getPerimeter(self):
  106.         return self.__side * self.__n
  107.  
  108.     def getArea(self):
  109.         return round((self.__n * (self.__side ** 2)) / (4 * math.tan((3.14/self.__n))),2)
  110.  
  111. print("---------------Clasa Polygon----------------------")
  112.  
  113. Obiectul1 = RegularPolygon()
  114. Obiectul2 = RegularPolygon(6, 4)
  115. Obiectul3 = RegularPolygon(10, 4, 5.6, 7.8)
  116.  
  117. print("Perimetru Obiect 1: ", Obiectul1.getPerimeter())
  118. print("Arie Obiect 1: " + str(Obiectul1.getArea()))
  119.  
  120. print("Perimetru Obiect 2: ", Obiectul2.getPerimeter())
  121. print("Arie Obiect 2: ", str(Obiectul2.getArea()))
  122.  
  123. print("Perimetru Obiect 3: ", Obiectul3.getPerimeter())
  124. print("Arie Obiect 3: ", Obiectul3.getArea())
  125.  
  126.  
  127. print("---------------Clasa Account----------------------")
  128.  
  129. Cont = Account(1122, 20000, 4.5)
  130. print(Cont.getBalance())
  131. Cont.withdraw(2500)
  132. print(Cont.getBalance())
  133. Cont.deposit(3000)
  134. print(Cont.getBalance())
  135. print(Cont.getId())
  136. print(Cont.getMonthlyInterest())
  137. print(Cont.getAnnualInterestRate())
  138.  
  139. print("-------------------------------------")
  140.  
  141.  
  142. IntelCorporation = Stock("INTC", "Intel Corporation", 20.5, 20.35)
  143.  
  144. print("Numele stocului este: " + str(IntelCorporation.getStockName()))
  145. print("Simbolul stocului este: " + str(IntelCorporation.getStockSymbol()))
  146. print("Pretul anterior este: " + str(IntelCorporation.veziStocAnterior()))
  147. print("Pretul curent este: " + str(IntelCorporation.veziPretCurent()))
  148.  
  149. print("Procent de crestere: " + str(round(IntelCorporation.getChangeProcent(),2)) + "%")
  150.  
  151. IntelCorporation.seteazaPretCurent(30)
  152.  
  153. print("Procent de crestere: " + str(round(IntelCorporation.getChangeProcent(),2)) + "%")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement