i need help on :
we sum the balances of all of the Accounts ??
print the total sum.
print the owners of all the Accounts that have balances < 100 ?
Danny is generous – and wants to deposit 72 into all accounts with balances < 100
How many accounts have balances < 200 now ?
○ First print the account information out ..
○ How count how many
frank won Super Power Ball
replace her account with her new name Madame Mona, with the balance of 4377
harry is leaving town – delete his account
public class Account {
private int balance; //current balance
private String owner; // Account owner
public Account(String owner, int balance) {
this.owner = owner;
this.balance = balance;
}
public void deposit(int amt) {
balance += amt;
}
public void withdraw( int amt) {
balance -= amt;
}
public int getBalance () {
return balance;
}
public String getOwner () {
return owner;
}
public String toString () {
return "Account :: Owner: " + owner + " Balance: " + balance ;
}
import java.util.ArrayList;
public class ArrayCC {
//have to have globasl scope for the gBank
//declaree the array
static ArrayList<Account> gBank;
public static void main(String[] args) {
gBank = new ArrayList<Account>(); //accessible as a paraneter
gBank.add(new Account("liz", 344)); \
Account acct;
acct = new Account("tom", 76);
gBank.add(acct);
gBank.add(new Account("harry", 155));
gBank.add(new Account("blake", 8));
//how would you print all the objects? use advanced for loop
for (Account i : gBank) {
System.out.println(i);
}
gBank.add(2, new Account("Danny", 787));
System.out.println("\nAt a club");
for (Account i : gBank) {
System.out.print(i);
}
gBank.set(2, new Account("Danny", 787));
for (Account i : gBank) {
System.out.println(i);
}
gBank.get(getIndex("danny")).deposit(45);
gBank.get(2).deposit(45);
John_285
0
Newbie Poster
Recommended Answers
Jump to Post... and what is your question?
All 3 Replies
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Ondrej_2
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.