Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help me to write this code on java this assignment, you will write classes for a Customer and a BankAccount. You will also write

please help me to write this code on java

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)

What to Turn In

You must turn in a .zip file which contains all of your java files. If you are using eclipse, highlight your project (com.century.pa2). From the menu, choose file->export. Choose "Archive File" (it's under General) and press next. Chose the project you are turning in (expand and make sure src is checked!). Make sure "Save in zip format" is selected and "Compress the contents of the file" is checked. Click "Browse" and choose a name and folder for your zip file. Click "Finish". (See the video in the D2L Module before this assignment)

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 nextDouble() and multiply by 100,000,000)

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)

Please also review the rubric for more specific information.

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!

image text in transcribed

Sample Output The sample Driver program produces output similar to the following (except for dates and the account numb which is random). Customer 1: Customer id=15000. firstName=Tim.lastName= Berners-Leo: address Cambridge, MA 02139. age=651 Customer 2: Customer [id-15011. firstName=Adele, lastName Goldberg, address Palo Alto, CA 94301. g751 Customet 3: Customer [id=15022. first Name-Window.lastName=Snyder address San Francisco 94103, age: 451 Customer 4: Customer Tid=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. account Number 64754195. annualInterest Rate 0.045 customers Customer Tid=15000. firstName=Tim. lastName = Berners-Leo. address-Cambridge, MA 021.39. Age=6511 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! public static void main(String[] args) { Customer ci = new Customer("Tim", "Berners-Lee", "Cambridge, MA 02139", 65); Customer c2 = new Customer ("Adele", "Goldberg", "Palo Alto, CA 94301", 75); Customer c3 = new Customer("Window", "Snyder", "San Francisco, CA 94103", 45); Customer c4 = new Customer("Mark", "Dean", "Knoxville, TN 37996", 63); System.out.println("Customer 1: " + ci); System.out.println("Customer 2: " + c2); System.out.println("Customer 3: " + c3); System.out.println("Customer 4: " + c); double balance - 1330; double interestRate - .045; BankAccount acct = new BankAccount(ci, balance, interestRate); System.out.println("Account Info: " + acct); acct.deposit(200); System.out.println("Current Balance: " + acct.getBalance()); System.out.println("Account Number: " + acct.getAccount Number()); System.out.println("Account created Date: + acct.getCreatedDate()); System.out.println("Customer ID: " + acct.getCustomer().getId()); System.out.println("Monthly Interest Rate: " + acct.getMonthlyInterestRate()); System.out.println("Monthly Interest: + acct.getMonthlyInterest(); acct.withdraw(300); }

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

Students also viewed these Databases questions

Question

How is slaked lime powder prepared ?

Answered: 1 week ago

Question

Why does electric current flow through acid?

Answered: 1 week ago

Question

What is Taxonomy ?

Answered: 1 week ago

Question

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago