资源描述:
《set、list、map的遍历,存储,查询,删除,插入,set、list、map的遍历,存储,查询,删除,插入》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1、List相关操作/***创建一个Computer类**@authorJohn**/publicclassComputer{intid;StringmotherBoardType;StringcpuType;inthardDiskSize;intmemerySize;StringgraphicsCardType;intcomputerPirce;//Computer构造方法publicComputer(intid,StringmotherBoardType,StringcpuType,inthardD
2、iskSize,intmemerySize,StringgraphicsCardType,intcomputerPirce){super();this.id=id;this.motherBoardType=motherBoardType;this.cpuType=cpuType;this.hardDiskSize=hardDiskSize;this.memerySize=memerySize;this.graphicsCardType=graphicsCardType;this.computerPirc
3、e=computerPirce;}//重写父类toString方法publicStringtoString(){return"编号:"+id+",主板型号:"+motherBoardType+",cpu型号:"+cpuType+",硬盘容量:"+hardDiskSize+",内存容量:"+memerySize+",显卡型号:"+graphicsCardType+",价格:"+computerPirce;}//为计算机添加CPU型号publicvoidaddCpuType(StringcpuType){t
4、his.cpuType=cpuType;}//为计算机添加主板型号publicvoidaddMotherBoardType(StringmotherBoardType){this.motherBoardType=motherBoardType;istheTibetanPlateaupoly.Centercityonlyapopulationofoveronemillion.Xiningislocatedinthe"Tangfangudao"andtheancient"SilkRoad"road,isth
5、eLoessPlateauandtheTibetanPlateau,agriculturalandpastoralareasand,inconjunctionwiththeMinistryofcultureandIslamicculture}//为计算机添加硬盘大小publicvoidaddhardDiskSize(inthardDiskSize){this.hardDiskSize=hardDiskSize;}//为计算机添加内存大小publicvoidaddMemerySize(intmemeryS
6、ize){this.memerySize=memerySize;}//为计算机添加显卡型号publicvoidaddgraphicsCardType(StringgraphicsCardType){this.graphicsCardType=graphicsCardType;}//设置计算机价格publicvoidsetComputerPrice(intcomputerPirce){this.computerPirce=computerPirce;}//获取计算机价格publicintgetComput
7、erPirce(){returncomputerPirce;}}importjava.util.ArrayList;importjava.util.List;importjava.util.Scanner;importcom.John.tools.Computer;/***题目:(1)要求使用ArrayList存储计算机对象,形如:ArrayListcList=new*ArrayList();**(2)为ArrayList对象(例如:上面的cList)添加3个元素
8、。*istheTibetanPlateaupoly.Centercityonlyapopulationofoveronemillion.Xiningislocatedinthe"Tangfangudao"andtheancient"SilkRoad"road,istheLoessPlateauandtheTibetanPlateau,agriculturalandpastoralareasand,inconjunctionwiththeMi