Answered step by step
Verified Expert Solution
Link Copied!

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 =0;
this.mailingList = false;
this.transactions = new ArrayList>();
}
public CustomerData(String lastName, String firstName, String address, String phone, int customerNumber, boolean mailingList, ArrayList transactions){
super(lastName, firstName, address, phone);
this.customerNumber = customerNumber;
this.mailingList = mailingList;
this.transactions = new ArrayList>(transactions); // Deep copy
}
public int getCustomerNumber(){
return customerNumber;
}
public boolean getMailingList(){
return mailingList;
}
public void setCustomerNumber(int customerNumber){
this.customerNumber = customerNumber;
}
public boolean isMailingList(){
return mailingList;
}
public void setMailingList(boolean mailingList){
this.mailingList = mailingList;
}
public ArrayList getTransactions(){
return new ArrayList>(transactions); // Deep copy
}
public void setTransactions(ArrayList transactions){
if (transactions == null){
throw new IllegalArgumentException("Transactions list cannot be null.");
}
this.transactions = new ArrayList>(transactions); // Deep copy
}
public void addTransaction(long t){
if (String.valueOf(t).length()>15|| t =0){
throw new IllegalArgumentException("Invalid transaction value.");
}
transactions.add(t);
}
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 ?1 : 0)+ transactions.hashCode();
}
@Override
public boolean equals(Object 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 ArrayList>(transactions).equals(new ArrayList>(that.transactions)); // 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 01: Test for no-argument constructor, and accessor methods PASSED
Test Set 01: Test for constructor with parameters FAILED
Test Set 01: Test for deep copy of the ArrayList field FAILED
Test Set 01: Test for accessors FAILED
Test Set 01: Test for getTransactions() deep copy FAILED
Test Set 01: Test for all mutator methods FAILED
Test Set 01: Test for deep copy of the ArrayList field when changed by mutator FAILED
Test Set 02: addTransaction() method FAILED
Test Set 02: addTransaction() exception PASSED
Test Set 02: Test for equals() method FAILED
Test Set 02: Test for clone() method FAILED
Test Set 02: Test for clone() method with deep copy FAILED
Here's the test cases code:
import java.io.PrintWriter;
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 tests(PrintWriter out){
out.println("\r
----CustomerData Class TEST SETS -------------------------------------------------------\r
");
boolean t1= testSet01CustomerDataClass(out);
boolean t2= testSet02CustomerDataClass(out);
return t1 && t2;
}
/**
* Set of unit tests for no-argument constructor, constructor, accessors
*
* @param outputStream stream to direct output into
* @return number of points earned for this unit. 0 is returned if even one of
* the tests failed
*/
public static boolean testSet01CustomerDataClass(PrintWriter outputStream){
int count =0;
int expectedCount =7;
CustomerData p1= new CustomerData();
// Test #1
if (p1.getFirstName().equals("") && p1.getLastName().equals("") && p1.getPhone().equals("")
&& p1.getAddress().equals("") && p1.getMai
here's also my PersonData code
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions