If three classes. First class Good

class Good { String name; double price; public Good(String name, double price) { this.name = name; this.price=price; } } 

Second class OnlineStore

 class OnlineStore { String name; List<Good> goods; public OnlineStore(String name, List<Good> list) { this.name = name; this.goods = list; } } 

Third Class ProductSearchSrvice

 class ProductSearchSrvice { List<OnlineStore> store; public ProductSearchSrvice(List<OnlineStore> store) { if (store.isEmpty()) { throw new IllegalArgumentException(); } } } 

And there is a class where everything happens

 public class Lab10 { public static void main(String[] args){ Good Tuner = new Good("Tuner",350.0); Good Cable_HDMI = new Good("Cable HDMI",29.60); Good Control_panel = new Good("Control panel",150.50); Good Tuner_1 = new Good("Tuner",1323.0); Good Cable_HDMI_1 = new Good("Cable_HDMI",470.0); Good Control_panel_1 = new Good("Control_panel",617.0); Good Tuner_2 = new Good("Tuner",567.89); Good Cable_HDMI_2 = new Good("Cable_HDMI",249.50); Good Control_panel_2 = new Good("Control_panel",850.0); List<Good> listOfMirElectroniki = new ArrayList<Good>(); List<Good> listOfHIKVISION = new ArrayList<Good>(); List<Good> listOfOLX = new ArrayList<Good>(); listOfMirElectroniki.add(Tuner); listOfMirElectroniki.add(Cable_HDMI); listOfMirElectroniki.add(Control_panel); listOfHIKVISION.add(Tuner_1); listOfHIKVISION.add(Cable_HDMI_1); listOfHIKVISION.add(Control_panel_1); listOfOLX.add(Tuner_2); listOfOLX.add(Cable_HDMI_2); listOfOLX.add(Control_panel_2); OnlineStore MirElectroniki = new OnlineStore("Mir Electroniki", listOfMirElectroniki); OnlineStore HIKVISION = new OnlineStore("HIKVISION", listOfHIKVISION); OnlineStore OLX = new OnlineStore("OLX", listOfOLX); } } 

Help me please. I do not understand how to do this. The task is not difficult, but I do not understand something.

  • Here each product is 1 copy. What to look for? Or should the program intuitively understand that, for example, Tuner_1 and Tuner_2 are products of the same category and compare Their prices? - Oleksiy Morenets
  • And how to make them one category? - Nastya Grant
  • You can add a category field in Good . If the task of polymorphism / inheritance, then it is necessary to inherit from class Good 3 classes and then determine by instanceof ... - Oleksiy Morenets

0