import java.util.ArrayList;
import java.util.Collections;

public class Kino {

 ArrayList<Integer> platz = new ArrayList<Integer>();
 static int platzReihe = 50;
 int startplatz, endplatz;

 public Kino(int Kategorie) {
 platz.add(0); //Fixt den Bug, da sonst -1 ausgabe bei BinarySearch
 switch (Kategorie) {
 case 1:    startplatz = 1;  break; // Reihe A
 case 2: startplatz = 100; break; // Reihe B
 case 3:    startplatz = 200; break; // Reihe C
 case 4:    startplatz = 300; break; // Reihe D
 }
 endplatz = startplatz + platzReihe;
 }

 public boolean checkPlatz(int anzahlPlaetze) {
 int tempInt = 0;
 for (int i = startplatz; i < endplatz; i++) {
 if (istFrei(i)) {
 tempInt++;
 } else {
 tempInt = 0;
 }

 if (tempInt == anzahlPlaetze) {
 return true;
 }

 }
 return false;
 }

 /**
 *
 * @param platznummer
 * @return true, wenn der Platz frei ist.
 */

 public boolean istFrei(int platznummer) {
 if (! (platznummer < startplatz) || (platznummer > endplatz) ) { // prüfe ob platznumer in Range
 Collections.sort(platz);
 return (Integer.valueOf(Collections.binarySearch(platz, platznummer)) <= 0) ? true : false;
 }
 return false;
 }

 public boolean addPlatz(int Platznummer, int Kategorie) {
 if (istFrei(Platznummer)) {
 platz.add(Platznummer);
 return true;
 } else {
 return false;
 }
 }

 public boolean deletePlatz(int platznummer) {
 Collections.sort(platz);
 platz.remove( Collections.binarySearch(platz, platznummer) );
 return true;
 }

 public int hoechstePlatznummer(int Kategorie) {
 int z = 0;
 for (int i = endplatz; i > startplatz; i--) {
 if (Collections.binarySearch(platz, i) > 0);
 z = platz.get( Collections.binarySearch(platz, i) );
 System.out.println("Z!" + z);

 }

 return z;
 }

 public static void main(String args[]) {
 Kino test = new Kino(2); // A = 1, B = 2, C = 3, D = 4

 test.addPlatz(104, 2);
 test.addPlatz(108, 2);
 test.addPlatz(144, 2);

 if (test.checkPlatz(44) == true) {
 System.out.println("Jep, frei.");
 } else {
 System.out.println("keiner frei");
 }

 test.hoechstePlatznummer(2);

 }
}