Question
(JAVA) PART 1: A furniture business wants an application to keep track of purchases for the business rewards program. The business is selling sofas, recliners,
(JAVA)
PART 1:
A furniture business wants an application to keep track of purchases for the business rewards program. The business is selling sofas, recliners, tables and chairs.
Implement the classes Customer and Address with the fields shown in the following class diagram. Add getter and setter methods for all fields.
Create an interfaces Furniture and the following four classes that implement the interface. Each class must add the corresponding fieldfor each methodinherited by the interface.
Override and implement the toString(), hashCode() and equals(Object obj) methods in every class (Customer, Address, four Furniture classes). The Customer hashCode() and equals(..) methods should include id, name, and address. The Address hashCode() and equals(..) methods should include all address fields.The furniture classes must not include the price in the hashCode() and equals(..) methods but all other fields.
PART 2:
Create a class called FurnitureBusinessthat has aprivatehash table of type java.util.HashMapthat keepstrack of each customer and the furniture a customerhas bought:HashMap
The FurnitureBusiness class should provide the following methods:
* Called when customer purchases new furniture. It tracks the purchased furniture in the private map. If the customer does not yet exist in the map, put the customer as a key and an empty list as a value. Then, get the list for that customer and add the given furniture f to the list.
public voidpurchase(Customer c, Furniture... f) Checks if the given customer has bought the furniture f @return true if customer has bought furniture, false otherwise
public boolean hasBought(Customer c, Furniture f) Gets the purchased furniture for the given customer @return List of furniture bought by given customer
public List
public int moneySpent(Customer c)
PART 3: (Test) Instantiate the FurnitureBusinessclass. Create threefully populated but different customers. Create fivedifferent furniture objects; at least one of each type. The first customer buys three furniture by calling the purchase(..) method of the FurnitureBusinessobject. The second and third customer each buy one furniture piece.
Now, use a for loop to iterate over all three customers. Use a nested for loop to iterate over the fivefurniture pieces. In each iteration, call the hasBought(..)method of the FurnitureBusinessobjectand print out customer, furniture, and hasBoughtstatus.
Iterateover each customer again and print out the furniture he has bought by calling the getPurchases(..)method. Also, print out the total money a customer has spent using the moneySpent(..) method.
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