Multiple Inhertiance Using Interfaces
class Account
{
Account(){}
Account(int n, double b, String s)
{
acct_bal = b;
ss = s;
acct_no = n;
}
void deposit(double amt) { acct_bal += amt;}
int withdraw(double amt)
{
if (acct_bal < amt) return -1;
acct_bal -= amt;
return 0;
}
double balance() { return acct_bal; }
int acct_no;
String ss;
double acct_bal;
}
class JointAccount extends Account
{
JointAccount() {}
JointAccount(int n, double b, String owner, String jowner)
{
super (n,b,owner);
jss = jowner;
}
String jss;
}
interface FCheckInterface
{
public static final double min_bal = 500.0;
public static final double service_fee = 18.0;
public void fee();
public int withdraw(double amt);
}
class FreeChecking extends Account implements FCheckInterface
{
FreeChecking(){}
FreeChecking(int n, double b, String owner)
{
super (n, b, owner);
free = (b >= min_bal);
}
public void fee()
{
if (!free)
if (withdraw(service_fee) == -1)
System.out.println("fee: Insufficient Balance for Account "+acct_no);
free = (balance() >= min_bal);
}
public int withdraw(double amt)
{
int ok = super.withdraw(amt);
if (ok != -1 && balance() < min_bal) free = false;
return (ok);
}
boolean free;
}
class JtFrChecking extends JointAccount implements FCheckInterface
{
JtFrChecking() {}
JtFrChecking(int n, double b, String owner, String jowner)
{
super(n,b,owner,jowner);
}
public void fee()
{
if (!free)
if (withdraw(service_fee) == -1)
System.out.println("fee: Insufficient Balance for Account "+acct_no);
free = (balance() >= min_bal);
}
public int withdraw(double amt)
{
int ok = super.withdraw(amt);
if (ok != -1 && balance() < min_bal) free = false;
return (ok);
}
boolean free;
}
public class AccountProgram
{
public static void main(String arg[])
{
FreeChecking susan = new FreeChecking(555234, 750.0, "034-55-6789");
susan.deposit(25.5);
susan.withdraw(250);
susan.fee();
System.out.println("month 1: "+susan.balance());
susan.withdraw(30);
susan.deposit(100);
susan.fee();
System.out.println("month 2: "+susan.balance());
JtFrChecking peter_lucy = new JtFrChecking(2345,750,"034-55-111","052-44-7777");
System.out.println(peter_lucy.balance());
peter_lucy.withdraw(400);
System.out.println(peter_lucy.balance());
peter_lucy.deposit(300);
System.out.println(peter_lucy.balance());
peter_lucy.fee();
System.out.println(peter_lucy.balance());
}
}