Answered step by step
Verified Expert Solution
Question
1 Approved Answer
pThis code needs to be modified so it can pass the tests import java.util.ArrayList; public class CustomerData extends PersonData { private int customerNumber; private boolean
pThis code needs to be modified so it can pass the tests
import java.util.ArrayList;
public class CustomerData extends PersonData
private int customerNumber;
private boolean mailingList;
private ArrayList transactions;
public CustomerData
super;
this.customerNumber ;
this.mailingList false;
this.transactions new ArrayList;
public CustomerDataString lastName, String firstName, String address, String phone, int customerNumber, boolean mailingList, ArrayList transactions
superlastName firstName, address, phone;
this.customerNumber customerNumber;
this.mailingList mailingList;
this.transactions new ArrayListtransactions; Deep copy
public int getCustomerNumber
return customerNumber;
public boolean getMailingList
return mailingList;
public void setCustomerNumberint customerNumber
this.customerNumber customerNumber;
public boolean isMailingList
return mailingList;
public void setMailingListboolean mailingList
this.mailingList mailingList;
public ArrayList getTransactions
return new ArrayListtransactions; Deep copy
public void setTransactionsArrayList transactions
if transactions null
throw new IllegalArgumentExceptionTransactions list cannot be null.";
this.transactions new ArrayListtransactions; Deep copy
public void addTransactionlong t
if StringvalueOftlength t
throw new IllegalArgumentExceptionInvalid transaction value.";
transactions.addt;
public int getState
You may implement the getState method based on your requirements
For now, let's return a sample state you can modify this accordingly
return customerNumber mailingList : transactions.hashCode;
@Override
public boolean equalsObject other
if this other return true;
if other null getClass other.getClass return false;
CustomerData that CustomerData other;
return customerNumber that.customerNumber &&
mailingList that.mailingList &&
new ArrayListtransactionsequalsnew ArrayListthattransactions; Deep copy for comparison
@Override
public CustomerData clone
return CustomerData super.clone;
Here's the results that i have right now
CustomerData Class TEST SETS
Test Set : Test for noargument constructor, and accessor methods PASSED
Test Set : Test for constructor with parameters FAILED
Test Set : Test for deep copy of the ArrayList field FAILED
Test Set : Test for accessors FAILED
Test Set : Test for getTransactions deep copy FAILED
Test Set : Test for all mutator methods FAILED
Test Set : Test for deep copy of the ArrayList field when changed by mutator FAILED
Test Set : addTransaction method FAILED
Test Set : addTransaction exception PASSED
Test Set : Test for equals method FAILED
Test Set : Test for clone method FAILED
Test Set : Test for clone method with deep copy FAILED
Here's the test cases code:
import java.ioPrintWriter;
import java.util.ArrayList;
@author AV
public class TestCustomerData
All tests for PesronData class
@return total score for AggregationClass part of assignment
public static boolean testsPrintWriter out
out.printlnr
CustomerData Class TEST SETS r
;
boolean t testSetCustomerDataClassout;
boolean t testSetCustomerDataClassout;
return t && t;
Set of unit tests for noargument constructor, constructor, accessors
@param outputStream stream to direct output into
@return number of points earned for this unit. is returned if even one of
the tests failed
public static boolean testSetCustomerDataClassPrintWriter outputStream
int count ;
int expectedCount ;
CustomerData p new CustomerData;
Test #
if pgetFirstNameequals && pgetLastNameequals && pgetPhoneequals
&& pgetAddressequals && pgetMai
here's also my PersonData code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started