Created
October 3, 2015 19:46
-
-
Save polaroidkidd/a659e01067a3535e1c88 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
/** | |
* Write a description of class ArugmentChecks here. | |
* | |
* @author (your name) | |
* @version (a version number or a date) | |
*/ | |
public class ArgumentChecks | |
{ | |
private int amount; | |
public ArgumentChecks (){} | |
public int checkIfNegativ(int amount) | |
{ | |
if(amount < 0) | |
{ | |
System.out.println("ACHTUNG: NUR 0 ODER POSITIVE ZAHLEN"); | |
return amount = 0; | |
//throw new IllegalArgumentException("ACHTUNG: Nur 0 oder positive Zahlen werden aktzeptiert."); | |
} | |
return amount; | |
} | |
public void checkIfCorrectCategory(int category) | |
{ | |
if ((category < 1) || (category > 3)) | |
{ | |
throw new IllegalArgumentException("ACHTUNG: Kategorien können nur 1, 2 oder 3 sein."); | |
} | |
} | |
} |
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
/** | |
* Write a description of class Event here. | |
* | |
* @author (your name) | |
* @version (a version number or a date) | |
*/ | |
public class Event | |
{ | |
private String eventName; | |
private int anzahlTickets; | |
private ArgumentChecks argumentChecks; | |
private Tickets ticketKat1; | |
private Tickets ticketKat2; | |
private Tickets ticketKat3; | |
private Kuenstler eventKuenstler; | |
//private int anzahlTickets; | |
public Event(){} | |
public Event(String eventName) | |
{ | |
this.eventName = eventName; | |
} | |
public void setKat1(int anzahlTickets, int preis, String beschreibung) | |
{ | |
int kategorie = 1; | |
ticketKat1 = new Tickets(anzahlTickets, kategorie, preis, beschreibung); | |
} | |
public void setKat2(int anzahlTickets, int preis, String beschreibung) | |
{ int kategorie = 2; | |
ticketKat2 = new Tickets(anzahlTickets, kategorie, preis, beschreibung); | |
} | |
public void setKat3(int anzahlTickets, int preis, String beschreibung) | |
{ | |
int kategorie = 3; | |
ticketKat3 = new Tickets(anzahlTickets, kategorie, preis, beschreibung); | |
} | |
public void setKuenstler(String kuenstler, int gage) | |
{ | |
eventKuenstler = new Kuenstler(kuenstler, gage); | |
} | |
public void ticketsKaufen(int anzahlTickets, int kategorie) | |
{ | |
this.anzahlTickets = anzahlTickets; | |
ArgumentChecks argumentChecks = new ArgumentChecks(); | |
argumentChecks.checkIfNegativ(anzahlTickets); | |
argumentChecks.checkIfCorrectCategory(kategorie); | |
checkAvailability(anzahlTickets, kategorie); | |
if((ticketKat1.getKategorie() == kategorie)) //&& (((ticketKat1.getAnzahlTickets() - anzahlTickets) >= 0))) | |
{ | |
System.out.println(""); | |
System.out.println("Gekaufte Tickets: " + this.anzahlTickets); | |
System.out.println("Kategorie: " + ticketKat1.getBeschreibung() + " (" + ticketKat1.getKategorie() + ")"); | |
System.out.println("Preis Total: CHF " + (ticketKat1.getTicketPreis() * this.anzahlTickets)); | |
ticketKat1.setVerkaufteTickets(this.anzahlTickets); | |
System.out.println(""); | |
} else if ((ticketKat2.getKategorie() == kategorie)) //&& (((ticketKat2.getAnzahlTickets() - anzahlTickets) >= 0))) | |
{ | |
System.out.println(""); | |
System.out.println("Gekaufte Tickets: " + anzahlTickets); | |
System.out.println("Kategorie: " + ticketKat2.getBeschreibung() + " (" + ticketKat2.getKategorie() + ")"); | |
System.out.println("Preis Total: CHF " + (ticketKat2.getTicketPreis() * anzahlTickets)); | |
ticketKat2.setVerkaufteTickets(anzahlTickets); | |
System.out.println(""); | |
}else if ((ticketKat3.getKategorie() == kategorie)) //&& (((ticketKat3.getAnzahlTickets() - anzahlTickets) >= 0))) | |
{ | |
System.out.println(""); | |
System.out.println("Gekaufte Tickets: " + anzahlTickets); | |
System.out.println("Kategorie: " + ticketKat3.getBeschreibung() + " (" + ticketKat3.getKategorie() + ")"); | |
System.out.println("Preis Total: CHF " + (ticketKat3.getTicketPreis() * anzahlTickets)); | |
ticketKat3.setVerkaufteTickets(anzahlTickets); | |
System.out.println(""); | |
} else { | |
System.out.println("SYSTEM ERROR"); | |
} | |
} | |
private int checkAvailability(int anzahlTickets, int kategorie) | |
{ | |
this.anzahlTickets = anzahlTickets; | |
if(ticketKat1.getKategorie() == kategorie) | |
{ | |
if (ticketKat1.getAnzahlTickets() < (anzahlTickets + ticketKat1.getVerkaufteTickets())) | |
{ | |
//throw new IllegalArgumentException("Es sind nur noch " + ticketKat1.getAnzahlTickets() + " Tickets in der Kategorie " + ticketKat1.getBeschreibung() + | |
// " (" + ticketKat1.getKategorie() + ") verfügbar."); | |
System.out.println("SYSTEM RESPONSE: NOT ENOUGH TICKETS"); | |
anzahlTickets = 0; | |
} | |
} else if (ticketKat2.getKategorie()== kategorie) | |
{ | |
if (ticketKat2.getAnzahlTickets() < (anzahlTickets + ticketKat2.getVerkaufteTickets())){ | |
throw new IllegalArgumentException("Es sind nur noch " + ticketKat2.getAnzahlTickets() + " Tickets in der Kategorie " + ticketKat2.getBeschreibung() + | |
" (" + ticketKat2.getKategorie() + ") verfügbar."); | |
} | |
} | |
else if ((ticketKat3.getKategorie()) == kategorie) | |
{ | |
if (ticketKat3.getAnzahlTickets() < (anzahlTickets + ticketKat3.getVerkaufteTickets())) | |
{ | |
throw new IllegalArgumentException("Es sind nur noch " + ticketKat2.getAnzahlTickets() + " Tickets in der Kategorie " + ticketKat2.getBeschreibung() + | |
" (" + ticketKat2.getKategorie() + ") verfügbar."); | |
} | |
} | |
return anzahlTickets; | |
} | |
public void printAllInfo() | |
{ | |
System.out.println("#########################################"); | |
} | |
/** | |
* Get/Set-Methods for Category 1 Tickets | |
*/ | |
public int getKat1Tickets() | |
{ | |
return ticketKat1.getAnzahlTickets(); | |
} | |
/** | |
* Get/Set-Methods for Category 1 Tickets | |
*/ | |
public int getKat1TicketPreis() | |
{ | |
return ticketKat1.getTicketPreis(); | |
} | |
public int getKat1Kategorie() | |
{ | |
return ticketKat1.getKategorie(); | |
} | |
public String getKat1Beschreibung() | |
{ | |
return ticketKat1.getBeschreibung(); | |
} | |
public void setKat1AnzahlTickets(int anzahlTickets) | |
{ | |
ticketKat1.setAnzahlTickets(anzahlTickets); | |
} | |
public int getKat1VerkaufteTickets() | |
{ | |
return ticketKat1.getVerkaufteTickets(); | |
} | |
/** | |
* Get/Set-Methods for Category 2 Tickets | |
*/ | |
public int getKat2Tickets() | |
{ | |
return ticketKat2.getAnzahlTickets(); | |
} | |
public int getKat2TicketPreis() | |
{ | |
return ticketKat2.getTicketPreis(); | |
} | |
public int getKat2Kategorie() | |
{ | |
return ticketKat2.getKategorie(); | |
} | |
public String getKat2Beschreibung() | |
{ | |
return ticketKat2.getBeschreibung(); | |
} | |
public void setKat2AnzahlTickets(int anzahlTickets) | |
{ | |
ticketKat2.setAnzahlTickets(anzahlTickets); | |
} | |
/** | |
* Get/Set-Methods for Category 3 Tickets | |
*/ | |
public int getKat3Tickets() | |
{ | |
return ticketKat3.getAnzahlTickets(); | |
} | |
public int getKat3TicketPreis() | |
{ | |
return ticketKat3.getTicketPreis(); | |
} | |
public int getKat3Kategorie() | |
{ | |
return ticketKat3.getKategorie(); | |
} | |
public String getKat3Beschreibung() | |
{ | |
return ticketKat3.getBeschreibung(); | |
} | |
public void setKat3AnzahlTickets(int anzahlTickets) | |
{ | |
ticketKat3.setAnzahlTickets(anzahlTickets); | |
} | |
} | |
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
/** | |
* Write a description of class Kaufen here. | |
* | |
* @author (your name) | |
* @version (a version number or a date) | |
*/ | |
public class Kaufen | |
{ | |
private int preis; | |
private int anzahlTickets; | |
private int kategorie; | |
private ArgumentChecks argumentChecks; | |
private Event event; | |
public Kaufen(){} | |
public void ticketsKaufen(int anzahlTickets, int kategorie) | |
{ | |
event = new Event(); | |
preis = event.getKat1TicketPreis(); | |
ArgumentChecks argumentChecks = new ArgumentChecks(); | |
argumentChecks.checkIfNegativ(anzahlTickets); | |
argumentChecks.checkIfCorrectCategory(kategorie); | |
event = new Event(); | |
if(event.getKat1Kategorie() == kategorie) | |
{ | |
if(event.getKat1Tickets() >= event.getKat1VerkaufteTickets() + anzahlTickets) | |
{ | |
System.out.println("SUCCESS"); | |
} | |
} | |
} | |
} |
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
/** | |
* Write a description of class Kuenstler here. | |
* | |
* @author (your name) | |
* @version (a version number or a date) | |
*/ | |
public class Kuenstler | |
{ | |
private String kuenstler; | |
private int gage; | |
private ArgumentChecks argumentChecks; | |
public Kuenstler (String kuenstler, int gage) | |
{ | |
this.kuenstler = kuenstler; | |
this.gage = gage; | |
ArgumentChecks argumentChecks = new ArgumentChecks(); | |
argumentChecks.checkIfNegativ(gage); | |
} | |
public void setThisKuenstler(String kuenstler) | |
{ | |
this.kuenstler = kuenstler; | |
} | |
public void setGage(int gage) | |
{ | |
this.gage = gage; | |
argumentChecks.checkIfNegativ(gage); | |
} | |
public void setKuenstlerAndGage(String kuenstler, int gage) | |
{ | |
this.kuenstler = kuenstler; | |
this.gage = gage; | |
argumentChecks.checkIfNegativ(gage); | |
} | |
} |
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
/** | |
* Write a description of class Tickets here. | |
* | |
* @author (your name) | |
* @version (a version number or a date) | |
*/ | |
public class Tickets | |
{ | |
private int anzahlTickets; | |
private int kategorie; | |
private int preis; | |
private int verkaufteTickets; | |
private String beschreibung; | |
private ArgumentChecks argumentChecks; | |
public Tickets(int anzahlTickets, int kategorie, int preis, String beschreibung) | |
{ | |
verkaufteTickets = 0; | |
this.anzahlTickets = anzahlTickets; | |
this.kategorie = kategorie; | |
this.preis = preis; | |
this.beschreibung = beschreibung; | |
argumentChecks = new ArgumentChecks(); | |
argumentChecks.checkIfNegativ(preis); | |
argumentChecks.checkIfNegativ(anzahlTickets); | |
argumentChecks.checkIfCorrectCategory(kategorie); | |
} | |
public void setPreis(int preis) | |
{ | |
this.preis = preis; | |
argumentChecks.checkIfNegativ(preis); | |
} | |
public void setAnzahlTickets(int anzahlTickets) | |
{ | |
this.anzahlTickets = anzahlTickets; | |
argumentChecks.checkIfNegativ(anzahlTickets); | |
} | |
public void setKategorie(int kategorie) | |
{ | |
this.kategorie = kategorie; | |
argumentChecks.checkIfCorrectCategory(kategorie); | |
} | |
public void setBeschreibung(String beschreibung) | |
{ | |
this.beschreibung = beschreibung; | |
} | |
public int setVerkaufteTickets(int wert) | |
{ | |
return verkaufteTickets = verkaufteTickets + wert; | |
} | |
public int getAnzahlTickets() | |
{ | |
return anzahlTickets; | |
} | |
public int getTicketPreis() | |
{ | |
return preis; | |
} | |
public int getVerkaufteTickets() | |
{ | |
return verkaufteTickets; | |
} | |
public int getKategorie() | |
{ | |
return kategorie; | |
} | |
public String getBeschreibung() | |
{ | |
return beschreibung; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment