Skip to content

Instantly share code, notes, and snippets.

@tobiballof
Created May 2, 2016 14:31
Show Gist options
  • Save tobiballof/c67a727e0ce2a36e325bb7261da7f8d4 to your computer and use it in GitHub Desktop.
Save tobiballof/c67a727e0ce2a36e325bb7261da7f8d4 to your computer and use it in GitHub Desktop.
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();
}
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;
}
}
/*
* 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