Java ArrayList实现班级信息管理系统

网友投稿 200 2022-08-25


Java ArrayList实现班级信息管理系统

ArrayList实现班级信息管理系统,供大家参考,具体内容如下

代码如下:

import java.util.*;

public class Demo1 {

public static void main(String[] args) {

Manage M = new Manage();

Scanner reader = new Scanner(System.in);

while (true) {

System.out.println("0.加载原有信息");

System.out.println("1.添加学生信息");

System.out.println("2.根据信学号查看学生信息");

System.out.println("3.修改学生综合考评成绩");

System.out.println("4.删除学生信息");

System.out.println("5.根据综合考评排名");

System.out.println("6.打印所有学生的信息");

System.out.println("7.退出系统");

System.out.print("请输入您选择的功能【0~7】:");

int x;

x = reader.nextInt();

switch (x) {

case 0:

Student f = new Student("2018", "李小龙", 23, '男', 98.56);

Student g = new Student("2019", "鱼幼薇", 31, '女', 77.42);

Student h = new Student("2020", "季长风", 17, '男', 85.56);

Student o = new Student("2021", "轩辕辰", 12, '男', 56.42);

Student p = new Student("2022", "徐凤年", 25, '男', 95.01);

M.addStudent(f);

M.addStudent(g);

M.addStudent(h);

M.addStudent(o);

M.addStudent(p);

System.out.println("加载信息成功!");

break;

case 1:

String id;

String name;

int age;

char sex;

double result;

System.out.println("请输入学生学号 姓名 年龄 性别 综合考评成绩(中间以空格隔开):");

id = reader.next();

// System.out.println("请输入学生姓名:");

name = reader.next();

// System.out.println("请输入学生年龄:");

age = reader.nextInt();

// System.out.println("请输入学生性别:");

sex = reader.next().charAt(0);

// System.out.println("请输入学生学综合考评成绩:");

result = reader.nextDouble();

Student e = new Student(id, name, age, sex, result);

M.addStudent(e);

System.out.println("添加学生信息成功!");

break;

case 2:

System.out.println("输入您要查询的学号:");

String idd = reader.next();

M.findinfo(idd);

break;

case 3:

System.out.println("输入您要改动学生的学号:");

String iddd = reader.next();

System.out.println("输入您要改成的目的综合考评:");

double resultt = reader.nextDouble();

M.change(iddd, resultt);

break;

case 4:

System.out.println("输入您要删除学生的学号:");

String idddd = reader.next();

M.deleteStu(idddd);

break;

case 5:

M.sort();

System.out.println("排序成功!");

M.PrintInfo();

break;

case 6:

M.PrintInfo();

break;

case 7:

System.out.println("程序已经运行结束,下次见!");

System.exit(0);

break;

case 8:

System.out.println("数字在1~7之间!");

break;

}

}

}

}

//管理学生类

class Manage

{

ArrayList l=null;

public Manage()

{

l=new ArrayList();

}

//添加学生信息

public void addStudent(Student e)

{

l.add(e);

}

//根据信学号查看学生信息

public void findinfo(String id)

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//修改学生综合考评成绩

public void change(String id,double resultt)

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

System.out.println("原有信息:");

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

for(int i=0;i

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

System.out.println("最终信息:");

temp.setResult(resultt);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//删除学生信息

public void deleteStu(String id)

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

l.remove(i);

}

}

System.out.println("删除信息成功!");

}

//根据综合考评排名

public void sort()

