实验五 集合的使用.doc

  1. 1、本文档共10页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
EXP3 课题(项目)名称: 实验五 集合的使用 计划学时: 2 实验类型: 1.演示性□ 2.验证性□ 3.综合性□ 4.设计性□ 5.其它□ 授课日期: 年 月 日 第 周 星期 第 节 实验目的 验证集合的使用 学习集合的应用技术 实验要求 掌握List的使用 掌握Set的使用 掌握Map的使用 理解集合应用技术 实验内容与步骤 集合基本操作 (1)编写存入集合的对象类 class Person { String id; String name; Person(String id,String name) { this.id=id; this.name=name; } public void sleep() { System.out.println(I am Person,I am sleeping); } public void eat() { System.out.println(I am Person,I am eating); } } class Student extends Person { String sno; Student(String id,String name,String sno) { super(id,name); this.sno=sno; } public void study() { System.out.println(I am Student,I am studying); } public void eat() { System.out.println(I am Student); System.out.println(id:+id); System.out.println(name:+name); System.out.println(sno:+sno); System.out.println(eating ..........); } public String toString(){ return Student +ID:+this.id + Name:+this.name + SNo:+this.sno; } } class Teacher extends Person { String tid; Teacher(String id,String name,String tid) { super(id,name); this.tid=tid; } public void tech() { System.out.println(I am Student,I am taching); } public void eat() { System.out.println(I am Teacher); System.out.println(id:+id); System.out.println(name:+name); System.out.println(tid:+tid); System.out.println(eating ..........); } public String toString(){ return Teacher +ID:+this.id + Name:+this.name + Tid:+this.tid; } } (2)创建测试类,完成以下操作 a.创建3个Student的对象,2个Teacher对象 b.创建一个List和一个Set c.将a中创建的5个对象加入到List中 d.将a中创建的5个对象加入到Set中 e.编写一个static方法,可以对b中中创始的集合进行遍历,将集合中每个元素读出来转型为Person对象,并调用eat()方法 public static void travel(Collection collection){ Iterator it = collection.iterator(); } f.尝试删除List和Set中的元素,并在删除前后都调用e中编写的方法对List,Set进行遍历. g.创建一个Map,并将a中创建的三个学生对象,加入到Map中(以SNo为Key) HashMap h.编写一个static 方法,实现对g中创建Map进行遍历,并调用study()方法 public static void travel(Map map){ } i.编写代码测试Set中不能加入重复元素 package Exercise1; import java.util.*; public class Persontest { public static void main(St

文档评论(0)

shuwkb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档