Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will write classes for a Customer and a BankAccount. You will also write a Driver program to test all of the

In this assignment, you will write classes for a Customer and a BankAccount. You will also write a Driver program to test all of the methods in your classes. Your program must include input validation and error checking. Please refer to the detailed instructions and sample output.

You will use some of the following constructs you have learned:

  • constructors
  • accessor/mutator methods
  • instance variables
  • access modifiers: public, private, static
  • toString() method
  • the Random class
  • Create java documentation (all classes and methods must have javadoc including @author, @param and @return block tags as appropriate)
  • Read java documentation (you may want to review the java.util.Random and java.util.Date documentation. See: Java 11 API - All Classes

Detailed Instructions

You should create a package for your classes. Name your package "com.century.pa2". All of your classes should be in this package.

Customer class

Design and write a class for a Customer.

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. (Hint: you may want to create a static variable to hold the next or current ID)

BankAccount class

Design and write a class for a BankAccount.

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 calulated 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. (Hint: use nextInt() and the math given at the top of the D2L "Methods" content module)
  • 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 whtich returns all details about the BankAccount including all details about the Customer.

BankAccount has a single constructor which cretes a BankAccount with the specified Customer, balance and annualInterestRate. It should assign the accountNumber and the current date.

Driver

Write a test program that tests all of the methods in both the Customer and BankAccount classes. Use enough test cases to be sure all your code works.

Note: You do not need to use Scanner to read user input. Simply "hard code" values in the driver.

Criteria for Success

You will be graded on the following:

  • Your program should meet the specifications of the problem. Make sure you are including ALL required aspects.
  • Your program must be free of syntax, runtime and logic errors.
  • You must use the correct data type for all variables
  • Your output must properly display all the required data
  • You must use meaningful variable/method/class names. These must follow the standard conventions.
  • Your Driver program must include Top of program comments: Author name, course name, instructor, due date and program description.
  • You must include proper javadoc comments for your classes. Include @author block tags
  • You must include proper javadoc comments for all methods used. Include @param and @return block tags
  • Your program should seek to minimize redundant code. Code should be easy to read/understand/maintain.
  • Your Driver program should have a wide enough range of test cases to ensure everything is properly coded. (test accessor/mutators and other methods)

THE OUTPUT EXAMPLE.

Sample Output

The sample Driver program produces output similar to the following (except for dates and the account number which is random).

Customer 1:

Customer [id=15000, firstName=Tim, lastName=Berners-Lee, address=Cambridge, MA 02139, age=65]

Customer 2:

Customer [id=15011, firstName=Adele, lastName=Goldberg, address=Palo Alto, CA 94301, age=75]

Customer 3:

Customer [id=15022, firstName=Window, lastName=Snyder, address=San Francisco, CA 94103, age=45]

Customer 4:

Customer [id=15033, firstName=Mark, lastName=Dean, address=Knoxville, TN 37996, age=63]

Account Info:

BankAccount [balance=1330.0, date=Sun Feb 07 13:38:04 CST 2021, accountNumber=64754195, annualInterestRate=0.045

customer=Customer [id=15000, firstName=Tim, lastName=Berners-Lee, address=Cambridge, MA 02139, age=65]]

Current Balance: 1530.0

Account Number: 64754195

Account Created Date: Sun Feb 07 13:38:04 CST 2021

Customer ID: 15000

Monthly Interest Rate: 0.00375

Monthly Interest: 5.7375

Sample Driver

Note: This is not a complete Driver. Be sure you are adding to the Driver to test all of your methods!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

what are the provisions in the absence of Partnership Deed?

Answered: 1 week ago

Question

1. What is called precipitation?

Answered: 1 week ago

Question

1.what is dew ?

Answered: 1 week ago

Question

1.The difference between climate and weather?

Answered: 1 week ago