Question: Write classes for a Customer and a BankAccount. You will also write a Driver program to test all of the methods in your classes. the
Write classes for a Customer and a BankAccount. You will also write a Driver program to test all of the methods in your classes.
the following constructs require:
constructors
accessor/mutator methods
instance variables
access modifiers: public, private, static
toString() method
the Random class
Create java documentation
Customer class
Customer has the following data:
customerId - int
firstName - String
lastName - String
address - String
age - int
Customer has the following methods:
- accessor and mutator methods for firstName, lastName, address. In your mutators, validate that the values are not empty.
- accessor and mutator methods for age. In the mutator method, validate that age is between 0 and 120.
- an accessor method for customerId
- a toString() method which returns all details about the Customer (customerId, firstName, lastName, address, age)
Customer has a single constructor which creates a customer with the specified first name, last name, address and age. The constructor should generate the customerID. The first customer should have a customerId of 15000. Subsequent customers should add 11 to the prior id.
BankAccount class
BankAccount has the following data:
accountNumber - long
createdDate - date (Use the Date class from the java.util package)
balance - double
annualInterestRate - double
customer - Customer class which you created
BankAccount has the following methods:
accessor and mutator methods for balance, annualInterestRate, createdDate and customer (Ensure balance and annualInterestRate are non-negative)
accessor method for accountNumber.
a method called getMonthlyInterestRate. This method returns the monthly interest rate which is calculated as annualInterestRate / 12.
a method called getMonthlyInterest. This method returns the monthly interest which is calculated as balance * monthlyInterestRate
a method called generateAccountNumber that returns a 9 digit number. Use the java.util.Random class to generate a 9 digit number.
A method called deposit. This method takes a parameter of type double and adds the parameter to the balance. If the parameter is negative, method should print an error and not update balance.
a method called withdraw. This method takes a parameter of type double and subtracts the parameter from the balance. If the parameter is negative or greater than the existing balance, do not update balance, instead, print an error specifying the problem.
a toString() method which returns all details about the BankAccount including all details about the Customer.
BankAccount has a single constructor which creates a BankAccount with the specified Customer, balance, and annualInterestRate. It should assign the accountNumber and the current date.
Driver:
public class SampleDriver{ public static void main(String[] args) { Customer c1 = new Customer("Tim", "Berners-Lee", "Cambridge, MA 02139", 65); System.out.println("Customer 1: " + c1); Customer c2 = new Customer ("Adele", "Goldberg", "Palo Alto, CA 94301", 75); System.out.println("Customer 2: " + c2); Customer c3 = new Customer ("Window", "Snyder", "San Francisco, CA 94103", 45); System.out.println("Customer 3: " + c3); double balance = 1330; double interestRate = .045;
Note:
The program must include proper javadoc comments for your classes, including @author block tags
BankAccount accounts = new BankAccount(c1, balance, interestRate); System.out.println("Account Information: " + accounts); accounts.deposit(200);
System.out.println("Current Balance: " + accounts.getBalance()); System.out.println("Account Number: " + accounts.getAccountNumber()); System.out.println("Account Created Date: " + accounts.CreatedDate()); System.out.println("Customer ID: " +accounts.getCustomer().getId()); System.out.println("Monthly Interest Rate: " + accounts.getMonthlyInterestRate()); accounts.withdraw(300); System.out.println("Monthly Interest: " + accounts.getMonthlyInterest()); System.out.println("Account-1 toString output: " + accounts);
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
