ch4,ch5 _ sol manual

ch4,ch5 _ sol manual - // Adds deposit amount to balance.

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

View Full Document Right Arrow Icon
//******************************************************* // Account.java // // A bank account class with methods to deposit to, withdraw from, // change the name on, charge a fee to, and return a string // representation of the account. //******************************************************* public class Account { private double balance; private String name; private long acctNum; //---------------------------------------------- //Constructor -- initializes balance, owner, and account number //---------------------------------------------- public Account(double initBal, String owner, long number) { balance = initBal; name = owner; acctNum = number; } //---------------------------------------------- // Checks to see if balance is sufficient for withdrawal. // If so, decrements balance by amount; if not, prints message. //---------------------------------------------- public void withdraw(double amount) { if (balance >= amount) balance -= amount; else System.out.println("Insufficient funds"); } //----------------------------------------------
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: // Adds deposit amount to balance. //----------------------------------------------public void deposit(double amount) { balance += amount; } //----------------------------------------------// Returns balance. //----------------------------------------------public double getBalance() { return balance; } //----------------------------------------------// Returns a string containing the name, account number, and balance //----------------------------------------------public String toString() { return "Name: " + name + "\nAccount Number: " + acctNum + "\nBalance: " + balance; } //---------------------------------------------------// Deducts $10 service fee //---------------------------------------------------public double chargeFee() { balance -= 10; return balance; } //----------------------------------------------// Changes the name on the account //----------------------------------------------public void changeName(String newName) { name = newName; } }...
View Full Document

Page1 / 2

ch4,ch5 _ sol manual - // Adds deposit amount to balance.

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