lehrkraefte:blc:informatik:ffprg1-2020:oop

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
lehrkraefte:blc:informatik:ffprg1-2020:oop [2021/03/26 17:53]
michael.greminger
lehrkraefte:blc:informatik:ffprg1-2020:oop [2021/03/26 18:02]
michael.greminger
Line 197: Line 197:
  
 <hidden Lösungsvorschlag> <hidden Lösungsvorschlag>
-Kommt bald ;-)+<code python> 
 +from datetime import datetime 
 + 
 +class Konto: 
 +    def __init__(self, i, k): 
 +        self._inhaber = i  
 +        self._kontostand = k  
 +        self._buchungen = []               
 + 
 +    def inhaber(self): 
 +       return self._inhaber  
 +        
 +    def kontostand(self): 
 +        return self._kontostand   
 +     
 +    def zinssatz(self): 
 +        return 0.035   
 +     
 +    def kontostandDatum(self, dString): 
 +        datum = datetime.strptime(dString, "%d.%m.%Y"
 +        index = len(self._buchungen) 
 +        betrag = self._kontostand 
 +        while index >= 0 and datum < self._buchungen[index].datum(): 
 +            betrag = betrag - self._buchungen[index].betrag()  
 +            index = index - 1             
 +        return betrag        
 +     
 +    def addBuchung(self, b, d): 
 +        b = Buchung(b, d) 
 +        self._buchungen.append(b) 
 +        self._kontostand += b.betrag() 
 +         
 +class Supersparkonto (Konto):  
 +    def __init__(self, i, k): 
 +        Konto.__init__(self, i, k)     
 +     
 +    def zinssatz(self): 
 +        abgehoben = 0 
 +        for b in self._buchungen: 
 +            if b.betrag() < 0: 
 +              abgehoben += 1 
 +        zins = Konto.zinssatz(self) 
 +        if abgehoben < 3: 
 +            zins += 0.01  
 +        return zins              
 +     
 +class Buchung: 
 +    def __init__(self, b, d): 
 +       self._betrag = b  
 +       self._datum = datetime.strptime(d, "%d.%m.%Y"       
 + 
 +    def betrag(self): 
 +       return self._betrag  
 +        
 +    def datum(self): 
 +        return self._datum                                            
 + 
 + 
 +k1 = Supersparkonto("Michael", 1000) 
 +k1.addBuchung(-100, "13.12.2021"
 +k1.addBuchung(-200, "15.12.2021"
 +print k1.zinssatz() 
 +k1.addBuchung(-300, "17.12.2021"
 +print k1.zinssatz() 
 +    
 +</code>
 </hidden> </hidden>
  
Line 207: Line 272:
  
 <hidden Lösungsvorschlag> <hidden Lösungsvorschlag>
 +<code python>
 Kommt bald ;-) Kommt bald ;-)
 +</code>
 </hidden> </hidden>
  
  
  • lehrkraefte/blc/informatik/ffprg1-2020/oop.txt
  • Last modified: 2021/03/26 18:02
  • by michael.greminger