Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The base code for this assignment contains some initial code for an electronic store program. This code includes an ElectronicStore class, a Product dlass,

The base code for this assignment contains some initial code for an electronic store program. This code includes an Electroni

1. Change the existing code so that is uses ADTs for expandable storage of Product objects instead of a fixed-size array. 2.


public class Assignment 4LoadTester { public static void main(String[] args) { System.out.println(Loading a store from a fil

public class Assignment 4 Tester { public static void main(String[] args) { ElectronicStore store = new ElectronicStore (Pas

Customer cl = new Customer(Frodo); Customer c2 = new Customer (Galadriel); Customer c3 = new Customer( Tom B.); store.r

System.out.println(Should be: Tom B. (14018), Frodo (8200), Galadriel (4000)); for (Customer c: store.getTopCustomers(3)) {  
 

The base code for this assignment contains some initial code for an electronic store program. This code includes an ElectronicStore class, a Product dlass, and a number of descendants of the Product class representing specific types of products. The ElectronicStore class currently uses an array to store up to MAX_PRODUCTS products. Within this assignment, you will be modifying the ElectronicStore to make use of ADTS for storage. You will also be adding customers into this program and implementing some additional functionality. The remainder of this document outlines the changes you should make to the existing code and the functionality you will be required to add. There are two test classes provided on the assignment page that you should use to test your methods. These test dasses perform minimal testing. Providing further testing of your own is advisable. You should include any additional test classes you have created with your assignment submission. Customer Class: Add a Customer class to the project that will be responsible for tracking the purchase history of a customer within the electronic store. The class must support the following constructors and methods: 1. Customer(String name) Constructor used to initialize the customer with the given name. 2. String toString()- Should return a string of the format "{name} who has spent $x" where (name} is the customer's name and x represents the total dollars that customer has spent at the electronic store. 3. void printPurchaseHistory() Prints out a list of products the customer has bought. This list should contain each unique product once and should indicate how many units of each product the customer has purchased (e.g., 4 x 2.0 cu. ft. Horn Pass Fridge with Freezer (Red, 111 watts)). 4. String getName() - A basic get method that returns the name of the Customer. The above methods must be implemented following the given specifications. Note, however, that you will have to add additional state/methods into the Customer class to support the remainder of the assignment requirements (e.g., you will need to keep track of the purchase history for the customer). ElectronicStore Class: You will have to update the existing ElectronicStore class and add in additional state/methods. The final ElectronicStore class will keep track of both Product objects and Customer objects. Below is a summary of the changes and additions you must make: 1 1. Change the existing code so that is uses ADTS for expandable storage of Product objects instead of a fixed-size array. 2. Create a boolean registerCustomer(Customer) method that will add the given Customer object to the ElectronicStore. It shouid not be possible to add two customers with the same name (i.e., the customer names within a store are unique). This method should return true if the Customer was added successfully and false otherwise. 3. Update the boolean addProduct(Product) method in the induded code to work with your ADT-based storage. It should not be possible to add duplicate products. For the purposes of this assignment, two products should be considered identical if their toString() methods return the same strings. 4. Add a List public class Assignment4LoadTester { public static void main(String[) args){ System.out.println("Loading a store from a file that doesn't exist, should be null: " + ElectronicStore.loadFromFile("doesntexist.txt")); System.out.println( "Loading a store for file that does exist (assuming you have run Assignment 4Tester already)..."); ElectronicStore store = Electronicstore.loadFromPile("store.dat"); System.out.println("Printing out all customers sorted by amount of money spent"); System.out.println("First 4 should be: Tom B. (17018), Galadriel (10000), Frodo (8200), Fredigar (6000)"); System.out.println("Followed by 5 others in any order with so each"); for (Customer c: store.getTopXCustomers(store.getCustomers ().size()+ 1)){ System.out.printin (c); for (Customer c: store.getCustomers()){ if(c.getName ( ).equals ("Tom B.")){ System.out.println("Printing Tom B.'s purchases"); System.out.println("Should have 4xDesktop, 1xFridge, 5xToasters"); c.printPurchaseHistory(); public class Assignment4Tester { public static void main(String[] args){ Electronicstore store = new ElectronicStore( "Past Shop"): Product pl = new Desktop(1000, 10, 4, 32, true, 256, "Full Size"); store.addProduct (pl); store.addProduct (new Desktop(800, 25, 3, 16, false, 2048, "Mid Size")); store.addProduct (new Desktop(700, 15, 2.5, 16, false, 1024, "Compact")); Product p2 = new Desktop(1200, 5, 4.5, 64, true, 512, "Server"); store.addProduct (p2); store.addProduct (new Laptop (1500, 10, 3.5, 16, true, 256, 15.1)); store.addProduct (new Laptop(2500, 3, 4, 32, true, 512, 35.1)); store.addProduct (new Laptop(1200, 12, 3, 16, false, 512, 15.1)); Product p3 = new Laptop(800, 5, 2.5, 8, true, 128, 13.1); store.addProduct (p3); store.addProduct (new Fridge (1500, 15, 250, "Stainless Steel", "Danby", 15.5, true)); store.addProduct (new Fridge (2500, 5, 900, "Shiny Blue", "Mr Freeze", 25, true)); Product p4 = new Fridge (3018, 1, 111, "Red", "Horn Pass", 2, true); store.addProduct (p4); store.addProduct (new Fridge (250, 30, 100, "White", "Discount Freezer Corporation", 5, false)); store.addProduct (new Fridge (500, 13, 275, "Off White", "Discount Freezer Corporation", 15, false)); store.addProduct (new Toasteroven (80, 10, 50, "Red", "General Electric", 5, false)); store.addProduct (new Toasteroven (50, 5, 40, "Red", "General Electric", 3, false)); Product p5 = new Toasteroven (2000, 25, 400, "Gold", "Toast-0-Max Bluetooth-Enabled Toasters", 3, true); store.addProduct (p5); Customer cl = new Customer( "Frodo"); Customer c2 new Customer ( "Galadriel"); Customer c3 = new Customer( "Tom B."); store.registerCustomer (cl); store.registercustomer (c2); store.registerCustomer (new Customer( "Eowyn")); store.registerCustomer (c3); store.registercustomer (new Customer ("Shadowfax")); store.registercustomer (new Customer("Galadriel")); store.registerCustomer (new Customer ("Lobelia")); store.registerCustomer (new Customer ("Bert")); store.registerCustomer (new Customer ("Shadowfax")); store.registerCustomer (new Customer ( "William")); store.registerCustomer (new Customer ( "Lobelia")); System.out.println( "# customers (should be 8): " + store.getCustomers ().size()); //Testing size of list returned by product search System.out.println( "# matched products (should be 3): store.searchProducts ("red").size()); System.out.println("# matched products (should be 5): store.searchProducts ("SSD").size()); System.out.println("# matched products (should be 8): store.searchProducts("ram").size()); (should be 1): 100).size()); System.out.println("# matched products + store.searchProducts ("red", 55, (should be 2): 100).size()); System.out.println("# matched products + store.searchProducts ("red", -1, (should be 2): -1).size()); System.out.println("# matched products + store.searchProducts ("red", 55, (should be 2) : 1100).size()); System.out.println("# matched products + store.searchProducts ("ssd", -1, (should be 3): 1050, -1).size()): System.out.println("# matched products " + store.searchProducts ("ssd", System.out.println("Should be: Tom B. (14018), Frodo (8200), Galadriel (4000)"); for(Customer c: store.getTopXCustomers (3)){ System.out.println(c); System.out.println("Registering new user and retrying previous sell step..."); store.registerCustomer (newCustomer); store.sellProduct (p2, newCustomer, 5); System.out.println("Printing top 3 customers"); System.out.println("Should be: Tom B. (14018), Frodo (8200), Fredigar (6000)"); for (Customer c: store.getTopXCustomers (3)){ System.out.println(c); } System.out.println("Adding more of product #1 (Desktop $1000)"); store.addStock (pl, 10); store.sellProduct (pl, c2, 6); store.sellProduct (pl, c3, 3); store.sellProduct (pl, cl, 2); System.out.println("Printing top 4 customers"); System.out.println("Should be: Tom B. (17018), Galadriel (10000), Frodo (8200), Fredigar (6000)"); for (Customer c: store.getTopXCustomers (4)){ System.out.println(c); } System.out.println("Printing out all customers"); System.out.println("First four should match above, followed by 5 others in any order"); for (Customer c: store.getTopXCustomers (store.getCustomers ().size()+ 1)){ System.out.println(c); System.out.println("Saving store to store.dat file"); store.saveTOFile("store.dat"); }

Step by Step Solution

3.34 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

Please find the below code Appliancejava public abstract class Appliance extends Product private int wattage private String color private String brand public Appliancedouble initPrice int initQuantity ... 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

Principles of heat transfer

Authors: Frank Kreith, Raj M. Manglik, Mark S. Bohn

7th Edition

495667706, 978-0495667704

More Books

Students also viewed these Accounting questions

Question

Use a computer to find the following probabilities. a. b. c. d.

Answered: 1 week ago

Question

What is the relationship between negative thinking and depression?

Answered: 1 week ago

Question

what is homomorphic encryption?

Answered: 1 week ago