Nie wiem jak przetworzyć obiekty BanCustomer na String.
Na razie drukuje mi
BankCustomer@2a139a55
BankCustomer@15db9742
BankCustomer@2a139a55
BankCustomer@15db9742
Wiem, że to przedszkole, ale javą zajmuje się od miesiąca.
public class BankingTest {
public static void main(String[] args) {
Person janP = new Person("Jan"),
alaP = new Person("Ala");
BankCustomer jan = new BankCustomer(janP);
BankCustomer ala = new BankCustomer(alaP);
jan.getAccount().deposit(1000);
ala.getAccount().deposit(2000);
jan.getAccount().transfer(ala.getAccount(), 500);
ala.getAccount().withdraw(1000);
System.out.println(jan);
System.out.println(ala);
Account.setInterestRate(4.5);
jan.getAccount().addInterest();
ala.getAccount().addInterest();
System.out.println(jan);
System.out.println(ala);
}
}
public class BankCustomer {
Account konto;
Person klient;
BankCustomer(Person nazwa){
klient = nazwa;
konto= new Account();
}
public Account getAccount() {
return this.konto;
}
}
public class Person {
String name;
public Person(String name) {
this.name=name;
}
}
public class Account {
private double balance;
static double stopa;
public void deposit(int wplata) {
if(wplata < 0) {
throw new IllegalArgumentException(
"Wplata powinne być > 0 . ");
}else {
balance+=wplata;
}
}
public void withdraw( int wyplata) {
if(wyplata < 0) {
throw new IllegalArgumentException(
"Wyplata powinne być > 0 . ");
}else {
balance-=wyplata;
}
}
public void transfer (Account konto, int przelew) {
if(przelew < 0) {
throw new IllegalArgumentException(
"Transfer powinne być > 0 . ");
}else {
konto.balance+=przelew;
this.balance-=przelew;
}
}
public void addInterest() {
}
public static void setInterestRate(double d) {
Account.stopa=d;
}
public double stanKonta() {
return balance;
}
}