DOC PREVIEW
WVU CS 110 - Account

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

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 int account; // instance account # private String holder; // holder name private double balance; // current account balance private boolean overdrawnflag; // indicates if the account is overdrawn // CONSTRUCTORS GO HERE. 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.// Accessorspublic 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// Mutatorspublic 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


View Full Document

WVU CS 110 - Account

Download Account
Our administrator received your request to download this document. We will send you the file to your email shortly.
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 2 2 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?