From 70073306f9e4ee45f8f795976c107482a48e64bc Mon Sep 17 00:00:00 2001 From: Kate <119519512+Youta-Joy@users.noreply.github.com> Date: Sun, 6 Jul 2025 14:23:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B8=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Solution.java" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git "a/src/com/school/faang/hashmap/\320\267\320\260\320\264\320\260\321\207\320\260_3/Solution.java" "b/src/com/school/faang/hashmap/\320\267\320\260\320\264\320\260\321\207\320\260_3/Solution.java" index a79ebdb..ced5e25 100644 --- "a/src/com/school/faang/hashmap/\320\267\320\260\320\264\320\260\321\207\320\260_3/Solution.java" +++ "b/src/com/school/faang/hashmap/\320\267\320\260\320\264\320\260\321\207\320\260_3/Solution.java" @@ -1,7 +1,53 @@ package com.school.faang.hashmap.задача_3; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + public class Solution { public static void main(String[] args) { + Map basket = new HashMap<>(); + int counter = 0; + + Product phone = new Product("@qwerty", "Phone 16"); + Product iPhone = new Product("@qwerty", "Phone 16"); + + basket.put(phone, ++counter); + basket.put(iPhone, ++counter); + + System.out.println(basket); + } +} + +class Product { + private String productId; + private String name; + + private Product product; + + public Product(String productId, String name) { + this.productId = productId; + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Product product = (Product) o; + return Objects.equals(productId, product.productId); + } + + @Override + public int hashCode() { + return Objects.hash(productId); + } + @Override + public String toString() { + return "Product{" + + "productId='" + productId + '\'' + + ", name='" + name + '\'' + + '}'; } }