Java实验 学生通讯录系统.docx

上传人:牧羊曲112 文档编号:3159638 上传时间:2023-03-11 格式:DOCX 页数:23 大小:42.72KB
返回 下载 相关 举报
Java实验 学生通讯录系统.docx_第1页
第1页 / 共23页
Java实验 学生通讯录系统.docx_第2页
第2页 / 共23页
Java实验 学生通讯录系统.docx_第3页
第3页 / 共23页
Java实验 学生通讯录系统.docx_第4页
第4页 / 共23页
Java实验 学生通讯录系统.docx_第5页
第5页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《Java实验 学生通讯录系统.docx》由会员分享,可在线阅读,更多相关《Java实验 学生通讯录系统.docx(23页珍藏版)》请在三一办公上搜索。

1、Java实验 学生通讯录系统 成绩: 面向对象原理与Java实践课程实验报告 实验1:对象和类 姓 名 _ _ 班 级 _ _ 学 号 _ _ 实验地点 _ _ 实验时间 _ _ 指导教师 _ _ 面向对象原理与Java实践课程实验报告 实验1:对象和类 一、实验目的: l l l 掌握类的定义及应用方法 掌握对象的创建方法,了解实例变量、实例方法和静态字段的特性 体会Java在类和对象的设计中体现的面向对象的思想 二、实验要求: l l l l 具备Java基础知识 掌握Java中对象和类的基本概念和应用方法 设计类时注意保证类的封装性 编写程序完成以下实验内容并上交实验报告 三、实验内容:

2、 设计并实现一个“广石化院电信学院学生通信录”系统。系统采用字符界面,在出现的主界面中按提示输入相应字符以选择“增加”、“删除”、“修改”、“查找”等功能进行操作。记录的存储可采用数组或链表的方式。 四、设计思路: 为了实现该系统,首先要需要两个类;一个类为主界面服务,用于接收用户输入信息以及做出相关反应;一个类为学生信息服务,定义学生通讯录信息的各个字段,以及操作字段的各个方法,考虑到部分字段的属性问题,所以将操作方法都写在学生类中,不再另外放置在其他类中。学生信息将会采用学生类的对象数组来储存。 五、程序源代码: 下面是ZhuJieMian 主界面类 package pkg_TXL; im

