import java.util.Calendar;
import java.util.GregorianCalendar;
abstract class Payment {
Account account;
Account transferAccount;
double amount;
Category cat;
GregorianCalendar cal;
//Kontruktor für sofortige Ausführung. SinglePayment.
public Payment (Account account, double amount, Category cat) {
this.account = account;
this.transferAccount = null;
this.amount = amount;
this.cat = cat;
this.cal = new GregorianCalendar();
this.account.accPaymentList.add(this);
this.cat.catPaymentList.add(this);
}
// Kontruktor mit variablem Ausführungszeitpunkt. SinglePayment.
public Payment (Account account, double amount, Category cat, int date, int month, int year) {
this.account = account;
this.transferAccount = null;
this.amount = amount;
this.cat = cat;
this.cal = new GregorianCalendar();
this.cal.set(Calendar.DATE, date);
this.cal.set(Calendar.MONTH, month-1);
this.cal.set(Calendar.YEAR, year);
this.account.accPaymentList.add(this);
this.cat.catPaymentList.add(this);
}
// Konstruktor mit 2 Accounts für Transfer-Buchungen. Sofortige Ausführung.
public Payment (Account account, Account transferAccount, double amount, Category cat) {
this.account = account;
this.transferAccount = transferAccount;
this.amount = amount;
this.cat = cat;
this.cal = new GregorianCalendar();
Payment p = new Withdrawal(account, amount, cat); //!! Müssen noch abgespeichert werden
Payment q = new Deposit(transferAccount, amount, cat);
}
// Konstruktor mit 2 Accounts für Transfer-Buchungen. Variabler Ausführungszeitpunkt.
public Payment (Account account, Account transferAccount, double amount, Category cat, int date, int month, int year) {
this.account = account;
this.transferAccount = transferAccount;
this.amount = amount;
this.cat = cat;
this.cal = new GregorianCalendar();
this.cal.set(Calendar.DATE, date);
this.cal.set(Calendar.MONTH, month-1);
this.cal.set(Calendar.YEAR, year);
Payment p = new Withdrawal(account, amount, cat, date, month, year); //!! Müssen noch abgespeichert werden
Payment q = new Deposit(transferAccount, amount, cat, date, month, year);
}
// Erhöht das Guthaben des übergebenen Kontos um den übergebenen Betrag
public void increaseAccountAmount(Account account, double amount) {
if (this.account.amount == null)
this.account.amount = amount;
else
this.account.amount = this.account.amount+amount;
}
// Verringert das Guthaben des übergebenen Kontos um den übergebenen Betrag
public void decreaseAccountAmount(Account account, double amount) {
if (this.account.amount == null)
this.account.amount = -amount;
else
this.account.amount = this.account.amount-amount;
}
// getDate im Format "Datum: D.M.Y"
public String getDate () {
return this.cal.get(Calendar.DATE)+"."+(this.cal.get(Calendar.MONTH)+1)+"."+this.cal.get(Calendar.YEAR);
}
/*
* Methode, die von Payments aufgerufen werden muss, die wiederholt werden sollen.
* Zahlung wird so oft wie übergeben monatsweise wiederholt.
*/
public void repPayment (int times) { //!!Müssen noch abgespeichert werden
if (this instanceof Deposit) {
for (int i = 1; i < times; i++){
int a = this.cal.get(Calendar.DATE);
int b = ((this.cal.get(Calendar.MONTH)+1));
int c = this.cal.get(Calendar.YEAR);
b = b+i;
Payment x = new Deposit(this.getAccount(), this.getAmount(), this.getCat(), a, b, c);
}
}
if (this instanceof Withdrawal) {
for (int i = 1; i<= times; i++){
int a = this.cal.get(Calendar.DATE);
int b = ((this.cal.get(Calendar.MONTH)+1));
int c = this.cal.get(Calendar.YEAR);
b = b+i;
Payment x = new Withdrawal(this.getAccount(), this.getAmount(), this.getCat(), a, b, c);
}
}
if (this instanceof Transfer) {
for (int i = 1; i<= times; i++){
int a = this.cal.get(Calendar.DATE);
int b = ((this.cal.get(Calendar.MONTH)+1));
int c = this.cal.get(Calendar.YEAR);
b = b+i;
Payment x = new Withdrawal(this.getAccount(), this.getAmount(), this.getCat(), a, b, c);
Payment y = new Deposit(this.getTransferAccount(), this.getAmount(), this.getCat(), a, b, c);
}
}
}
//Getter & Setter
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
public Category getCat() {
return cat;
}
public void setCat(Category cat) {
this.cat = cat;
}
public GregorianCalendar getCal() {
return cal;
}
public void setCal(GregorianCalendar cal) {
this.cal = cal;
}
public Account getTransferAccount() {
return transferAccount;
}
public void setTransferAccount(Account transferAccount) {
this.transferAccount = transferAccount;
}
}