当前位置: 首页 > news >正文

html5在线网站城镇建设部网站

html5在线网站,城镇建设部网站,小城镇建设网站答案,网站开发工程师专业臣无祖母#xff0c;无以至今日#xff0c;祖母无臣#xff0c;无以终余年 母孙二人#xff0c;更相为命#xff0c;是以区区不能废远 —— 陈情表.李密 —— 24.2.20 一、编写JavaBean public class Student {//学号private int id;//姓名private String name;//年龄pr… 臣无祖母无以至今日祖母无臣无以终余年 母孙二人更相为命是以区区不能废远                                                 ——  陈情表.李密                                                              —— 24.2.20 一、编写JavaBean public class Student {//学号private int id;//姓名private String name;//年龄private int age;//性别private String sex;public Student() {}public Student(int id,String name,int age,String sex) {this.age age;this.name name;this.id id;this.sex sex;}public int getAge() {return age;}public void setAge(int age) {this.age age;}public String getName() {return name;}public void setName(String name) {this.name name;}public int getId() {return id;}public void setId(int id) {this.id id;}public String getSex() {return sex;}public void setSex(String sex) {this.sex sex;} }二、添加功能 addStudent() private void addStudent() {System.out.println(添加功能);//1.键盘录入学生信息System.out.println(请您输入学生学号);int id sc.nextInt();System.out.println(请您输入学生姓名);String name sc.next();System.out.println(请您输入学生年龄);int age sc.nextInt();System.out.println(请您输入学生性别);String sex sc.next();//2.将学生信息封装到Student对象中Student student new Student(id,name,age,sex);//3.将封装好的Student对象放到students数组中students[count] student;//4.count记录存储了多少个对象count ;System.out.println(添加成功);} 三、查看功能 findAllStudent() private void findAllStudent() {System.out.println(学号 姓名 年龄 性别);//排序为了防止删除后在添加原序号代表学生导致发生乱序结果for (int i 0; i count-1; i) {for (int j 0; j count-1-i; j) {if(students[i].getId()students[i1].getId()){Student temp students[i];students[i] students[i1];students[i1] temp;}}}//如果count0 证明没有添加学生if(count 0){System.out.println(对不起该班级尚未添加学生);}else {for (int i 0; i count; i) {System.out.println( students[i].getId() students[i].getName() students[i].getAge() students[i].getSex());}}} 四、修改功能 deleteStudent private void updateStudent() {//1.录入要修改的学生学号System.out.println(请您录入要修改的学生学号);int id sc.nextInt();/*2.注意修改之后不能直接将id当索引去存储新的学生对象原因id和学生在数组中的索引不是对应的解决根据id查询对应的学生在数组中的索引位置*/int updateIndex ArrayUtils.findIndexById(students,id,count);System.out.println(请您输入学生姓名:);String name sc.next();System.out.println(请您输入学生年龄);int age sc.nextInt();System.out.println(请您输入学生性别);String sex sc.next();Student student new Student(id,name,age,sex);students[updateIndex] student;System.out.println(修改成功);} 五、删除功能 deleteStudent private void deleteStudent() {//1.要输入要删除的学生学号System.out.println(请您输入要删除的学生学号);int id sc.nextInt();//2.根据id查询学生对应的索引位置int removeIndex ArrayUtils.findIndexById(students,id,count);//复制被删除元素前面一部分System.arraycopy(students,0,newStudents,0,removeIndex);//在复制被删除元素后面一部分System.arraycopy(students,removeIndex1,newStudents,removeIndex,students.length-removeIndex-1);//将新数组的地址值给老数组students newStudents;//删除完之后count--count--;System.out.println(删除成功); }六、退出功能 public void start(){while(true){System.out.println(——————————学生管理系统——————————);System.out.println( 1 添加学生 );System.out.println( 2 修改学生 );System.out.println( 3 删除学生 );System.out.println( 4 查看学生 );System.out.println( 5 退出系统 );System.out.println( 请选择1~5: );int num sc.nextInt();System.out.println(——————————————————————————————);switch (num){case 1:addStudent();break;case 2:updateStudent();break;case 3:deleteStudent();break;case 4:findAllStudent();break;case 5:System.out.println(是否退出按0为退出/按9为取消);int key sc.nextInt();if(key0){System.out.println(再见欢迎下次使用!);return;//结束方法}else if(key 9){break;}default:System.out.println(输入数字有误);}}} 七、总代码 1.增删改查方法 import java.lang.reflect.Array; import java.util.Scanner;public class StudentView {//后面会反复键盘录入所以Scanner键盘录入方法放在开头Scanner sc new Scanner(System.in);/*老数组长度为50代表班级最多能放50个人后面每个功能都需要使用数组所以可以将数组放到成员位置*/Student[] students new Student[50];/*定义一个count变量记录数组中有多少个对象遍历元素不能全部遍历因为没有存对象的位置遍历出来是null在调用get xxx方法会出现空指针所以我们应该记录存储对象的个数存多少个对象就遍历多少次而且后面可能会反复使用count所以提到成员位置*/int count 0;/*新数组一会删除元素的时候需要将删除后剩下的元素复制到新数组中因为数组定长不能直接在原来的数组基础上随意改变长度由于一次删一个所以新数组长度为老数组长度-1后面可能会反复使用新数组所以定义到成员位置*/Student[] newStudents new Student[students.length-1];//start方法用于展示页面以及调用对应功能public void start(){while(true){System.out.println(——————————学生管理系统——————————);System.out.println( 1 添加学生 );System.out.println( 2 修改学生 );System.out.println( 3 删除学生 );System.out.println( 4 查看学生 );System.out.println( 5 退出系统 );System.out.println( 请选择1~5: );int num sc.nextInt();System.out.println(——————————————————————————————);switch (num){case 1:addStudent();break;case 2:updateStudent();break;case 3:deleteStudent();break;case 4:findAllStudent();break;case 5:System.out.println(是否退出按0为退出/按9为取消);int key sc.nextInt();if(key0){System.out.println(再见欢迎下次使用!);return;//结束方法}else if(key 9){break;}default:System.out.println(输入数字有误);}}}private void findAllStudent() {System.out.println(学号 姓名 年龄 性别);//排序for (int i 0; i count-1; i) {for (int j 0; j count-1-i; j) {if(students[i].getId()students[i1].getId()){Student temp students[i];students[i] students[i1];students[i1] temp;}}}//如果count0 证明没有添加学生if(count 0){System.out.println(对不起该班级尚未添加学生);}else {for (int i 0; i count; i) {System.out.println( students[i].getId() students[i].getName() students[i].getAge() students[i].getSex());}}}private void deleteStudent() {//1.要输入要删除的学生学号System.out.println(请您输入要删除的学生学号);int id sc.nextInt();//2.根据id查询学生对应的索引位置int removeIndex ArrayUtils.findIndexById(students,id,count);//复制被删除元素前面一部分System.arraycopy(students,0,newStudents,0,removeIndex);//在复制被删除元素后面一部分System.arraycopy(students,removeIndex1,newStudents,removeIndex,students.length-removeIndex-1);//将新数组的地址值给老数组students newStudents;//删除完之后count--count--;System.out.println(删除成功); }private void updateStudent() {//1.录入要修改的学生学号System.out.println(请您录入要修改的学生学号);int id sc.nextInt();/*2.注意修改之后不能直接将id当索引去存储新的学生对象原因id和学生在数组中的索引不是对应的解决根据id查询对应的学生在数组中的索引位置*/int updateIndex ArrayUtils.findIndexById(students,id,count);System.out.println(请您输入学生姓名:);String name sc.next();System.out.println(请您输入学生年龄);int age sc.nextInt();System.out.println(请您输入学生性别);String sex sc.next();Student student new Student(id,name,age,sex);students[updateIndex] student;System.out.println(修改成功);}private void addStudent() {System.out.println(添加功能);//1.键盘录入学生信息System.out.println(请您输入学生学号);int id sc.nextInt();System.out.println(请您输入学生姓名);String name sc.next();System.out.println(请您输入学生年龄);int age sc.nextInt();System.out.println(请您输入学生性别);String sex sc.next();//2.将学生信息封装到Student对象中Student student new Student(id,name,age,sex);//3.将封装好的Student对象放到students数组中students[count] student;//4.count记录存储了多少个对象count ;System.out.println(添加成功);} }2.测试类 main函数 public class Test01 {public static void main(String[] args) {new StudentView().start();} } 3.复制数组内容 public class Test02 {public static void main(String[] args) {int[] arr1 {1,2,3,4,5,6,7,8};int[] arr2 new int[8];/*工具类System静态方法arrayCopy参数1源数组 - 从哪个数组中开始复制参数2从源数组的哪个索引开始复制参数3目标数组 - 复制到哪里去参数4从目标数组的哪个索引开始粘贴参数5复制多少个*/System.arraycopy(arr1,0,arr2,0,3);for (int i 0; i arr2.length; i) {System.out.println(arr2[i]);}} }4.查找数组中与查询学号值相同的索引 public class ArrayUtils {private ArrayUtils(){}public static int findIndexById(Student[] students,int id,int count){//遍历查找for (int i 0; i count; i) {if(id students[i].getId()){return i;}}return -1;} }5.测试运行结果 添加学生 查看学生 删除学生 修改学生  退出系统
http://www.pierceye.com/news/569753/

