Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Problem #1 PersonData and CustomerData Classes PersonData Class Start with PersonData.java provided with assignment files. Class already has all fields and toString() method written

JAVA

Problem #1 PersonData and CustomerData Classes

PersonData Class

Start with PersonData.java provided with assignment files. Class already has all fields and toString() method written in. It also extends HasState class, please do not change this hierarchy. HasState is provided with the assignment files.

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 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

Start with CustomerData.java provided with assignment files. Class already has all fields and toString() method written in.

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

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. 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.

PersonData.java

public class PersonData extends HasState implements Cloneable

{

protected String lastName;

protected String firstName;

protected String address;

protected String phone;

public String toString()

{

//Do not change this implementation

return "First name: "+firstName+"; Last name: "+lastName+"; Address: "+address+"; Phone: "+phone;

}

}

CustomerData.java

import java.util.ArrayList;

public class CustomerData extends PersonData

{

private int customerNumber;

private boolean mailingList;

private ArrayList transactions;

public String toString()

{

//Do not change this implementation

String str = super.toString()+"; Customer number: "+customerNumber+"; Mailing list: "+mailingList+"; Transactions: "+transactions.toString();

return str;

}

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxxviii Special Issue On Database And Expert Systems Applications Lncs 11250

Authors: Abdelkader Hameurlain ,Roland Wagner ,Sven Hartmann ,Hui Ma

1st Edition

3662583836, 978-3662583838

More Books

Students also viewed these Databases questions

Question

Demonstrate three aspects of assessing group performance?

Answered: 1 week ago