68 lines
1.9 KiB
Java
68 lines
1.9 KiB
Java
package at.reisinger;
|
|
|
|
/**
|
|
* Alle coins eines Users
|
|
*/
|
|
public class Coins {
|
|
private int amount;
|
|
|
|
/**
|
|
* Erstellt ein neues Münzen Obj
|
|
* @param coins Alle münzen des Users
|
|
*/
|
|
public Coins(int coins) {
|
|
this.amount = coins;
|
|
}
|
|
|
|
/**
|
|
* Holt alle münzen
|
|
* @return Alle münzen
|
|
*/
|
|
public int getCoinAmount() {
|
|
return this.amount;
|
|
}
|
|
|
|
/**
|
|
* Fügt münzen hinzu
|
|
* @param coins Münzen die hinzugefügt werden -> Positiv
|
|
* @throws NegativAmountException Wenn negative münzen hinzugefüght werden
|
|
*/
|
|
public void addCoin(int coins) throws NegativAmountException{
|
|
if(coins < 0) {
|
|
throw new NegativAmountException("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden");
|
|
}else {
|
|
this.amount += coins;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Entfernt münzen
|
|
* @param coins Münzen die entfernt werden sollen, muss positiv sein
|
|
* @return True wenn erfolgreich
|
|
* @throws NegativAmountException Wenn ein negativer betrag abgezogen werden soll
|
|
*/
|
|
public boolean removeCoin(int coins) throws NegativAmountException{
|
|
if(coins < 0) {
|
|
throw new NegativAmountException("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden");
|
|
}else {
|
|
this.amount -= coins;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Ändert den Absoluten Coin amount
|
|
* @param coins Neue Coin anzahl, muss positiv sein
|
|
* @return true wenn erfolgreich
|
|
* @throws NegativAmountException Wenn ein negativer wert eingegeben wird
|
|
*/
|
|
public boolean changeCoinAmmount(int coins) throws NegativAmountException{
|
|
if(coins < 0) {
|
|
throw new NegativAmountException("Es kann kein negativer amount an at.reisinger.Coins hinzugefügt werden");
|
|
}else {
|
|
this.amount = coins;
|
|
return true;
|
|
}
|
|
}
|
|
}
|