- 1、本文档共10页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 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
您可能关注的文档
- 实验2 热气球的制作.docx
- 实验2 离子交换柱层析分离纯化蔗糖酶.ppt
- 磁电选设备与工艺.ppt
- 磨煤机安装方案.doc
- 实验2-凝集反应-ELISA(双抗原夹心法).ppt
- 实验1阿伏伽德罗常数的测定.ppt
- 磁铁生产工艺.ppt
- 示波器使用.ppt
- 实验2单相半波可控整流电路).doc
- 实验2数据库表.ppt
- 吉林省吉林市第五十五中学2024_2025学年高二政治上学期期末考试试题.doc
- 湖南省醴陵市第一中学2024_2025学年高一地理下学期期中试题含解析.doc
- 北京市西城区2024_2025学年高一政治上学期期末考试试题.doc
- 2024_2025学年高中生物课时跟踪检测十三种群数量的变化含解析新人教版必修3.doc
- 鄂尔多斯专版2024中考物理复习方案第一篇教材梳理课时训练11光现象试题.docx
- 2024年高考地理高考真题和高考模拟题分项版汇编专题18环境保护含解析.doc
- 2025版高考数学总复习第二篇函数导数及其应用第11节导数在研究函数中的应用第二课时利用导数研究函数的极值与最值应用能力提升理含解析.doc
- 广东省潮州市2024_2025学年高一地理下学期期末教学质量检测试题扫描版.doc
- 湖北省襄阳市2024_2025学年高一英语下学期期末考试试题扫描版无答案.doc
- 江苏省徐州市第一中学2024_2025学年高二生物下学期第二次寒假作业检测试题.doc
文档评论(0)