有机会能够处理你所遇到的工作
相关的要求也能够告知我们
数据库课题:学生信息查询**。
ES:\\535C64B4DE21BEEFB825BEA33A52A3F3
USE STUDENT ------SQLSERVER中切换到STUDENT的语法SELECT * FROM 学生基本信息表
或者SELECT * FROM STUDENT..学生基本信息表
Student 类public class Student
{
private int id
private int age
private int score
private String name
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 "学号:" + id + " 姓名:" + name + " 年龄:" + age + " 成绩:" + score
}
}
Manager类
import java.util.ArrayList
import java.util.Iterator
import java.util.List
public class Manager
{
private List<Student>list
public Manager(List<Student>list)
{
this.list = list
}
public List<Student>getList()
{
return list
}
public void setList(List<Student>list)
{
this.list = list
}
//添加学生
public void add(Student s)
{
list.add(s)
}
//根据学生学号返回学生年龄
public int search(int id)
{
for(Iterator<Student>iter = list.iterator()iter.hasNext())
{
Student s = iter.next()
if(s.getId() == id)
{
return s.getAge()
}
}
return -1
}
//删除学生
public void remove(int id)
{
for(Iterator<Student>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(Iterator<Student>iter = list.iterator()iter.hasNext())
{
Student s = iter.next()
temp = s.getScore()
score += temp
}
return score
}
//修改成绩
public void update(int id)
{
for(Iterator<Student>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)
{
List<Student>list = new ArrayList<Student>()
Manager manager = new Manager(list)//创建一个管理者
Student s1 = new Student()//无参构造方法创建的学生实例
//通过方法设置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)//修改成绩
}
}
可以完成你上述的基本要求,如果改动可以自行修改 很简单。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)