3、port java.util.Scanner; public class ZhuJieMian /* * * 该类为通讯录系统的主界面提供主要功能显示,以及负责主菜单与子菜单的正常跳转 */ public static void main(String args) ); / TODO Auto-generated method stub /XueShengXinXi Stu=ChuShiHua; /初始化系统数据 XueShengXinXi Stu=new XueShengXinXi100; Stu0=new XueShengXinXi(专业, 班级, 姓名, 性别, 电话, 家庭住址 Stu

4、1=new XueShengXinXi(自动化, 自动化10-1, 张三, 男, 63256, fnhjfdhsdbh); Stu2=new XueShengXinXi(自动化, 自动化10-2, 李四, 女, 653256, nfhggdfddhsdbh); Stu3=new XueShengXinXi(电子, 电子10-1, 王五, 男, 6156, fnhvjbh); Stu4=new XueShengXinXi(电子, 电子10-2, 小红, 女, 63956, asdfnhjbh); Stu5=new XueShengXinXi(网络, 网络10-1, 小明, 男, 656, nfg

5、dgfnhjbh); Stu6=new XueShengXinXi(网络, 网络10-2, 小芳, 女, 62215, nfgdmmmdfhbdsh); Stu7=new XueShengXinXi(计算机, 计算机10-1, 黄龙, 男, 65584, bbbdddfnhjbh); Stu8=new XueShengXinXi(计算机, 计算机10-2, 陈玲, 女, 666114, mjgfddddfnhjbh); Stu9=new XueShengXinXi(测控, 测控10-1, 赵小斌, 男, 644814, fthnrehbkjhjbh); Stu10=new XueShengXi

6、nXi(测控, 测控10-2, 钱颖, 女, 63641, dbfsvnnhjbh); Stu11=new XueShengXinXi(电信, 电信10-1, 孙武, 男, 6321514, mmhmgvvdfnhjbh); Stu12=new XueShengXinXi(电信, 电信10-2, 李雨, 女, 6314, 43ghffvvdfnhjbh); for(int x=13;xStu.length;x+) Stux=new XueShengXinXi; System.out.println(欢迎使用广石化电信学院通讯录系统!); ZhuJieMian: for(int exit=0;e

7、xit=0;)/exit为退出主菜单的指示变量,0为不退出,非0为退出 System.out.println; System.out.println(*); System.out.println(*主菜单*); System.out.print( 1。查询学生信息tt); System.out.println(2。新增学生信息); System.out.print( 3。修改学生信息tt); System.out.println(4。删除学生信息); System.out.print( 5。恢复已被删除信息tt); System.out.println(6。退出); System.out.pr

8、intln(*); System.out.println(*); System.out.print(请选择你要操作的功能序号:); Scanner scn_input=new Scanner(System.in); String XuHao=scn_input.next; System.out.println; if(XuHao.equals(1) /二级菜单查询学生信息 select:for(int exit2=0;exit2=0;) /exit为退出二级菜单的指示变量,0为不退出,非0为退出 System.out.println(*); System.out.println(*二级菜单查询

9、学生信息*); System.out.println(*); System.out.println; System.out.print(请输入要查找的关键字,输入“all”显示全部信息,输入“back”返回主菜单:); String str_KeyWord=scn_input.next; System.out.println; if(str_KeyWord.equals(all) System.out.println; System.out.println(*学生通讯录信息*); XueShengXinXi.Show(Stu); System.out.println; System.out.p

10、rintln; continue select; else if(str_KeyWord.equals(back) continue ZhuJieMian; else int index=XueShengXinXi.Select(str_KeyWord,Stu); if(index0=0) System.out.println(抱歉,没有找到关于“+str_KeyWord+”的学生信息!); System.out.println; continue select; else System.out.println(*学生通讯录信息*); XueShengXinXi.Show(Stu,index)

11、; System.out.println; System.out.println; continue select; else if(XuHao.equals(2) /二级菜单新增学生信息 insert:for(int exit3=0;exit3=0;) System.out.println; System.out.println(*); System.out.println(*二级菜单新增学生信息*); System.out.println(*); System.out.println; System.out.println(请按右边的格式输入新增学生的专业/班级/姓名/性别/电话/地址信息

12、,输入“back”返回主菜单:); String str_Stu=scn_input.next; if(str_Stu.equals() System.out.println(输入有误,请重新输入!); continue insert; else if(str_Stu.equals(back) System.out.println; continue ZhuJieMian; else boolean zuoFei=XueShengXinXi.Insert(Stu, str_Stu); if(zuoFei=true) System.out.println; System.out.println(

13、由于学生信息必填项信息缺失,所以新增失败。返回至二级菜单.); System.out.println; continue insert; else System.out.println; System.out.println(新增成功!返回至二级菜单.); System.out.println; continue insert; /exit3=1; else if(XuHao.equals(3) /二级菜单修改学生信息 System.out.println(*); System.out.println(*二级菜单修改学生信息*); System.out.println(*); System.o

14、ut.println; System.out.println(*学生通讯录信息*); XueShengXinXi.Show(Stu); /System.out.println; update:for(int exit4=0;exit4=0;) /exit为退出二级菜单的指示变量,0为不退出,非0为退出 System.out.println; System.out.print(请输入要修改的学生前的序号,输入“back”返回主菜单:); String str_XuHao=scn_input.next; System.out.println; if(str_XuHao.equals(back) S

15、ystem.out.println; continue ZhuJieMian; else int id=XueShengXinXi.Str_Int(Stu,str_XuHao,false); if(id0Stu.length&id0!=0) System.out.println; /int index=XueShengXinXi.Select_index(Stu, id0); System.out.println(该学生信息如下:); System.out.print(Stuid0.str_ZhuanYe+/+Stuid0.str_BanJi+/); System.out.print(Stui

16、d0.str_XingMing+/+Stuid0.str_XingBie+/); System.out.println(Stuid0.str_DianHua+/+Stuid0.str_DiZhi); System.out.println(请按以上格式输入修改后的信息:); String str_Stu=scn_input.next; XueShengXinXi.Update(Stuid0, str_Stu); System.out.println(修改成功!已返回二级菜单); System.out.println; System.out.println(*); System.out.print

17、ln(*二级菜单修改学生信息*); System.out.println(*); System.out.println; System.out.println(*学生通讯录信息*); XueShengXinXi.Show(Stu); continue update; else System.out.println(输入有误!已返回至二级菜单); continue update; /exit4=1; else if(XuHao.equals(4) /二级菜单删除学生信息 System.out.println(*); System.out.println(*二级菜单删除学生信息*); System

18、.out.println(*); System.out.println; System.out.println(*学生通讯录信息*); XueShengXinXi.Show(Stu); delete:for(int exit5=0;exit5=0;) /exit为退出二级菜单的指示变量,0为不退出,非0为退出 System.out.println; /System.out.println(*二级菜单删除学生信息*); System.out.print(请输入要删除的学生信息前的序号,输入“all”删除全部信息,输入“back”返回主菜单:); String str_xuHao=scn_inpu

19、t.next; System.out.println; if(str_xuHao.equals(back) System.out.println; continue ZhuJieMian; else if(str_xuHao.equals(all) XueShengXinXi.Delete_All(Stu); System.out.println(全部数据已被删除,已返回主菜单。); /XueShengXinXi.Show(Stu); continue ZhuJieMian; else int id=XueShengXinXi.Str_Int(Stu,str_xuHao,false); if(

20、id0Stu.length) /System.out.println; XueShengXinXi.Delete_index(Stu, id); /System.out.println(删除成功!已返回二级菜单); System.out.println; System.out.println(*); System.out.println(*二级菜单删除学生信息*); System.out.println(*); System.out.println; System.out.println; System.out.println(*学生通讯录信息*); XueShengXinXi.Show(St

21、u); continue delete; else System.out.println(输入有误!已返回至二级菜单); continue delete; /exit5=1; else if(XuHao.equals(5) /二级菜单恢复已被删除信息 System.out.println(*); System.out.println(*二级菜单恢复已被删除信息*); System.out.println(*); System.out.println; System.out.println(*回收站信息*); boolean bol=XueShengXinXi.Show_Del(Stu); if

22、(bol=true) System.out.println; System.out.println(回收站为空,目前没有被删除的信息!已返回至主菜单。); continue ZhuJieMian; else recover:for(int exit6=0;exit6=0;) /exit为退出二级菜单的指示变量,0为不退出,非0为退出 System.out.println; /System.out.println(*二级菜单删除学生信息*); System.out.print(请输入要恢复的信息的序号,输入“all”恢复全部信息,输入“back”返回主菜单:); String str_xuHao

23、=scn_input.next; System.out.println; if(str_xuHao.equals(back) System.out.println; continue ZhuJieMian; else if(str_xuHao.equals(all) XueShengXinXi.Recover_All(Stu); System.out.println(全部恢复完毕!已返回主菜单。); continue ZhuJieMian; else int id=XueShengXinXi.Str_Int(Stu,str_xuHao,true); if(id0Stu.length) /Sys

24、tem.out.println; XueShengXinXi.Recover_index(Stu, id); /System.out.println(删除成功!已返回二级菜单); System.out.println; System.out.println(*); System.out.println(*二级菜单恢复已被删除信息*); System.out.println(*); System.out.println; System.out.println; System.out.println(*回收站信息*); XueShengXinXi.Show_Del(Stu); continue r

25、ecover; else System.out.println(输入有误!已返回至二级菜单); continue recover; else if(XuHao.equals(6) break ZhuJieMian; else System.out.println(输入有误,已返回主菜单!); System.out.println; continue ZhuJieMian; /exit=1; 下面是XueShengXinXi 学生信息类 package pkg_TXL; public class XueShengXinXi String str_ZhuanYe=; String str_BanJ

26、i=; /String str_XueHao=; String str_XingMing=; String str_XingBie=; String str_DianHua=; String str_DiZhi=; Boolean bol_ZuoFei=true; /String str_ID=; int int_ID=0; XueShengXinXi /有参构造方法 public XueShengXinXi(String ZhuanYe,String BanJi,String XingMing,String XingBie,String DianHua,String DiZhi) str_Z

27、huanYe=ZhuanYe; str_BanJi=BanJi; str_XingMing=XingMing; str_XingBie=XingBie; str_DianHua=DianHua; str_DiZhi=DiZhi; bol_ZuoFei=false; /新增学生信息的函数 public static boolean Insert(XueShengXinXi stu,String str_stu) int i=0; for(;istu.length;i+) if(stui.bol_ZuoFei=true) break; stui.str_ZhuanYe=; stui.str_Ban

28、Ji=; stui.str_XingMing=; stui.str_XingBie=; stui.str_DianHua=; stui.str_DiZhi=; int k=0; for(int j=1;j=str_stu.length;j+) if(str_stu.substring(j-1, j).equals(/) k+=1; /index=j; else /System.out.println(k); if(k=0) /stui.str_ZhuanYe=str_stu.substring(index, j); stui.str_ZhuanYe=stui.str_ZhuanYe+str_s

29、tu.substring(j-1, j); else if(k=1) /stui.str_BanJi=str_stu.substring(index, j); stui.str_BanJi=stui.str_BanJi+str_stu.substring(j-1, j); else if(k=2) /stui.str_XingMing=str_stu.substring(index, j); stui.str_XingMing=stui.str_XingMing+str_stu.substring(j-1, j); else if(k=3) /stui.str_XingBie=str_stu.

30、substring(index, j); stui.str_XingBie=stui.str_XingBie+str_stu.substring(j-1, j); else if(k=4) /stui.str_DianHua=str_stu.substring(index, j); stui.str_DianHua=stui.str_DianHua+str_stu.substring(j-1, j); else if(k=5) /stui.str_DiZhi=str_stu.substring(index, j); stui.str_DiZhi=stui.str_DiZhi+str_stu.s

31、ubstring(j-1, j); if(stui.str_ZhuanYe.equals()|stui.str_BanJi.equals()|stui.str_XingMing.equals() stui.bol_ZuoFei=true; stui.str_ZhuanYe=; stui.str_BanJi=; stui.str_XingMing=; stui.str_XingBie=; stui.str_DianHua=; stui.str_DiZhi=; else stui.bol_ZuoFei=false; return stui.bol_ZuoFei; public static voi

32、d Show(XueShengXinXi stu) /格式化的输出全部学生的信息 int col=new int6; /定义六个int类型变量,分别存储六列宽度 for(int x=0;xcol.length;x+) colx=0; for(int j=0;jcol0&stuj.bol_ZuoFei=false) col0=stuj.str_ZhuanYe.length; if(stuj.str_BanJi.lengthcol1&stuj.bol_ZuoFei=false) col1=stuj.str_BanJi.length; if(stuj.str_XingMing.lengthcol2&stuj.bol_ZuoFei=false) col2=stuj.str_XingMing.l

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号