用java数组实现学生管理_第1页
用java数组实现学生管理_第2页
用java数组实现学生管理_第3页
用java数组实现学生管理_第4页
用java数组实现学生管理_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

建立一个Student类代码如下package .xcu.student;import java.util.Scanner;public class Student publicint Id; publicString Name; publicint Age; publicString Sex; public double Height; Student stu=new Student20; Scanner scan =new Scanner(System.in); public Student(int id, String name,int age,String sex,double height) this.Id=id; this.Name=name; this.Age=age; this.Sex=sex; this.Height=height; public Student() Student stu1=new Student(100, 王彦, 21, 男, 170); Student stu2=new Student(101, 李浩洋, 21, 男, 170); Student stu3=new Student(102, 张虎成, 21, 男, 170); Student stu4=new Student(103, 朱克飞, 21, 男, 170); Student stu5=new Student(104, 常亚平, 21, 女, 170); stu0=stu1; stu1=stu2; stu2=stu3; stu3=stu4; stu4=stu5; /* * * 添加一个学生的信息的方法 */public void add (Student m) int c=0; for (int i = 0; i stu.length; i+) if(stui=null) System.out.println(学号); m.Id=scan.nextInt(); System.out.println(姓名); m.Name=scan.next(); System.out.println(年龄); m.Age=scan.nextInt(); System.out.println(性别); m.Sex=scan.next(); System.out.println(身高); m.Height=scan.nextDouble(); for (int j = 0; j stu.length; j+) if(stuj!=null)c+; stuc=m; System.out.println(添加成功); break; /*删除一个学生信息的方法 * 通过得到学生的学号,删除该同学的信息 */ public void delete(int id1) for (int i = 0; i stu.length; i+) if(stui.Id=id1) System.out.println(删除成功); stui=null; for (int j = i; j stu.length-1; j+) stuj=stuj+1; /将后面的值依次向前一个数组赋值 break; /* * * 修改一个学生的方法 * */ public void XiuGai(int id2 ,Student m) for (int i = 0; i stu.length; i+) if(stui.Id=id2)System.out.println(修改后学号); m.Id=scan.nextInt(); System.out.println(修改后姓名); m.Name=scan.next(); System.out.println(修改后年龄); m.Age=scan.nextInt(); System.out.println(修改后性别); m.Sex=scan.next(); System.out.println(修改后身高); m.Height=scan.nextDouble(); stui=m; System.out.println(修改成功,修改后为); System.out.println(學號 +stui.Id+ 姓名 +stui.Name+ 年齡 +stui.Age+ 性別 +stui.Sex+ 身高 +stui.Height); break; /* * 根据一个学生的学号查找一个的信息 * */ public void selectId(int id) /*for (int j = 0; j stu.length; j+) if(stuj.Id!=id) System.out.println(查找失败,请重新输入); */ for (int i = 0; i stu.length; i+) if(stui.Id=id) System.out.println(學號 +stui.Id+ 姓名 +stui.Name+ 年齡 +stui.Age+ 性別 +stui.Sex+ 身高 +stui.Height); break; /* * 遍历所有学生的信息 */ public void selectAll() for (int i = 0; i stu.length; i+) if(stui!=null) System.out.println(i+學號 +stui.Id+ 姓名 +stui.Name+ 年齡 +stui.Age+ 性別 +stui.Sex+ 身高 +stui.Height); 在建立个测试类package .xcu.student;import java.util.Scanner;public class StudentManage public static void main(String args) Student Stu=new Student(); System.out.println( t欢迎使用学生管理系统 ); System.out.println(*); System.out.println(*1 增加 2,删除 3。 修改 4.查找 5查询所有学生信息 6 退出 *); System.out.println(*); System.out.println(请输入你要操作序号); Scanner scan =new Scanner(System.in); boolean flag =true; while(flag) int a=scan.nextInt(); switch (a) case 1:System.out.println(请输入添加学生的信息);Stu.add(Stu); /调用添加学生的方法break;case 2:System.out.println(请输入删除学生的学号);int id1=scan.nextInt();Stu.delete(id1); /调用删除学生的方法break;case 3:System.out.println(请输入修改学生的学号);int id2=scan.nextInt();Stu.XiuGai(id2, Stu); /调用修改学生的方法break;case 4:System.out.println(请输入查找学生的学号);int id =scan.nextInt(); Stu.selectId(id); /调用查找学生的方法break;case 5:Stu.selectAll(); /调用查找所有学生的方法break;default:System.out.println(感谢你使用学生管理系统);flag=false;break; Syste

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论