Thursday, June 20, 2013

OOD Video Source


package oodDemo;

public abstract class Account {
private String name;
private double balance;

public Account(String name, double balance) {
this.name = name;
this.balance = balance;
}
public Account() {}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void displayInfo() {
System.out.println("Name: " + name + " Balance: " + balance);
}
public abstract void deposit(double amount);

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

package oodDemo;

public class Checking extends Account {
public Checking(String name, double amount) {
      super(name, amount); 
}

public void deposit(double amount) {
setBalance (getBalance() + amount);
}

}

~~~~~~~~~~~~~~~~~~~

package oodDemo;

public class oodApp {

/**
* @param args
*/
public static void main(String[] args) {

      Account acct1 = new Checking("john", 100.0d);
      Account acct2 = new Saving("Jane", 100.0d);
      
      acct1.deposit(100);
      acct2.deposit(100);
      
      acct1.displayInfo();
      acct2.displayInfo();
      
}

}
~~~~~~~~~~~~~~~~

package oodDemo;

public class Saving extends Account {

public Saving(String name, double amount) {
       super(name,amount);
}

public void deposit(double amount) {
setBalance (getBalance() + (amount * 1.10));
}

}

~~~~~~~~~~~~~~~~~~~~~

No comments:

Post a Comment