Created
May 2, 2016 14:31
-
-
Save tobiballof/c67a727e0ce2a36e325bb7261da7f8d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package og11bank; | |
//import og11bank.Konto; | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
/** | |
* | |
* @author Tobi | |
*/ | |
public class Bank { | |
public Konto testKonto=new Konto(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package og11bank; | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
/** | |
* | |
* @author Tobi | |
*/ | |
public class Konto { | |
private int kontostand; | |
private boolean gesperrt = false; | |
public int abheben(int betrag) { | |
if (gesperrt == true) { | |
return -1; | |
} | |
if (kontostand >= betrag) { | |
kontostand = kontostand - betrag; //kurz: kontostand -= betrag; | |
return kontostand; | |
} else { | |
gesperrt = true; | |
return -1; | |
} | |
} | |
public int getKontostand() { | |
return kontostand; | |
} | |
public void setKontostand(int egal) { | |
if (egal >= 0) { | |
kontostand = egal; | |
} else { | |
//erschiesseAnwender(); | |
System.out.println("Der uebergebene Anfangskontostand muss groesser 0 sein!"); | |
} | |
} | |
public boolean getGesperrt() { | |
return gesperrt; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package og11bank; | |
/** | |
* | |
* @author Tobi | |
*/ | |
public class OG11Bank { | |
private static boolean kontoGesperrt(Konto ed4) { | |
boolean hack = ed4.getGesperrt(); | |
return hack; | |
} | |
public static void main(String[] args) { | |
Bank bank1saar = new Bank(); | |
Bank bank2palz = new Bank(); | |
bank1saar.testKonto.setKontostand(109); | |
bank2palz.testKonto.setKontostand(11025); | |
int xyz = 0; | |
while (xyz != -1) { | |
xyz = bank1saar.testKonto.abheben(23); | |
System.out.println("Kontostand: " + xyz); | |
if (kontoGesperrt(bank1saar.testKonto)) { | |
System.out.println("Konto ist gesperrt!"); | |
} else { | |
System.out.println("Konto ist NICHT gesperrt."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment