Question: In this question, you are working with products Computer and TV (which both inherit from ElectronicsProduct), for use in an ElectronicsStore. /** * A class

In this question, you are working with products Computer and TV (which both inherit from ElectronicsProduct), for use in an ElectronicsStore. /** * A class for an electronics product. * * You do not have to modify the following. */ public class ElectronicsProduct { private String name; private int stock; public ElectronicsProduct(String name) { this.name = name; stock = 0; } public ElectronicsProduct(ElectronicsProduct p) { // Notice that the values are copied over from p this.name = p.name; this.stock = p.stock; } public String getModelName() { return name; } public void addStock(int amount) { stock += amount; } public int getStock() { return stock; } public boolean equals(Object other) { ElectronicsProduct otherProd = (ElectronicsProduct) other; return name.equals(otherProd.name); } public String toString() { return "Model: " + name + ", Stock: " + stock; } } 
_______________________________________________________________________________ /** * A class for Computers. You should complete the following: * * - Complete the regular constructor * - Complete the "copy" constructor * - Complete toString * - Complete equals */ public class Computer extends ElectronicsProduct { private double screenSize; private double ramGB; private double hdGB; public Computer(String name, double screenSize, double ramGB, double hdGB) { //-----------Start below here. To do: approximate lines of code = 4 //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } public Computer(Computer computer) { //-----------Start below here. To do: approximate lines of code = 4 // // Remember to copy all values from the given computer. // See the ElectronicsProduct constructor of this type for an example // You can use super to copy the values in ElectronicsProduct //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } public String toString() { //-----------Start below here. To do: approximate lines of code = 2 // // Remember to use super to get toString for needed parts //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } public boolean equals(Object other) { //-----------Start below here. To do: approximate lines of code = 3 // // Use super.equals to compare parts in ElectronicsProduct //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } } 

____________________________________________________________________________________________________________________________________________

/** * A class for TVs. You should complete the following: * * - Complete the regular constructor * - Complete the "copy" constructor * - Complete toString * - Complete equals */ public class TV extends ElectronicsProduct { public enum Type { LED, OLED, LCD } private Type type; private double screenSize; public TV(String name, Type type, double screenSize) { //-----------Start below here. To do: approximate lines of code = 3 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } public TV(TV tv) { //-----------Start below here. To do: approximate lines of code = 3 // // Remember to copy all values from the given TV. // See the ElectronicsProduct constructor of this type for an example // You can use super to copy the values in ElectronicsProduct //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } public String toString() { //-----------Start below here. To do: approximate lines of code = 1 // // Remember to use super to get toString for needed parts //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } public boolean equals(Object other) { //-----------Start below here. To do: approximate lines of code = 2 // // Use super.equals to compare parts in ElectronicsProduct //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } } 

________________________________________________________________________________________________________________________________

import java.util.ArrayList; /** * A class for an ElectronicsStore. You are to complete the following: * * - Initialization of the array lists in the constructor * - The addComputerStock method * - The addTVStock method */ public class ElectronicsStore { private ArrayList computers; private ArrayList tvs; public ElectronicsStore() { //-----------Start below here. To do: approximate lines of code = 2 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } public int getNumberComputers() { return computers.size(); } public int getNumberOfTVs() { return tvs.size(); } public Computer getComputer(int index) { return computers.get(index); } public TV getTV(int index) { return tvs.get(index); } public void addComputerStock(Computer computer) { //-----------Start below here. To do: approximate lines of code = 5 // // Check if the computer is already in the computers array list. // If it isn't, add a copy to the array list (NOT THE ORIGINAL REFERENCE) // If it is, then just add the new stock to the computer already in the array list // The arrayList.indexOf(element) command may be helpful for this. It finds the // element in arrayList and returns its index. If it isn't there, it returns -1 // Note, that indexOf uses equals, so that must be implemented correctly //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } public void addTVStock(TV tv) { //-----------Start below here. To do: approximate lines of code = 5 // // Check if the tv is already in the tvs array list. // If it isn't, add a copy to the array list (NOT THE ORIGINAL REFERENCE) // If it is, then just add the new stock to the tv already in the array list // The arrayList.indexOf(element) command may be helpful for this. It finds the // element in arrayList and returns its index. If it isn't there, it returns -1 // Note, that indexOf uses equals, so that must be implemented correctly //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } } 
___________________________________________________________________ /** * Tests the different components of an ElectronicsStore */ public class ElectronicsStoreTester { public static void main(String[] args) { TV tv1 = new TV("LG Smart TV", TV.Type.LED, 45.0); tv1.addStock(50); TV tv2 = new TV("LG Smart TV", TV.Type.LED, 45.0); tv2.addStock(100); TV tv3 = new TV("Sony Bravia", TV.Type.OLED, 55.0); tv3.addStock(75); Computer c1 = new Computer("Macbook Pro", 13, 16, 256); c1.addStock(25); Computer c2 = new Computer("Macbook Pro", 13, 16, 128); c2.addStock(35); Computer c3 = new Computer("Macbook Pro", 13, 16, 256); c3.addStock(67); System.out.println("--- TEST 1: Test that toString works correctly"); System.out.println("OUTPUT: " + tv1); System.out.println("EXPECTED: Model: LG Smart TV, Stock: 50, Type: LED, Screen Size: 45.0"); System.out.println("OUTPUT: " + c1); System.out.println("EXPECTED: Model: Macbook Pro, Stock: 25, Screen Size: 13.0, RAM: 16.0, hdSpace: 256.0"); System.out.println(" --- TEST 2: Check equals"); System.out.println("tv1 equals tv2?"); System.out.println("OUTPUT: " + tv1.equals(tv2)); System.out.println("EXPECTED: true"); System.out.println(" tv1 equals tv3?"); System.out.println("OUTPUT: " + tv1.equals(tv3)); System.out.println("EXPECTED: false"); System.out.println(" c1 equals c2?"); System.out.println("OUTPUT: " + c1.equals(c2)); System.out.println("EXPECTED: false"); System.out.println(" c1 equals c3?"); System.out.println("OUTPUT: " + c1.equals(c3)); System.out.println("EXPECTED: true"); System.out.println(" --- TEST 3: Check Store Initialization"); ElectronicsStore store = new ElectronicsStore(); System.out.println("OUTPUT: " + store.getNumberComputers()); System.out.println("EXPECTED: " + 0); System.out.println(" OUTPUT: " + store.getNumberOfTVs()); System.out.println("EXPECTED: " + 0); // add products store.addTVStock(tv1); store.addTVStock(tv2); store.addTVStock(tv3); store.addComputerStock(c1); store.addComputerStock(c2); store.addComputerStock(c3); System.out.println(" --- TEST 4: Test addTVStock"); System.out.println("check right number of stored tvs"); System.out.println("OUTPUT: " + store.getNumberOfTVs()); System.out.println("EXPECTED: 2"); System.out.println(" check right values for TVs"); System.out.println("OUTPUT: " + store.getTV(0)); System.out.println("EXPECTED: Model: LG Smart TV, Stock: 150, Type: LED, Screen Size: 45.0"); System.out.println("OUTPUT: " + store.getTV(1)); System.out.println("EXPECTED: Model: Sony Bravia, Stock: 75, Type: OLED, Screen Size: 55.0"); System.out.println(" check tv1 copied and not stored"); System.out.println("OUTPUT: " + tv1); System.out.println("EXPECTED: Model: LG Smart TV, Stock: 25, Type: LED, Screen Size: 45.0"); System.out.println(" --- TEST 5: Test addTVStock"); System.out.println("check right number of stored computers"); System.out.println("OUTPUT: " + store.getNumberComputers()); System.out.println("EXPECTED: 2"); System.out.println(" check right values for Computers"); System.out.println("OUTPUT: " + store.getComputer(0)); System.out.println("EXPECTED: Model: Macbook Pro, Stock: 92, Screen Size: 13.0, RAM: 16.0, hdSpace: 256.0"); System.out.println("OUTPUT: " + store.getComputer(1)); System.out.println("EXPECTED: Model: Macbook Pro, Stock: 35, Screen Size: 13.0, RAM: 16.0, hdSpace: 128.0"); System.out.println(" check tv1 copied and not stored"); System.out.println("OUTPUT: " + c1); System.out.println("EXPECTED: Model: Macbook Pro, Stock: 25, Screen Size: 13.0, RAM: 16.0, hdSpace: 256.0"); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!