任务1: 教师电话管理系统(数组版)

1.1 任务描述

知识点:类、接口、Java数组、java.io相关工具类的使用

1.2 任务目标

完善以下类与接口中"//to do…"部分代码,实现老师电话管理系统

1.3 任务实现思路

完成教师电话信息的管理(测试类):public class ArrTeacherTelUser
定义顺序表中的数据元素类型(教师电话类):class TeacherTel
接口定义了顺序表的数据操作(顺序表操作接口):class interface TeacTelOPeration
实现接口中的操作(顺序表接口实现类):class ArrTeacTel implements TeacTelOPeration

1.4 任务实现源码

package com.it.Array;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Objects;class TeacherTel { // 定义顺序表中的数据元素类型// 属性定义private String name;private int teacherNo;private String telphone;public TeacherTel() {}// 构造方法public TeacherTel(int teacherNo, String name, String telphone) {this.name = name;this.teacherNo = teacherNo;this.telphone = telphone;}// 成员方法public void setName(String name) {this.name = name;}public void setTeacherNo(int teacherNo) {this.teacherNo = teacherNo;}public void setTelphone(String telphone) {this.telphone = telphone;}public String getName() {return name;}public int getTeacherNo() {return teacherNo;}public String getTelphone() {return telphone;}public String toString() {return this.getTeacherNo() + "," + this.getName() + "," + this.getTelphone();}
}interface TeacTelOPeration { // 此接口定义了顺序表的数据操作int getCounts(); // 获取记录个数void add(TeacherTel node); // 在顺序表的尾部添加一个 教师电话记录void listAll(); // 遍历顺序表中所有教师电话记录void search(int index); // 根据教师编号查询记录void search(String name); // 根据教师姓名查询记录void delete(int index); // 根据教师编号删除记录void delete(String name); // 根据教师姓名删除记录
}class ArrTeacTel implements TeacTelOPeration {// 实现接口中的操作private TeacherTel[] teacTel;// 顺序表,存放教师电话信息private int count = 0;// 记录记数器,当前顺序表中的记录个数ArrTeacTel(int initialCapacity) {// 创建指定容量的顺序表teacTel = new TeacherTel[initialCapacity];}public int getCounts() {// 获取教师电话记录个数return count;}// 在顺序表添加一个教师电话信息记录,并且在添加时按教师编号 从小到大的 顺序插入结点public void add(TeacherTel node) {if (count == 0) {//to do...teacTel[0] = node;count++;System.out.println("添加新教师电话信息成功!");} else {int flag = 0;for (int i = 0; i < count; i++) {//to do...如果新加入的编号比原来的小,则后移一位if (teacTel[i].getTeacherNo() == node.getTeacherNo()) {break;}else if(teacTel[i].getTeacherNo() > node.getTeacherNo()){count++;TeacherTel TEA1 = teacTel[i];//原来的编号teacTel[i] = node;//新编号for (int j = i + 1; j <= count; j++) {TeacherTel TEA2 = teacTel[j];//原来编号的后一位j=i+1teacTel[j] = TEA1;//后移TEA1 = TEA2;}flag = 1;System.out.println("添加新教师电话信息成功!");break;}if (i == count - 1) {flag = 1;teacTel[count] = node;count++;System.out.println("添加新教师电话信息成功!");}}if (flag == 0) {//to do...System.out.println("该教师电话信息已存在,请重新选择!");}}if (count == teacTel.length)System.out.println(" 存储空间已满");}public void listAll() {// 遍历顺序表中所有教师电话记录if (count == 0)System.out.println("没有记录!");for (int i = 0; i < count; i++) {//to do...System.out.println(teacTel[i].toString());}System.out.println("共有教师记录"+count+"条");}public void search(int teacherNo) { // 根据教师编号查询记录int flag = 0;for (int i = 0; i < count; i++) {//to do...if(teacTel[i].getTeacherNo()==teacherNo){flag=1;System.out.println(teacTel[i].toString());break;}System.out.println("共有教师记录"+count+"条");}if (flag == 0)System.out.println("输入的编号无效!");}public void search(String name) { // 根据教师姓名查询记录int flag = 0;for (int i = 0; i < count; i++) {//to do...if(Objects.equals(teacTel[i].getName(), name)){System.out.println(teacTel[i].toString());flag=1;break;}System.out.println("共有教师记录"+count+"条");}if (flag == 0)System.out.println("查无此人");}public void delete(int teacherNo) { // 根据教师编号删除记录int flag = 0;for (int i = 0; i < count; i++) {if (teacTel[i].getTeacherNo() == teacherNo) {//to do...for(int j=i+1;j<count;j++){teacTel[j-1]=teacTel[j];}flag=1;count--;System.out.println("删除成功!");break;}}if (flag == 0)System.out.println("查无此人");}public void delete(String name) { // 根据教师姓名删除记录int flag = 0;for (int i = 0; i < count; i++) {if (teacTel[i].getName().equals(name)) {//to do...for(int j=i+1;j<count;j++){teacTel[j-1]=teacTel[j];}flag=1;count--;System.out.println("删除成功!");break;}}if (flag == 0)System.out.println("查无此人!");}
}
public class ArrTeacherTelUser {// 完成教师电话信息的管理public static void main(String args[]) throws IOException {ArrTeacTel teacTel = new ArrTeacTel(20); // 根据实际情况初始化数组的大小BufferedReader br = new BufferedReader(new InputStreamReader(System.in));//BufferedReader(缓冲区读取内容,避免中文乱码)while (true) {System.out.print("********教师电话管理系统**********\n");System.out.print("1 增加记录\n");System.out.print("2 显示所有信息\n");System.out.print("3 根据教师编号查找记录\n");System.out.print("4 获取教师电话信息记录个数\n");System.out.print("5 根据编号删除记录\n");System.out.print("6 根据教师姓名查找记录\n");System.out.print("7 根据教师姓名删除记录\n");System.out.print("0 退出\n\n");//to do ..System.out.print("请输入你的选择:");int choice = Integer.parseInt(br.readLine());switch (choice) {case 0:System.exit(0);case 1:System.out.print("\n请输入教师编号:");int TeacNum = Integer.parseInt(br.readLine());System.out.print("请输入姓名:");String TeacName = br.readLine();System.out.print("请输入电话号码:");String TeacTelphone = br.readLine();///TeacherTel Teacnode = new TeacherTel(TeacNum, TeacName,TeacTelphone);teacTel.add(Teacnode);/System.out.println();break;case 2:teacTel.listAll();System.out.println();break;case 3:System.out.print("\n请输入教师编号:");int teacherNo = Integer.parseInt(br.readLine());teacTel.search(teacherNo);System.out.println();break;case 4:System.out.println("教师电话记录个数为:" + teacTel.getCounts());break;case 5:System.out.println("请输入要删除记录的教师编号");int teacherId = Integer.parseInt(br.readLine());teacTel.delete(teacherId);System.out.println();break;case 6:System.out.println("请输入要查询记录的教师姓名");String name1 = br.readLine();teacTel.search(name1);System.out.println();break;case 7:System.out.println("请输入要删除的教师姓名");String name = br.readLine();teacTel.delete(name);System.out.println();break;}//switch}//while}//main}

1.5 任务运行结果图示

任务2: 教师电话管理系统(链表版)

2.1 任务描述

知识点:链表、类、接口、java.io相关工具类的使用

2.2 任务目标

完善以下类与接口中"//to do…"部分代码,实现老师电话管理系统

2.3 任务实现思路

完成教师电话信息的管理(测试类:public class LinkTeacTelUser
定义链表中的数据元素类型(教师电话类):class TeacherTel
接口定义了链表的数据操作(操作接口):interface TeacTelOPeration
实现接口中的操作(接口实现类):class LinkTeacTel implements TeacTelOPeration

2.4 任务实现源码

package ChainTable;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;class TeacherTel { // 定义链表中的数据元素类型// 属性定义private String name;private int teacherNo;private String telphone;private TeacherTel next;//下一个节点对象的信息public TeacherTel() {}// 构造方法public TeacherTel(int teacherNo, String name, String telphone) {this.name = name;this.teacherNo = teacherNo;this.telphone = telphone;}// 成员方法public void setName(String name) {this.name = name;}public void setTeacherNo(int teacherNo) {this.teacherNo = teacherNo;}public void setTelphone(String telphone) {this.telphone = telphone;}public void setNext(TeacherTel node) {this.next = node;}public String getName() {return name;}public int getTeacherNo() {return teacherNo;}public String getTelphone() {return telphone;}public TeacherTel getNext() {return next;}public String toString() {//输出return this.getTeacherNo() + "," + this.getName() + "," + this.getTelphone();}
}interface TeacTelOPeration { // 此接口定义了链表的数据操作int getCounts(); // 获取记录个数//在链表添加一个教师电话信息记录,并且在添加时按教师编号从小到大的顺序插入结点void add(TeacherTel node);void listAll(); // 遍历链表中所有教师电话记录void search(int index); // 根据教师编号查询记录void search(String name); // 根据教师姓名查询记录void delete(int index); // 根据教师编号删除记录void delete(String name); // 根据教师姓名删除记录
}class LinkTeacTel implements TeacTelOPeration {// 实现接口中的操作private TeacherTel head;  // 链表的头private int count;  // 记录数计数器// 构造方法方法,创建一个空链表LinkTeacTel() {head = null;count = 0;}public int getCounts() {// 获取教师电话记录个数return count;}// 在链表添加一个教师电话信息记录,并且在添加时按教师编号从小到大的顺序插入结点public void add(TeacherTel node) {TeacherTel prior = head, current = head;if (head == null)// 空表head = node;else {// 非空表// 寻找插入位置while (current != null) {//如果新节点小于当前节点,则跳出循环if (node.getTeacherNo() < current.getTeacherNo()){break;}prior = current;current = current.getNext();}// 插入新节点nodeif (current == head) {// 在表头节点前插入nodenode.setNext(head);head = node;} else {// 在表中和表尾某插入nodeprior.setNext(node);node.setNext(current);}}count++;}public void listAll() {// 遍历链表中所有教师电话记录TeacherTel current = head;while (current != null) {System.out.println(current);current = current.getNext();}System.out.println("共有记录" + count + "条");}public void search(int teacherNo) {// 根据教师编号查询记录int flag = 0;TeacherTel current = head;while (current != null) {//to do...if(current.getTeacherNo()==teacherNo){flag=1;System.out.println(current.toString());}current = current.getNext();}if (flag == 0)System.out.println("输入的编号无效!");}public void search(String name) {//根据教师姓名查询记录TeacherTel current = head;int flag = 0;while (current != null) {//to do...if(name.equals(current.getName())){flag=1;System.out.println(current.toString());}current = current.getNext();}if (flag == -1)System.out.println("查无此人");}public void delete(int teacherNo) {//根据教师编号删除记录TeacherTel pre = null;TeacherTel current = head;pre = current;int flag = 0;while (current != null) {//to do...if(current.getTeacherNo()==teacherNo){flag=1;if(current==head){current=current.getNext();head=current;}else {current=current.getNext();pre.setNext(current);}}pre=current;if(current!=null){current=current.getNext();}}if (flag == 0)System.out.println("查无此人!");else {System.out.println("删除成功!");count--;}}public void delete(String name) {//根据教师姓名删除记录TeacherTel pre = null;TeacherTel current = head;pre = current;int flag = 0;while (current != null) {//to do...if(current.getName().equals(name)){flag=1;if(current==head){current=current.getNext();head=current;}else {current=current.getNext();pre.setNext(current);}}pre = current;if(current!=null){current=current.getNext();}}if (flag == 0)System.out.println("查无此人!");else {System.out.println("删除成功!");count--;}}
}public class LinkTeacTelUser {public static void main(String args[]) throws IOException {LinkTeacTel linkTeacTel = new LinkTeacTel();BufferedReader br = new BufferedReader(new InputStreamReader(System.in));while (true) {System.out.print("********教师电话管理系统**********\n");System.out.print("1 增加记录\n");System.out.print("2 显示所有信息\n");System.out.print("3 根据教师编号查找记录\n");System.out.print("4 获取教师电话信息记录个数\n");System.out.print("5 根据编号删除记录\n");System.out.print("6 根据教师姓名查找记录\n");System.out.print("7 根据教师姓名删除记录\n");System.out.print("0 退出\n\n");System.out.print("请输入你的选择:");int choice = Integer.parseInt(br.readLine());switch (choice) {case 0:System.exit(0);case 1:System.out.print("\n请输入教师编号:");int TeacNum = Integer.parseInt(br.readLine());System.out.print("请输入姓名:");String TeacName = br.readLine();System.out.print("请输入电话号码:");String TeacTelphone = br.readLine();TeacherTel Teacnode = new TeacherTel(TeacNum, TeacName,TeacTelphone);linkTeacTel.add(Teacnode);System.out.println();break;case 2:linkTeacTel.listAll();System.out.println();break;case 3:System.out.print("\n请输入教师编号:");int teacherNo = Integer.parseInt(br.readLine());linkTeacTel.search(teacherNo);System.out.println();break;case 4:System.out.println("教师电话记录个数为:" + linkTeacTel.getCounts());break;case 5:System.out.println("请输入要删除记录的教师编号");int teacherId = Integer.parseInt(br.readLine());linkTeacTel.delete(teacherId);System.out.println();break;case 6:System.out.println("请输入要查询记录的教师姓名");String name1 = br.readLine();linkTeacTel.search(name1);System.out.println();break;case 7:System.out.println("请输入要删除的教师姓名");String name = br.readLine();linkTeacTel.delete(name);System.out.println();break;}}}
}

2.5 任务运行结果图示

教师电话管理系统(数组+链表)相关推荐

  1. C语言期末设计不在是千篇一律的学生管理系统,新题设值教师工作量管理系统(数组)。

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一.题目分析? 二.使用步骤 1.流程图 2.代码 总结 前言 题设为模拟学校管理老师工作量程序. 提示:以下是本篇文 ...

  2. c语言课程设老师信息管理,学生和教师信息管理系统C语言课程设计

    学生和教师信息管理系统C语言课程设计 1目 录一.课题内容 -------------------2二.总体设计 -------------------51.系统要求 ---------------- ...

  3. 简单的教师信息管理系统

    前言 本文内容只适合C语言入门者参考 提示:以下是本篇文章正文内容,下面案例可供参考 一.系统具体内容 1.存储教师信息的数据结构----结构体(后续考虑会出单链表).2.相关操作的子函数:增删查改排 ...

  4. 基于QT实现的教师住房管理系统

    基于QT实现的教师住房管理系统 教师住房管理系统 该系统在磁盘中存贮全校住学校宿舍的教师住房信息.对每一住户存贮如下信息: 户主:姓名,性别,职称(教授.副教授.讲师.助教),出生年月,参加工作年月, ...

  5. 教师工资管理系统(C语言)

    [设计目的] 1.教学目的 本课程设计是学生学习完<C 语言程序设计>课程后,进行的一次全面的综合训练,通过课程设计,更好地掌握使用 C 语言进行程序设计的方法,加深对C 语言特点和使用C ...

  6. 教师工资管理系统C语言课程设计

    教师工资管理系统 1.问题描述 每个教师的信息为:教师号.姓名.性别.单位名称.家庭住址.联系电话.基本工资.津贴.生活补贴.应发工资.电话费.水电费.房租.所得税.卫生费.公积金.合计扣款.实发工资 ...

  7. C/C++教师工资管理系统

    C/C++教师工资管理系统 2.教师工资管理系统 题目描逑: 每个教师的月工资信息为:教师号·姓名﹑性别﹑单位名称﹑联系电话﹑基本工资﹑津贴生活补贴﹑应发工资﹑电话费﹑水电费﹑房租﹑所得税﹑卫生费﹑公 ...

  8. 【实训项目】教师工作量管理系统

    目录 一.需求与分析 1. 项目概述 1.1 教师信息处理 1.2 教师工作量数据处理: 1.3 教师综合信息输出 2. 需求分析 3. 模块设计 3.1 功能模块 3.2 所有功能模块的流程图 二. ...

  9. 【java毕业设计】基于javaEE+原生servlet+tomcat的教师工资管理系统设计与实现(毕业论文+程序源码)——教师工资管理系统

    基于javaEE+原生servlet+tomcat的教师工资管理系统设计与实现(毕业论文+程序源码) 大家好,今天给大家介绍基于javaEE+原生servlet+tomcat的教师工资管理系统设计与实 ...

最新文章

  1. 使用hql动态创建对象问题
  2. MySQL基础篇:SELECT几种子句
  3. 【线上分享】机器视觉编码标准与技术进展
  4. 为什么中国天才都往美国跑,可美国人的数学那么槽糕
  5. 不同范数下的余弦定理_第06题 | 从源头追溯「余弦定理」amp; 文理科知识点的异同...
  6. 使用winform来递归实现资源管理器
  7. oracle在线中文文档,Oracle TopLink
  8. java tcp 字节数_服务器无法接收大小超过1500字节的TCP数据包
  9. 搭建外文技术博客程序员都应该有自己的博客
  10. PCL中将回调函数封装到类中
  11. web.config中的ExtensionlessUrlHandler-Integrated-4.0
  12. MATLAB图像检索系统GUI设计
  13. 借用 AWS 服务 CodePipeling + ECS 实现蓝绿发布 (awscli)
  14. 苹果手机网速慢_都2020年了,该不该换5G手机?
  15. 【Android游戏开发详细过程1】Android平台飞机大战游戏APP设计与实现
  16. DOX-HMDN-PEI 阿霉素-二氧化锰-聚乙烯亚胺/PEI-g-PLO(DCA) 聚鸟氨酸-聚乙烯亚胺
  17. Java:class6 继承
  18. html 内嵌iframe,html页面 内嵌iframe
  19. 用C#去读取陀螺仪姿态角度传感器JY61的串口数据
  20. oracle 每3位加逗号,[DB][Oracle]Oracle格式化数字的方法(指定小数点位数,每3位加逗号)...

热门文章

  1. 使用阿里云IoT Studio建立物模型可视化界面
  2. html中判断数组是否为空,jquery如何判断数组是否为空?
  3. 【算法】二叉树常见算法
  4. JavaScript中的二叉搜索树删除节点代码
  5. LaTex安装与更新
  6. 2525道菜谱(让老婆学做菜不用到处找菜谱了)~~
  7. 【硬件设计】如何玩转智能窗帘机器人
  8. android 7.0 添加google play
  9. 计算机关机时间设置方法,win7电脑如何设置关机时间,win7电脑设置关机时间的操作方法...
  10. Matlab中常用机器学习函数