Java Reference
In-Depth Information
■
Modify the
withdraw
and
deposit
methods to add a transaction to the
transactions
array list.
■
All other properties and methods are the same as in Programming Exercise 8.7.
Write a test program that creates an
Account
with annual interest rate
1.5%
, bal-
ance
1000
, id
1122
, and name
George
. Deposit $30, $40, and $50 to the account
and withdraw $5, $4, and $2 from the account. Print an account summary that
shows account holder name, interest rate, balance, and all transactions.
*11.9
(
Largest rows and columns
) Write a program that randomly fills in
0
s and
1
s into
an n-by-n matrix, prints the matrix, and finds the rows and columns with the most
1
s. (
Hint
: Use two
ArrayList
s to store the row and column indices with the most
1
s.) Here is a sample run of the program:
Enter the array size n:
The random array is
0011
0011
1101
1010
The largest row index: 2
The largest column index: 2, 3
4
11.10
(
Implement
MyStack
using inheritance
) In Listing 11.10
,
MyStack
is imple-
mented using composition. Define a new stack class that extends
ArrayList
.
Draw the UML diagram for the classes and then implement
MyStack
. Write a test
program that prompts the user to enter five strings and displays them in reverse
order.
11.11
(
Sort
ArrayList
) Write the following method that sorts an
ArrayList
of numbers:
public static void
sort(ArrayList<Integer> list)
Write a test program that prompts the user to enter 5 numbers, stores them in an
array list, and displays them in increasing order.
11.12
(
Sum
ArrayList
) Write the following method that returns the sum of all numbers
in an
ArrayList
:
public static double
sum(ArrayList<Double> list)
Write a test program that prompts the user to enter 5 numbers, stores them in an
array list, and displays their sum.