Question: Please use JAVA ! Problem #1 PersonData and CustomerData Classes PersonData Class Design a class named PersonData with the following fields of type String: lastName
Please use JAVA !
Problem #1 PersonData and CustomerData Classes
PersonData Class
Design a class named PersonData with the following fields of type String:
- lastName
- firstName
- address
- phone
Methods:
- Write appropriate accessor and mutator functions for all the fields.
- Write a non-argument constructor that sets all fields to empty strings.
- Write a constructor that takes all the data about customer as parameters (4 parameters) and initializes fields.
- Override toString() and equals() methods for the class
- Override clone() method. You can consider all of the fields to be of a primitive type, although strings are not. Because stings are immutable, default clone() will work just fine for them. Add declaration that the class implements Cloneable interface, otherwise your code will not compile. Handle CloneNotSupportedException in the method. If exception occurred, the program must terminate with appropriate message. clone() method must not throw exceptions in your calling code.
Suggested strategy: check out the unit tests for methods to see the signatures of methods used there.
CustomerData Class
Design a class named CustomerData, which is derived from the PersonData class. The CustomerData class should have the following fields:
- customerNumber
- mailingList
- transactions
- The customerNumber field will be used to hold a unique integer for each customer. The mailingList field should be a boolean. It will be set to true if the customer wishes to be on a mailing list, or false if the customer does not wish to be on a mailing list. Transactions represents the list of all transactions done with the customer for the last 5 years. Transactions are stored as an ArrayList of long integers.
- Write a non-argument constructor that sets all variables (including inherited ones) to empty strings and transactions to an empty ArrayList (but not null!). Make sure to call parent constructor FIRST.
- Write a constructor that takes all the data about customer as parameters (name, address, etc., total of 7 parameters) and initializes member variables. When working with transaction field, dont forget to create a deep copy of the object that is given to you as an argument. Make sure to call parent constructor first.
- Write appropriate accessor and mutator methods for these fields.
- Notice that you want to create a deep copy when writing accessor for transactions field.
- When writing mutator for ArrayList field, create a deep copy of the argument. If a null was passed as parameter IllegalArgumentException must be generated
- Write void addTransaction(long t) method that adds a transaction to the list. When adding a transaction, argument validation must be performed:
- t must be no more than 15 digits long
- t must be positive
- when any of the above errors occur throw IllegalArgumentException
- Override toString()
- toString() must list all the transactions
- Write boolean equals(Object other) methods for the class.
- When writing equals() make sure to compare object data not references.
- Override clone() method to create deep copy of the object. Use clone() method examples we worked on in class. When adding clone() method make sure to add implements Cloneable statement to the class header. Otherwise the override will not compile. Handle CloneNotSupportedException in the method. If exception occurred, the program must terminate with appropriate message. clone() method must not throw exceptions in your code.
Suggested strategy: check out the unit tests for methods to see the signatures of methods used there.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
