import java.util.Calendar;
import java.util.GregorianCalendar;
abstract class Payment {
Account account;
Account transferAccount;
double amount;
Category cat;
GregorianCalendar cal;
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);
}
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);
}
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);
Payment q = new Deposit(transferAccount, amount, cat);
}
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);
Payment q = new Deposit(transferAccount, amount, cat, date, month, year);
}
public void increaseAccountAmount(Account account, double amount) {
if (this.account.amount == null)
this.account.amount = amount;
else
this.account.amount = this.account.amount+amount;
}
public void decreaseAccountAmount(Account account, double amount) {
if (this.account.amount == null)
this.account.amount = -amount;
else
this.account.amount = this.account.amount-amount;
}
public String getDate () {
return this.cal.get(Calendar.DATE)+"."+(this.cal.get(Calendar.MONTH)+1)+"."+this.cal.get(Calendar.YEAR);
}
public void repPayment (int times) {
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);
}
}
}
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;
}
}