实验 220211127 1+X 中级实操考试样题
目录
步骤 5:完成 StudentDaoImpl 的 add 方法
步骤 6:完成 StudentDaoImpl 的 queryNum 方法
步骤 7:完成 StudentDaoImpl 的 queryMinAge 方法(使用子查询)
步骤 8:完成 CourseDaoImpl 的 queryCourse 方法
步骤 9:完成 CourseDaoImpl 的 updateDifficultyByName 方法
步骤 10:完成 ScoreDaoImpl 的 queryAvgMax 方法
步骤 11:完成 ScoreDaoImpl 的 queryName 方法
前言
2021中级考试的1+x真题样题源码,代码经过老师培训和课堂上写的,只供参考。。
PS:实验2、3、4源码已经大结局,大家可以在我下方提供的链接参考代码
步骤1:跟里面复制粘贴就完事了
步骤 2:完成实体类 Student
public student(){}
public Student(String name,String pwd,int age,int grade,int rate){
this.name = name;
this.pwd = pwd;
this.age = age;
this.grade = grade;
this.rate = rate;
}
步骤 3:完成实体类 Course
if(difficulty.equals("高")||difficulty.equals("中")||difficulty.equals("低")){
this.difficulty = difficulty;
}
步骤 4:完成实体类 Score
@Override
public String toString() {
return "(sname="+this.sname+";cname="+this.cname+";score="+this.score+")";
}
步骤 5:完成 StudentDaoImpl 的 add 方法
public int add(Student s) {
// 请补全sql语句
String sql = "insert into student values(?,?,?,?,?)";
return studentUtil.add(sql, s.getName(),s.getPwd(),s.getAge(),s.getGrade(),s.getRate());
}
步骤 6:完成 StudentDaoImpl 的 queryNum 方法
public int queryNum() {
String sql = "select * from student";
List<Student> list = studentUtil.getList(sql, Student.class);
// 请修改以下代码,保证返回值为总人数,假设所有学生名字都不一样
int num = 0;
num = list.size();
return num;
}
步骤 7:完成 StudentDaoImpl 的 queryMinAge 方法(使用子查询)
public String queryMinAge() {
// 请补全sql语句
String sql = "select * from student where age=(select min(age) from student)";
Student g = studentUtil.getOne(sql, Student.class);
return g.getName();
}
步骤 8:完成 CourseDaoImpl 的 queryCourse 方法
public Course queryCourse(String name) {
// 请补全sql语句
String sql = "select * from course where name=?";
return courseUtil.getOne(sql, Course.class, name);
}
步骤 9:完成 CourseDaoImpl 的 updateDifficultyByName 方法
public boolean updateDifficultyByName(String name,String difficulty){
// 请补全sql语句
String sql = "update course set difficulty=? where name=?";
int a = courseUtil.update(sql, difficulty, name);
if(a>0){
return true;
}else{
return false;
}
步骤 10:完成 ScoreDaoImpl 的 queryAvgMax 方法
public String queryAvgMax() {
// 请补全sql语句
String sql = "select sname from score group by sname order by avg(score) desc limit 1";
Score s = scoreUtil.getOne(sql, Score.class);
return s.getSname();
}
步骤 11:完成 ScoreDaoImpl 的 queryName 方法
public Set<String> queryName() {
// 查询出满足条件的成绩集合
String sql = "select * from score where sname in(select sname from score group by sname having count(*)>=2)";
List<Score> li = scoreUtil.getList(sql, Score.class);
Set<String> s = new HashSet<String>();
// 把集合 li 中的每个成绩对象的名字取出来放进集合 s 中,并返回
// 请补全以下代码
for(Score score:li){
s.add(score.getSname());
}
return s;
}
最后祝各位1+x证书顺利拿到。