Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write tests for the following Customer Class o Constructing a Customer o Getting and setting first and last names o Getting customer number public class

Write tests for the following
Customer Class
o Constructing a Customer
o Getting and setting first and last names
o Getting customer number
public class Customer {
private static int nextNumber =1;
private int number;
private String firstName;
private String lastName;
/**
* Represents a customer with customer number (autogenerated), first and last name.
* @param firstName
* @param lastName
*/
public Customer(String firstName, String lastName){
this.number = nextNumber++;
this.firstName = firstName;
this.lastName = lastName;
}
/**
* Returns the first name
* @return the first name
*/
public String getFirstName(){
return firstName;
}
/**
* Returns the last name
* @return the last name
*/
public String getLastName(){
return lastName;
}
/**
* Sets the first name
* @param firstName
*/
public void setFirstName(String firstName){
this.firstName = firstName;
}
/**
* Sets the last name
* @param lastName
*/
public void setLastName(String lastName){
this.lastName = lastName;
}
/**
* Returns the customer number
* @return the customer number
*/
public int getNumber(){
return number;
}
@Override
public String toString(){
return "Customer [number="+ number +", name="+ firstName +""+ lastName +"]";
}
/**
* Customers are equal *only* if their customer numbers are equal
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj){
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass()!= obj.getClass())
return false;
Customer other =(Customer) obj;
if (number != other.number)
return false;
return true;
}
}

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions