다음은 재고에 제품을 추가하기 위해 내가 만든 Java 코드입니다. 팀장님이 코드가 효율적이지 않다고 알려줬는데, 제품 수가 증가하면 문제가 발생할 것 같아요. 이 문제를 방지하기 위해 코드를 수정하고 코드 내에서 변경사항을 완전히 구현할 수 있는 방법을 알려줄 수 있나요?
importjava.util.ArrayList;importjava.util.List;importjava.util.Random;publicclassProductInventory{privatestaticfinalList<Product>products=newArrayList<>();privatestaticfinalRandomrandom=newRandom();publicstaticvoidmain(String[]args){addProduct("Product1");addProduct("Product2");addProduct("Product3");System.out.println("AllProducts:");for(Productproduct:products){System.out.println("Name: " +product.getName()+",ID: " +product.getId());}}publicstaticvoidaddProduct(StringproductName){StringrandomId;booleanidIsUnique;longstartTime;longendTime;longduration;// Record start timestartTime=System.nanoTime();do{randomId=getRandomId();idIsUnique=true;for(Productproduct:products){if(product.getId().equals(randomId)){idIsUnique=false;System.out.println("ID " +randomId+ " alreadyexists.GeneratinganewID.");break;}}}while(!idIsUnique);products.add(newProduct(productName,randomId));System.out.println("Added " +productName+ " withID: " +randomId);// Record end time and calculate durationendTime=System.nanoTime();duration=endTime-startTime;System.out.println("Timetakentoadd " +productName+": " +duration+ " nanoseconds");}publicstaticStringgetRandomId(){return"ID"+random.nextInt(1000);}}// Product class to store product name and IDclassProduct{privatefinalStringname;privatefinalStringid;publicProduct(Stringname,Stringid){this.name=name;this.id=id;}publicStringgetName(){returnname;}publicStringgetId(){returnid;}}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-11-22(UTC)"],[],[]]