YournameLab8.java

  • Create customer1 and calls readInput and writeOutput on it.
  • Create customer2 and calls readInput and writeOutput on it.
  • Tests the == operator customer1 and customer2.
  • Tests the equals method on customer1 and customer2.
  • Assigns customer2 to customer1 and tests the == operator on them again.
  • Calls setEmail on customer1 and calls writeOutput on customer1.

Customer.java

  • Has private instance variables for first name, last name, and email.
  • Has accessors for each private instance variable.
  • Has mutators for each private instance variable.
  • Implements readInput.
  • Implements writeOutput.
  • Implements hasSameNameAs.
  • Implements hasSameEmailAs.
  • Implements equals.
  • All methods are public except hasSameNameAs and hasSameEmailAs, which are private.

Instructions

1. Start NetBeans.

2. Create a new project called YournameLab8 with your name.

3. Create a Java class file for a Customer class.

4. Implement the Customer class.

(a) Add the following private instance variables to the Customer class:

  • An instance variable called firstName of type String.
  • An instance variable called lastName of type String.
  • An instance variable called email of type int.

(b) Add public accessor and mutator methods for each of the instance variables.

(c) Add the following public methods to the Customer class:

  • A void method called readInput that prompts the user for a first name, last name, and an email address, and initializes the appropriate instance variables with the resulting values.
  • A void method called writeOutput that displays the customer information in the following format:
First Name: Annie
Last Name: Malone
Email: amalone@poro.edu

5. Write a code in the main method of your main class to test the Customer class.

(a) Create a new Customer object called customer1.

(b) Call the readInput method on customer1.

(c) Call the writeOutput method on customer1.

(d) The output should look something like this:

Enter the customer first name:
Meg
Enter the customer last name:
Whitman
Enter the customer email address:
mwhitman@hp.com

First Name: Meg
Last Name: Whitman
Email: mwhitman@hp.com

6. Add some Boolean-valued methods to the Customer class.

(a) Add a private boolean-valued method hasSameNameAs with a parameter of type Customer that returns true if the first and last name of the object method is called on are identical to the first and last name of the parameter, and returns false otherwise.

(b) Add a private boolean-valued method called hasSameEmailAs with a parameter of type Customer that returns true if the email of the object the method was called on is the same as the email of the parameter ignoring case.

(c) Add a public boolean-valued method called equals with a parameter of type Customer that returns true if:

  • The customer have the same name (use hasSameNameAs).
  • The customer emails are the same(use hasSameEmailAs).

Otherwise, it should return false.

7. Write code in your main method to test out the equals method and the == operator onCustomer objects.

(a) Create a second customer object called customer2.

(b) Call readInput on customer2.

(c) Call writeOutput on customer2.

(d) Use the operator == to compare customer1 and customer2 and output one of the following messages depending on the result:

Customer1 is equal to customer2 using the == operator
Customer1 is not equal to customer2 using the == operator

(e) Use the equals method to compare customer1 and customer2 and output one of the following messages depending on the result:

Customer1 is equal to customer2 using the equals method
Customer1 is not equal to customer2 using the equals method

8. Test your code on multiple inputs to see how it behaves.

(a) Test the program with two customers with different names and email addresses.

(b) Test the program with two customer with identical names and the same email addresses.

(c) Test the program with two customers and identical names but with the first email address in uppercase and the second in lower case.

9. Write code in your main method to see what happens when one variable of class type is assigned to another variable of class type.

(a) Assign customer2 to customer1 object using the assignment operator =.

(b) Use the operator == to compare customer1 and customer2 and output the message indicating the result.

(c) Use the setEmail method to change the email address of customer2 to nobody@nowhere.com.

(d) Use the writeOutput method to display customer1.

(e) Test your code to see what happens.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.