Unformatted text preview:

public class Account CLASS VARIABLES GO HERE all instances of class Account share a variable called accountNumber which will contain the next available account number when an account is opened private static int nextAccount 1 INSTANCE VARIABLES GO HERE Each instance of class account will have its own copy of the following variables private private private private int account instance account String holder holder name double balance current account balance boolean overdrawnflag indicates if the account is CONSTRUCTORS GO HERE overdrawn Each class can have one or more constructors public Account account nextAccount balance 0 0 holder new String unknown overdrawnflag false end default constructor public Account double newBalance String newholder account nextAccount holder new String newholder balance newBalance overdrawnflag false A copy constructor creates a duplicate of an existing object public Account Account oldAccount account nextAccount balance oldAccount balance overdrawnflag oldAccount overdrawnflag holder new String oldAccount holder end copy constructor STATIC METHODS GO HERE static methods are invoked to a class not for a single object This method simply prints the next available account public static void showNextAccountNumber System out println the next available account number is nextAccount return INSTANCE METHODS GO HERE All of the following methods are applied to a specific instance of our class Credit and Debit are mutators because they change the balance stored in the instance print Information and check balance are accessors because they display information displayed inside the object but do not change it Accessors public double checkBalance return balance public void printAccount System out println The account number is account System out println The account holder is holder System out println The account balance is balance System out println The account is overdrawn overdrawnflag return public boolean compareTo Account otherAccount if this balance otherAccount balance this overdrawnflag otherAccount overdrawnflag this holder compareTo otherAccount holder 0 return true return false end compareTo Mutators public void credit double amount if amount 0 this balance this balance amount else System out println The amount given must be 0 for credit to work return public void debit double amount this balance this balance amount if this balance 0 overdrawnflag true System out println ERROR THE CURRENT BALANCE IN THE ACCOUNT IS balance THE CURRENT TRANSACTION TO WITHDRAW amount WILL CAUSE THE ACCOUNT TO BE OVERDRAWN return end of class Account


View Full Document

WVU CS 110 - Account

Loading Unlocking...
Login

Join to view Account and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Account and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?