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/19 13:18]
michael.greminger
lehrkraefte:blc:informatik:ffprg1-2020:oop [2021/03/26 18:02]
michael.greminger
Line 4: Line 4:
  
 === Präsentation === === Präsentation ===
-{{lehrkraefte:blc:informatik:ffprg1-2020:oop1.pptx}}+{{lehrkraefte:blc:informatik:ffprg1-2020:oop1.pdf}}
  
 === Aufgabe 1 === === Aufgabe 1 ===
Line 19: Line 19:
  
 <hidden Lösungsvorschlag> <hidden Lösungsvorschlag>
-Kommt bald ;-)+<code python> 
 +class Konto: 
 +    def __init__(self, i, k)
 +       self._inhaber = i  
 +       self._kontostand = k     
 + 
 +    def inhaber(self): 
 +       return self._inhaber  
 +        
 +    def kontostand(self): 
 +        return self._kontostand                   
 + 
 +k1 = Konto("Michael", 1234) 
 +k2 = Konto("Fritz", 12340)  
 +print k1.kontostand()   
 +print k2.inhaber()  
 +</code>  
 </hidden> </hidden>
  
Line 35: Line 51:
  
 <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     
 + 
 +    def inhaber(self): 
 +       return self._inhaber  
 +        
 +    def kontostand(self): 
 +        return self._kontostand    
 +     
 +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                                            
 + 
 +b1 = Buchung(456, "13.12.2021"
 +print b1.datum() 
 + 
 +k1 = Konto("Michael", 1234) 
 +k2 = Konto("Fritz", 12340)  
 +print k1.kontostand()   
 +print k2.inhaber()    
 +</code>
 </hidden> </hidden>
  
Line 43: Line 91:
  
 <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 addBuchung(self, betrag, datum): 
 +        buchungInstanz = Buchung(betrag, datum) 
 +        self._buchungen.append(buchungInstanz) 
 +        self._kontostand += buchungInstanz.betrag() 
 +     
 +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 = Konto("Michael", 1234) 
 +k1.addBuchung(100, "13.12.2021"
 +print k1.kontostand()   
 +</code>
 </hidden> </hidden>
  
Line 51: Line 134:
  
 <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 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 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 = Konto("Michael", 100) 
 +k1.addBuchung(100, "13.12.2021"
 +k1.addBuchung(200, "15.12.2021"
 +k1.addBuchung(300, "17.12.2021"
 +print k1.kontostand()   
 +print k1.kontostandDatum("12.12.2021")  
 +print k1.kontostandDatum("14.12.2021")  
 +print k1.kontostandDatum("16.12.2021")  
 +print k1.kontostandDatum("18.12.2021" 
 +</code>   
 </hidden> </hidden>
  
Line 57: Line 190:
  
 === Präsentation === === Präsentation ===
-{{lehrkraefte:blc:informatik:ffprg1-2020:oop2.pptx}}+{{lehrkraefte:blc:informatik:ffprg1-2020:oop2.pdf}}
  
 === Aufgabe 5 ===  === Aufgabe 5 === 
Line 64: 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 74: 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