{

String tempid;

String tempname;

int tempage;

char tempsex;

double tempresult;

for(int i=0;i

{

Student x=(Student) l.get(i);

for(int j=i+1;j

{

Student y=(Student) l.get(j);

{

if(x.getResult()

{

tempid=x.getId();

x.setId(y.getId());

y.setId(tempid);

tempname=x.getName();

x.setName(y.getName());

y.setName(tempname);

tempage=x.getAge();

x.setAge(y.getAge());

y.setAge(tehttp://mpage);

tempsex=x.getSex();

x.setSex(y.getSex());

y.setSex(tempsex);

tempresult=x.getResult();

x.setResult(y.getResult());

y.setResult(tempresult);

}

}

}

}

}

//打印所有学生的信息

public void PrintInfo()

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//学生类

class Student

{

//成员变量

private String id;

private String name;

private int age;

private char sex;

private double result;

//构造方法

public Student(String id, String name, int age, char sex, double result) {

super();

this.id = id;

this.name = name;

this.age = age;

this.sex = sex;

this.result = result;

}

//所有的setter和getter方法

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public char getSex() {

return sex;

}

public void setSex(char sex) {

this.sex = sex;

}

public double getResult() {

return result;

}

public void setResult(double result) {

this.result = result;

}

}

运行结果:

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//修改学生综合考评成绩

public void change(String id,double resultt)

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

System.out.println("原有信息:");

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

for(int i=0;i

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

System.out.println("最终信息:");

temp.setResult(resultt);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//删除学生信息

public void deleteStu(String id)

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

l.remove(i);

}

}

System.out.println("删除信息成功!");

}

//根据综合考评排名

public void sort()

{

String tempid;

String tempname;

int tempage;

char tempsex;

double tempresult;

for(int i=0;i

{

Student x=(Student) l.get(i);

for(int j=i+1;j

{

Student y=(Student) l.get(j);

{

if(x.getResult()

{

tempid=x.getId();

x.setId(y.getId());

y.setId(tempid);

tempname=x.getName();

x.setName(y.getName());

y.setName(tempname);

tempage=x.getAge();

x.setAge(y.getAge());

y.setAge(tehttp://mpage);

tempsex=x.getSex();

x.setSex(y.getSex());

y.setSex(tempsex);

tempresult=x.getResult();

x.setResult(y.getResult());

y.setResult(tempresult);

}

}

}

}

}

//打印所有学生的信息

public void PrintInfo()

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//学生类

class Student

{

//成员变量

private String id;

private String name;

private int age;

private char sex;

private double result;

//构造方法

public Student(String id, String name, int age, char sex, double result) {

super();

this.id = id;

this.name = name;

this.age = age;

this.sex = sex;

this.result = result;

}

//所有的setter和getter方法

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public char getSex() {

return sex;

}

public void setSex(char sex) {

this.sex = sex;

}

public double getResult() {

return result;

}

public void setResult(double result) {

this.result = result;

}

}

运行结果:

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

System.out.println("原有信息:");

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

for(int i=0;i

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

System.out.println("最终信息:");

temp.setResult(resultt);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//删除学生信息

public void deleteStu(String id)

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

l.remove(i);

}

}

System.out.println("删除信息成功!");

}

//根据综合考评排名

public void sort()

{

String tempid;

String tempname;

int tempage;

char tempsex;

double tempresult;

for(int i=0;i

{

Student x=(Student) l.get(i);

for(int j=i+1;j

{

Student y=(Student) l.get(j);

{

if(x.getResult()

{

tempid=x.getId();

x.setId(y.getId());

y.setId(tempid);

tempname=x.getName();

x.setName(y.getName());

y.setName(tempname);

tempage=x.getAge();

x.setAge(y.getAge());

y.setAge(tehttp://mpage);

tempsex=x.getSex();

x.setSex(y.getSex());

y.setSex(tempsex);

tempresult=x.getResult();

x.setResult(y.getResult());

y.setResult(tempresult);

}

}

}

}

}

//打印所有学生的信息

public void PrintInfo()

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//学生类

class Student

{

//成员变量

private String id;

private String name;

private int age;

private char sex;

private double result;

//构造方法

public Student(String id, String name, int age, char sex, double result) {

super();

this.id = id;

this.name = name;

this.age = age;

this.sex = sex;

this.result = result;

}

//所有的setter和getter方法

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public char getSex() {

return sex;

}

public void setSex(char sex) {

this.sex = sex;

}

public double getResult() {

return result;

}

public void setResult(double result) {

this.result = result;

}

}

运行结果:

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

System.out.println("最终信息:");

temp.setResult(resultt);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//删除学生信息

public void deleteStu(String id)

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

l.remove(i);

}

}

System.out.println("删除信息成功!");

}

//根据综合考评排名

public void sort()

{

String tempid;

String tempname;

int tempage;

char tempsex;

double tempresult;

for(int i=0;i

{

Student x=(Student) l.get(i);

for(int j=i+1;j

{

Student y=(Student) l.get(j);

{

if(x.getResult()

{

tempid=x.getId();

x.setId(y.getId());

y.setId(tempid);

tempname=x.getName();

x.setName(y.getName());

y.setName(tempname);

tempage=x.getAge();

x.setAge(y.getAge());

y.setAge(tehttp://mpage);

tempsex=x.getSex();

x.setSex(y.getSex());

y.setSex(tempsex);

tempresult=x.getResult();

x.setResult(y.getResult());

y.setResult(tempresult);

}

}

}

}

}

//打印所有学生的信息

public void PrintInfo()

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//学生类

class Student

{

//成员变量

private String id;

private String name;

private int age;

private char sex;

private double result;

//构造方法

public Student(String id, String name, int age, char sex, double result) {

super();

this.id = id;

this.name = name;

this.age = age;

this.sex = sex;

this.result = result;

}

//所有的setter和getter方法

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public char getSex() {

return sex;

}

public void setSex(char sex) {

this.sex = sex;

}

public double getResult() {

return result;

}

public void setResult(double result) {

this.result = result;

}

}

运行结果:

{

Student temp=(Student) l.get(i);

if(id.equals(temp.getId()))

{

l.remove(i);

}

}

System.out.println("删除信息成功!");

}

//根据综合考评排名

public void sort()

{

String tempid;

String tempname;

int tempage;

char tempsex;

double tempresult;

for(int i=0;i

{

Student x=(Student) l.get(i);

for(int j=i+1;j

{

Student y=(Student) l.get(j);

{

if(x.getResult()

{

tempid=x.getId();

x.setId(y.getId());

y.setId(tempid);

tempname=x.getName();

x.setName(y.getName());

y.setName(tempname);

tempage=x.getAge();

x.setAge(y.getAge());

y.setAge(tehttp://mpage);

tempsex=x.getSex();

x.setSex(y.getSex());

y.setSex(tempsex);

tempresult=x.getResult();

x.setResult(y.getResult());

y.setResult(tempresult);

}

}

}

}

}

//打印所有学生的信息

public void PrintInfo()

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//学生类

class Student

{

//成员变量

private String id;

private String name;

private int age;

private char sex;

private double result;

//构造方法

public Student(String id, String name, int age, char sex, double result) {

super();

this.id = id;

this.name = name;

this.age = age;

this.sex = sex;

this.result = result;

}

//所有的setter和getter方法

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public char getSex() {

return sex;

}

public void setSex(char sex) {

this.sex = sex;

}

public double getResult() {

return result;

}

public void setResult(double result) {

this.result = result;

}

}

运行结果:

{

Student x=(Student) l.get(i);

for(int j=i+1;j

{

Student y=(Student) l.get(j);

{

if(x.getResult()

{

tempid=x.getId();

x.setId(y.getId());

y.setId(tempid);

tempname=x.getName();

x.setName(y.getName());

y.setName(tempname);

tempage=x.getAge();

x.setAge(y.getAge());

y.setAge(tehttp://mpage);

tempsex=x.getSex();

x.setSex(y.getSex());

y.setSex(tempsex);

tempresult=x.getResult();

x.setResult(y.getResult());

y.setResult(tempresult);

}

}

}

}

}

//打印所有学生的信息

public void PrintInfo()

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//学生类

class Student

{

//成员变量

private String id;

private String name;

private int age;

private char sex;

private double result;

//构造方法

public Student(String id, String name, int age, char sex, double result) {

super();

this.id = id;

this.name = name;

this.age = age;

this.sex = sex;

this.result = result;

}

//所有的setter和getter方法

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public char getSex() {

return sex;

}

public void setSex(char sex) {

this.sex = sex;

}

public double getResult() {

return result;

}

public void setResult(double result) {

this.result = result;

}

}

运行结果:

{

Student y=(Student) l.get(j);

{

if(x.getResult()

{

tempid=x.getId();

x.setId(y.getId());

y.setId(tempid);

tempname=x.getName();

x.setName(y.getName());

y.setName(tempname);

tempage=x.getAge();

x.setAge(y.getAge());

y.setAge(tehttp://mpage);

tempsex=x.getSex();

x.setSex(y.getSex());

y.setSex(tempsex);

tempresult=x.getResult();

x.setResult(y.getResult());

y.setResult(tempresult);

}

}

}

}

}

//打印所有学生的信息

public void PrintInfo()

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//学生类

class Student

{

//成员变量

private String id;

private String name;

private int age;

private char sex;

private double result;

//构造方法

public Student(String id, String name, int age, char sex, double result) {

super();

this.id = id;

this.name = name;

this.age = age;

this.sex = sex;

this.result = result;

}

//所有的setter和getter方法

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public char getSex() {

return sex;

}

public void setSex(char sex) {

this.sex = sex;

}

public double getResult() {

return result;

}

public void setResult(double result) {

this.result = result;

}

}

运行结果:

{

tempid=x.getId();

x.setId(y.getId());

y.setId(tempid);

tempname=x.getName();

x.setName(y.getName());

y.setName(tempname);

tempage=x.getAge();

x.setAge(y.getAge());

y.setAge(tehttp://mpage);

tempsex=x.getSex();

x.setSex(y.getSex());

y.setSex(tempsex);

tempresult=x.getResult();

x.setResult(y.getResult());

y.setResult(tempresult);

}

}

}

}

}

//打印所有学生的信息

public void PrintInfo()

{

for(int i=0;i

{

Student temp=(Student) l.get(i);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//学生类

class Student

{

//成员变量

private String id;

private String name;

private int age;

private char sex;

private double result;

//构造方法

public Student(String id, String name, int age, char sex, double result) {

super();

this.id = id;

this.name = name;

this.age = age;

this.sex = sex;

this.result = result;

}

//所有的setter和getter方法

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public char getSex() {

return sex;

}

public void setSex(char sex) {

this.sex = sex;

}

public double getResult() {

return result;

}

public void setResult(double result) {

this.result = result;

}

}

运行结果:

{

Student temp=(Student) l.get(i);

System.out.println("学号:"+temp.getId()+" 姓名:"+temp.getName()+" 年龄:"+temp.getAge()+" 性别:"+temp.getSex()+" 综合考评成绩:"+temp.getResult());

}

}

}

//学生类

class Student

{

//成员变量

private String id;

private String name;

private int age;

private char sex;

private double result;

//构造方法

public Student(String id, String name, int age, char sex, double result) {

super();

this.id = id;

this.name = name;

this.age = age;

this.sex = sex;

this.result = result;

}

//所有的setter和getter方法

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public char getSex() {

return sex;

}

public void setSex(char sex) {

this.sex = sex;

}

public double getResult() {

return result;

}

public void setResult(double result) {

this.result = result;

}

}

运行结果:


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:python 上传文件(upload),保存临时文件,再以csv和xls格式读取
下一篇:python字典操作
相关文章

 发表评论

暂时没有评论,来抢沙发吧~