Java Reference
In-Depth Information
Draw the UML diagram for the classes and then implement them. Write a test pro-
gram
that
creates
objects
of Account ,
SavingsAccount ,
and
CheckingAccount and invokes their toString() methods.
11.4
( Maximum element in ArrayList ) Write the following method that returns the
maximum value in an ArrayList of integers. The method returns null if the list
is null or the list size is 0 .
public static Integer max(ArrayList<Integer> list)
Write a test program that prompts the user to enter a sequence of numbers ending
with 0 , and invokes this method to return the largest number in the input.
11.5
( The Course class ) Rewrite the Course class in Listing 10.6. Use an ArrayList
to replace an array to store students. You should not change the original contract of
the Course class (i.e., the definition of the constructors and methods should not
be changed).
11.6
( Use ArrayList ) Write a program that creates an ArrayList and adds a Loan
object, a Date object, a string, a JFrame object, and a Circle object to the list,
and use a loop to display all the elements in the list by invoking the object's
toString() method.
11.7
( Shuffle ArrayList ) Write the following method that shuffles the elements in an
ArrayList of integers.
public static void shuffle(ArrayList<Integer> list)
**11.8
( New Account class )An Account class was specified in Programming Exercise
8.7. Design a new Account class as follows:
VideoNote
New Account class
Add a new data field name of the String type to store the name of the cus-
tomer.
Add a new constructor that constructs an account with the specified name, id,
and balance.
Add a new data field named transactions whose type is ArrayList
that stores the transaction for the accounts. Each transaction is an instance
of the Transaction class. The Transaction class is defined as shown in
Figure 11.6.
The get and set methods for these data fields are
provided in the class, but omitted in the UML diagram
for brevity.
Transaction
-date: java.util.Date
-type: char
The date of this transaction.
The type of the transaction, such as 'W' for withdrawal, 'D'
for deposit.
The amount of the transaction.
The new balance after this transaction.
-amount: double
-balance: double
-description: String
The description of this transaction.
+Transaction(type: char,
amount: double, balance:
double, description: String)
Construct a Transaction with the specified date, type,
balance, and description.
F IGURE 11.6
The Transaction class describes a transaction for a bank account.
Search WWH ::




Custom Search