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
lehrkraefte:blc:informatik:ffprg1-2020:oop [2021/03/26 18:01]
michael.greminger
lehrkraefte:blc:informatik:ffprg1-2020:oop [2021/03/26 18:02] (current)
michael.greminger
Line 198: Line 198:
 <hidden Lösungsvorschlag> <hidden Lösungsvorschlag>
 <code python> <code python>
-Kommt bald ;-)+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> </code>
 </hidden> </hidden>
Line 210: Line 273:
 <hidden Lösungsvorschlag> <hidden Lösungsvorschlag>
 <code python> <code python>
-Kommt bald ;-)+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() 
 +         
 +    def jahresAbschluss(self): 
 +        self.addBuchung(self.kontostand() * self.zinssatz(), "31.12.2021"      
 +         
 +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"
 +k1.addBuchung(-300, "17.12.2021"
 +print k1.kontostand() 
 +k1.jahresAbschluss() 
 +print k1.kontostand()
 </code> </code>
 </hidden> </hidden>
  
  
  • lehrkraefte/blc/informatik/ffprg1-2020/oop.1616778103.txt.gz
  • Last modified: 2021/03/26 18:01
  • by michael.greminger