Lab 5 Pre-Lab Assignment | Name ___________________________________ |
0 1 1 0 1 0 1 1 + 0 0 1 1 0 1 0 0 ------------------ <---- your answer __________________
//***************************************************** // Account.java // // Represents a bank account; allows deposits, // withdrawals, balance inquiries, etc. //***************************************************** public class Account { public static final double RATE = 0.035; // interest rate of 3.5% ___________________________________________________________; // $10 fee private long acctNumber; private double balance; private String name; //--------------------------------------------------- // Constructor -- initializes instance data //--------------------------------------------------- public Account(String owner, long account, double initial) { name = owner; acctNumber = account; balance = initial; } //--------------------------------------------------- // Deposits the amount from the account and returns // the new balance. //--------------------------------------------------- public double deposit (double amount) { balance += amount; return balance; } //--------------------------------------------------- // Simple withdrawal -- deducts amount from balance // and returns the new balance. //--------------------------------------------------- public double withdraw(double amount) { balance -= amount; return balance; } //--------------------------------------------------- // Adds interest to the account and returns the // new balance. //--------------------------------------------------- public double addInterest () { balance = balance + balance * RATE; return balance; } //--------------------------------------------------- // Returns the current balance. //--------------------------------------------------- public double getBalance() { return balance; } //------------------------------------------------------ // Deducts the service fee and returns the new balance. //------------------------------------------------------ public double chargeFee() { // deduct the fee ____________________________________________________ // return the updated balance ____________________________________________________ } //--------------------------------------------------- // Changes the name on the account to newName. //--------------------------------------------------- public void setName(String newName) { ___________________________________________________ } //-------------------------------------------------- // Returns a string representation of the account. //-------------------------------------------------- public String toString () { return "Account number: " + acctNumber + "\nOwner: " + name + "\nCurrent balance: " + balance; } }
//***************************************************** // ManageAccounts.java // // Uses the Account class to create and // manipulate bank accounts for Sally and Joe. //***************************************************** public class ManageAccounts { public static void main(String[] args) { Account account1, account2; //create account1 for Sally for $1000 account1 = new Account("Sally", 12345, 1000); //create account2 for Joe with $500 and account number 11229 ______________________________________________ //deposit $100 to Joe's account ______________________________________________ //withdraw $50 from Sally's account ______________________________________________ //charge fees to both accounts ______________________________________________ ______________________________________________ //change name on Joe's account to Joseph ______________________________________________ //print summary for both accounts ______________________________________________ ______________________________________________ } }