public Student()
{
}
public Student(int id, int age, int score, String name)
{
this.id = id;
this.age = age;
this.score = score;
this.name = name;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public int getScore()
{
return score;
}
public void setScore(int score)
{
this.score = score;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
@Override
public String toString()
{
return "学号学校管理java代码:" + id + " 姓名:" + name + " 年龄:" + age + " 成绩:" + score;
}
}
Manager类
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Manager
{
private ListStudent list;
public Manager(ListStudent list)
{
this.list = list;
}
public ListStudent getList()
{
return list;
}
public void setList(ListStudent list)
{
this.list = list;
}
//添加学生
public void add(Student s)
{
list.add(s);
}
//根据学生学号返回学生年龄
public int search(int id)
{
for(IteratorStudent iter = list.iterator(); iter.hasNext();)
{
Student s = iter.next();
if(s.getId() == id)
{
return s.getAge();
}
}
return -1;
}
//删除学生
public void remove(int id)
{
for(IteratorStudent iter = list.iterator(); iter.hasNext();)
{
Student s = iter.next();
if(s.getId() == id)
{
list.remove(s);
}
}
}
//计算总成绩
public int allScore()
{
int score = 0;
int temp = 0;
for(IteratorStudent iter = list.iterator(); iter.hasNext();)
{
Student s = iter.next();
temp = s.getScore();
score += temp;
}
return score;
}
//修改成绩
public void update(int id)
{
for(IteratorStudent iter = list.iterator(); iter.hasNext();)
{
Student s = iter.next();
if(s.getId() == id)
{
s.setScore(s.getScore() + 10);
}
}
}
}
测试类 Client
import java.util.ArrayList;
import java.util.List;
public class Client
{
public static void main(String[] args)
{
ListStudent list = new ArrayListStudent();
Manager manager = new Manager(list);//创建一个管理者
Student s1 = new Student();//无参构造方法创建学校管理java代码的学生实例
//通过方法设置s1的属性
s1.setId(201105);
s1.setAge(20);
s1.setScore(100);
s1.setName("zhangsan");
Student s2 = new Student(201101,21,98,"lisi");//通过带参数的构造方法创建实例
Student s3 = new Student(201108,25,95,"zhaoliu");
Student s4 = new Student(201110,23,80,"xiaoming");
Student s5 = new Student(201106,28,78,"hello");
//放到集合当中
manager.getList().add(s1);//添加学生
manager.getList().add(s2);
manager.getList().add(s3);
manager.getList().add(s4);
manager.getList().add(s5);
System.out.println(list);
System.out.println(manager.allScore());
System.out.println(manager.search(201110));//根据学生学号查询学生年龄
manager.remove(201110);//删除学生
manager.update(201101);//修改成绩
}
}
可以完成你上述的基本要求学校管理java代码 , 如果改动可以自行修改 很简单 。
推荐阅读
- 网站单页制作,单页网站如何制作
- 视频的直观性是什么,直观视角
- 为什么微信视频号要绑定mcn,为什么微信视频号要绑定手机号才可以
- 单机小游戏射击,单机小型射击游戏
- python中文变量函数 python函数中的变量
- oracle查询常用命令,oracle数据查询语句
- word脚注横线怎么删除,如何删除word尾注遗留的横线
- linux运行时间命令 linux 命令时间
- js操作的session,js操作的两大方向是那两个