The base code for this assignment contains some initial code for an electronic store program. This...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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<Customer getCustomers() method that returns a List of Customer objects that are registered with the ElectronicStore. This ist does not need to be sorted in any way but should only contain one copy of each Customer registered within the store. 5. Add a List<Product searchProducts(String x) method. This method should return a list of matching Product objects in the ElectronicStore. A Product should match the search query if the toString() method of the Product contains the given String x. This search should be done in a case-insensitive manner (eg. DO matches a product with to String() of "dog"). 6. Add a List<Product searchProducts(String x, double minPrice, double maxPrice) method. This method will work like the searchProducts(String x) method but must only include Product objects where minPrice <= Product Price e maxPrice. f the minPrice or maxPrice inputs are less than 0, they should be ignored. As one example, searchProducts("dog", -1. -1) would be equivalent to searchProducts("dog"). As another example, searchProducts("dog". 10, -1) would find all products containing "dog" in the toString() that have a price of 10 dollars or more 7. Add a boolean addStock(Product p, int amount) method. If the given product exists in the store, this method should increase the stock amount of that product by the included amount. The method should retun true to indicate that the product stock was updated and false otherwise. 8. Add a boolean sellProductiProduct p. Customer c, int amount) method. This should simulate selling the given amount of units of Product p to Customer c. The method should retum false if the sale was not successful p is not in store, c is not registered with store, and/or there are not enough units in stock to complete the sale) and true if the sale was successful. 9. Add a List<Customer getTopXCustomers(int x) method. This method must retum a list of the x customers that have spent the most money at the store. This list should also be sorted from the highest to lowest amount spent. Ifxce 0, return an empty list. If x is greater than the number of customers in the store, retum a list with all customers sorted from highest to lowest amount spent. 10. Create a boolean saveToFile(String filename) method that saves the entire store state (including products and customers) to the file with the given name. The method should return true if the store was successfully saved and false otherwise: OMP 1006/1406 - W21 - A4 Due Sunday, April 11 at 11:59 PM 11. Create a static ElectronicStore ioadFromFile(String filename) method that loads a store and its associated customers/products from a file with the given name. The method should retum the loaded ElectronicStore object if the store is successfully loaded. If any errors occur during the loading process, the method should return null. 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"); } 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<Customer getCustomers() method that returns a List of Customer objects that are registered with the ElectronicStore. This ist does not need to be sorted in any way but should only contain one copy of each Customer registered within the store. 5. Add a List<Product searchProducts(String x) method. This method should return a list of matching Product objects in the ElectronicStore. A Product should match the search query if the toString() method of the Product contains the given String x. This search should be done in a case-insensitive manner (eg. DO matches a product with to String() of "dog"). 6. Add a List<Product searchProducts(String x, double minPrice, double maxPrice) method. This method will work like the searchProducts(String x) method but must only include Product objects where minPrice <= Product Price e maxPrice. f the minPrice or maxPrice inputs are less than 0, they should be ignored. As one example, searchProducts("dog", -1. -1) would be equivalent to searchProducts("dog"). As another example, searchProducts("dog". 10, -1) would find all products containing "dog" in the toString() that have a price of 10 dollars or more 7. Add a boolean addStock(Product p, int amount) method. If the given product exists in the store, this method should increase the stock amount of that product by the included amount. The method should retun true to indicate that the product stock was updated and false otherwise. 8. Add a boolean sellProductiProduct p. Customer c, int amount) method. This should simulate selling the given amount of units of Product p to Customer c. The method should retum false if the sale was not successful p is not in store, c is not registered with store, and/or there are not enough units in stock to complete the sale) and true if the sale was successful. 9. Add a List<Customer getTopXCustomers(int x) method. This method must retum a list of the x customers that have spent the most money at the store. This list should also be sorted from the highest to lowest amount spent. Ifxce 0, return an empty list. If x is greater than the number of customers in the store, retum a list with all customers sorted from highest to lowest amount spent. 10. Create a boolean saveToFile(String filename) method that saves the entire store state (including products and customers) to the file with the given name. The method should return true if the store was successfully saved and false otherwise: OMP 1006/1406 - W21 - A4 Due Sunday, April 11 at 11:59 PM 11. Create a static ElectronicStore ioadFromFile(String filename) method that loads a store and its associated customers/products from a file with the given name. The method should retum the loaded ElectronicStore object if the store is successfully loaded. If any errors occur during the loading process, the method should return null. 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"); }
Expert Answer:
Answer rating: 100% (QA)
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 ... View the full answer
Related Book For
Principles of heat transfer
ISBN: 978-0495667704
7th Edition
Authors: Frank Kreith, Raj M. Manglik, Mark S. Bohn
Posted Date:
Students also viewed these accounting questions
-
The Excel file for this assignment contains a database with information about the tax assessment value assigned to medical office buildings in a city. The following is a list of the variables in the...
-
A storage array dials a support center automatically whenever an error is detected. The vendor's representative at the support center can log on to the service processor of the storage array through...
-
1- Suppose we have production function F(k,n) = Akan where k denotes the capital stock, n denotes the number of hours worked, a = .25, and A = 100, (a) why do we assume k 0? (b) Show that F (k,n) >...
-
1. Consider the following problem: Suppose that the interest rate in this year is 5% and all investors expect that interest rates for the next 3 years will be as follows: Year 1 2 3 Forward Interest...
-
Following are selected transactions that affected NoQWERTY during 2009. On January 1, NoQWERTY paid $300,000 for 15,000 shares of LQTM, Inc. On January 1, LQTM, Inc. declared and paid a $0.32 per...
-
An investment analyst has been studying the long-term prospects of Six Flags Entertainment Corporation and has asked for assistance. Go to www.sixflags.com and click on Investors at the top of the...
-
The PFD in Figure 11.63 shows a process in which two liquid products, A and B, are produced from a feed stream of raw material R. In the process, the reactor feed is preheated to \(300^{\circ}...
-
During 2018, Brewster Company earned revenues of $146 million. Brewster incurred, during that same year, salary expense of $28 million, rent expense of $23 million, and utilities expense of $19...
-
Let C' be the curve of intersection of the cylinder 25x + y = 25 and the plane x + y + z = 4. (a) Using t as the parameter where 0
-
In Integrative Case 10.1, we projected financial statements for Walmart Stores for Years +1 through +5. The data in Chapter 12, Exhibits 12.17 through 12.19 include the actual amounts for 2015 and...
-
7. Minimize the following function using simulated annealing algorithm: (x)=(x + x2 11)+(x + x 7), x1, x2 [0,5]
-
A third order system is approximated to an equivalent second order system. The rise time of the lower order system will be (a) same as that of original system for any input. (b) smaller than that of...
-
In how many ways can a chairperson and a vice chairperson be selected from a committee of 25 senators?
-
How many permutations are there of the words given in Problems 33-42? HOLIDAY
-
Pear Corporation acquired 75 percent ownership of Sugar Company on January 1, 20X1, at underlying book value. At that date, the fair value of the noncontrolling interest was equal to 25 percent of...
-
Show that the sum of the entries of the \(n\)th row of Pascal's triangle is \(2^{n}\).
-
6. What advantages does a pivoting axle suspension system entail? 7. Could you class pneumatic tyres as a form of suspension. Explain your answer True/False 8. What special precaution must be...
-
Give the structural formulas of the alkenes that, on ozonolysis, give: a. (CH3)2C=O and CH2=O b. Only (CH3CH2)2C=O c. CH3CH=O and CH3CH2CH=O d. O=CHCH2CH2CH2CH=O
-
An electronic circuit board is the shape of a flat plate 0.3 m x 0.3 m in plan-form and dissipates 15 W. It may be placed in operation on an insulated surface in a horizontal position or at an angle...
-
A large body of nonluminous gas at a temperature of 1100?C has emission bands between 2.5 and 3.5 mm and between 5 and 8 mm. At 1100?C, the effective emittance in the first band is 0.8 and in the...
-
Determine the excess temperature at one-half of the maximum heat flux for the fluid-surface combinations in Problem 10.3.From Problem 10.3: Estimate the maximum heat flux obtainable with nucleate...
-
Mulberry Ltd has been using the FIFO costing method to account for inventories for several years. The company also has a policy of paying out all of its profits in cash dividends. What are the likely...
-
Burkinshaw Ltd was established on 1 April 2025 and began by issuing 250000 ordinary shares and 1200008% cumulative preference shares. The preference shares were issued privately at a value of \($4\)...
-
The directors of Outback Ltd decided to issue 200 000 ordinary shares. Required (a) Prepare journal entries (in general journal form) to record the issue of shares as a private placement to Rural Ltd...
Study smarter with the SolutionInn App