Account - { if (o instanceof Account) { Account a =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; public abstract class Account implements Comparable{ protected String owner; protected int number; protected double balance; public String getOwner() { return owner;} public double getBalance() { return balance;} public int getNumber() { return number;} public void setOwner(String owner) { this.owner= owner;} public void setBalance(double balance) { this.balance= balance;} public void setNumber(int number) { this.number = number;} p public Account(String owner, int number) { this(owner, 0, 0D); } public Account(String owner, int number, double balance){ this.owner = owner; this.balance = balance; this.number = number; } public void deposit(double amount) { balance += amount; } public double withdraw(double amount) { double totalBalance = 0D; totalBalance = balance - amount; return totalBalance; } public int compareTo(Object o)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { if (o instanceof Account) { Account a = (Account)o; if (getBalance()==a.getBalance()) { if(getOwner().equals(a.getOwner())) { return 0; } else return owner.compareTo(a.owner); } else return getBalance() >= a.getBalance() ? 1 : -1; } else { throw new ClassCastException(); } } public int compare(Object o1, Object o2) { if (o1 instanceof Account && o2 instanceof Account) { Account a = (Account)o1; Account b = (Account)o2; if (a.getOwner().equals(b.getOwner())) { if(a.getBalance()==b.getBalance()) { return 0; } else return a.getBalance() >= b.getBalance() ? 1 : -1; } else return a.owner.compareTo(b.owner); } else { throw new ClassCastException(); } } public String toString() { return "Account Number: " + getNumber()+ ",Owner:" + getOwner() + ",Balance:" + getBalance(); } }...
View Full Document

This note was uploaded on 03/25/2010 for the course CIS CIS3023 taught by Professor Seema during the Spring '10 term at Florida College.

Page1 / 2

Account - { if (o instanceof Account) { Account a =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online