相关文章:

  • 网站建设亿码酷出名5万站霸屏
  • 仿制网站建设山东关键词优化联系电话
  • 律所网站建设国队男子接力赛有哪些做短租的网站
  • 常用的网站推广方法制作简历模板网站
  • c2c网站有哪些网站可以先做代码么
  • 阿里云简单网站建设wordpress+调整+行距
  • 想自己做网站推广郴州网站建设哪里比较好
  • 实用网站推荐小程序权限超时
  • 济源市建设工程管理处网站wordpress模板搜索功能404
  • 成都三网合一网站建设网站广告收费标准
  • 网站制作咨询电话网站托管费用多少
  • 做网站 需求怎么写成都优化网站源头厂家
  • 我买了一个备案网站 可是公司注销了学服装设计的就业方向
  • 网站后台上传不了图片请人做网站需要注意什么条件
  • 建网站哪家好案例网页设计感悟与体会
  • 做网站要实名吗深圳货拉拉
  • 综合门户网站是什么意思建设机械网站
  • 主题资源网站建设作业高级网站开发工程师考试题
  • 含山建设局网站免费的个人简历模板文档
  • 门户网站建设推荐高校英文网站建设 文献综述
  • 织梦网站备案免费咨询网站
  • wordpress站内搜索插件网站管理程序
  • 网站建设友链交换自己电脑做网站iis
  • 全球优秀企业网站做原型的素材网站
  • 单页面营销网站怎么用polylang做网站
  • 网站开发入那个科目中国网站建设哪家公司好
  • 网站流量提升方案软件公司名称大全查询
  • 怎么做淘客专属网站济南公司网站推广优化最大的
  • 苏州网站建设极简幕枫织梦模板网站源码
  • 青岛网站设计定制2023传奇手游排行榜