搜档网
当前位置:搜档网 › homework1

homework1

homework1
homework1

1、Design a class named Account that contains:

■ A private int data field named id for the account (default 0).

■ A private double data field named balance for the account (default 0).

■ A private double data field named annualInterestRate that stores the cur-

rent interest rate (default 0). Assume all accounts have the same interest rate.

■ A private java.util.Date data field named dateCreated that stores the date when the account was created.

■ A private String data field named customer that stores the name of the customer.

■ A data field named transactions whose type is java.util.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 1.

■ A no-arg constructor that creates a default account.

■ A constructor that creates an account with the specified id and initial balance.

■ A constructor that constructs an account with the specified name,

id, and balance.

■The accessor and mutator methods for id, balance, and annualInterestRate.

■The accessor method for dateCreated.

■ A method named getMonthlyInterestRate() that returns the monthly

interest rate.

■ A method named withdraw that withdraws a specified amount from the account and adds a transaction to the transactions array list.

■ A method named deposit that deposits a specified amount to the account adds a transaction to the transactions array list.

Tasks:

A、Implement Account Class;

B、Implement Transaction Class;

C、Write a test program that creates an Account with annual interest rate 1.5%, balance 1000, id 1122, and name George. Deposit $30, $40, $50 to the account and withdraw $5, $4, $2 from the account. Print an account summary that shows account holder name, interest rate, balance, and all transactions.

Notes:java.util.Date and java.util.ArrayList are implemented in the Java API.

Figure 1

2、Implement xjtuse.ArrayList and the methods defined in Figure2. (Hint: Use an array to store the elements in ArrayList. If the size of the ArrayList exceeds the capacity of the current array, create a new array that doubles the size of the current array and copy the contents of the current to the new array.)

Figure 2

Tasks:

A、Implement the xjtuse.ArrayList class;

B、The xjtuse.ArrayList class takes the place of java.util.ArrayList calss in Account class.

相关主题