蓝桥1+x java中级 看了就过关

20210620 1+x中级实操考试(id:2496)

public class Student {
    private String name;
    private String pwd;
    //已经提供Student类的属性,补充完成该类的有参(两个参数)及无参构造方法
    
    public Student() {
	}

	public Student(String name, String pwd) {
		this.name = name;
		this.pwd = pwd;
	}

}
/**
	 * 使用全局变量: sdf,将字符串转换为java.util.Date类型并返回
	 * 注意,不能声明任何形式的异常抛出,否则测试用例无法通过
	 * @param stringDate
	 * @return
	 */
	public static Date convertFromStringToDate(String stringDate) {
		// 补全代码:
		Date date = null;
		try {
			date = sdf.parse(stringDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
/**
	 * 使用全局变量: sdf,将日期转换成字符串
	 * @param date 需要被转换的日期
	 * @return 转换之后的字符串形式的日期
	 */
	public static String convertFromDateToString(Date date) {
		// 补全或替换代码
		return sdf.format(date);
	}
   /**
	 * 依据书名查询书籍
         * @param bname 书名
	 * @return 有的话返回书籍对象(唯一),没有的话返回null
	 */
	public Book findByName(String bname){
                // 请补全sql语句
                String sql = "select * from book where name=?";
                Book b = ou.getOne(sql, Book.class, bname);
                return b;
        }
/**
	 * 查询所有书籍中价钱最贵的书籍名称
	 * @return 返回书籍名称
	 */
	public String queryExpensiveBook(){
                // 请补全sql语句
                String sql = "select * from book where price=(select max(price) from book)";
                Book b = ou.getOne(sql, Book.class);
                return b.getName();
        }
 /**
	 * 依据学生的姓名来删除学生
	 * @param name 学生姓名
	 * @return 存在名字则删除,并返回true;不存在则不删除,并返回false
	 */
	public boolean deleteStudent(String name){
              // 请补全sql语句
              String sql = "delete from student where name=?";
              int a = ou.delete(sql, name);
              if(a>0){
                        return true;
              }else{
                        return false;  
              }
        }
   /**
	 * 根据学生姓名、旧密码、新密码来更新密码
	 * 如果学生姓名和旧密码不正确,则不更新
	 * 如果学生姓名和旧密码正确,则更新
	 *
	 * @param name 姓名
	 * @param oldPwd 旧密码
	 * @param newPwd 新密码
	 */
	public void changePwd(String name,String oldPwd,String newPwd){
                // 1.先判断学生姓名和旧密码是否正确
                // 请补全sql语句
                String sql1 = "select * from student where name=? and pwd=?";
                Student s = ou.getOne(sql1, Student.class, name, oldPwd);

                // 2.姓名和旧密码正确,则更新;姓名和旧密码不正确,则不更新
                if(s!=null){
                        // 请补全sql语句
                        String sql2 = "update student set pwd=? where name=?";
                        ou.update(sql2, newPwd, name);
                }
        }
/**
	 * 借书
	 * @param sb 需要借阅的书籍信息
	 * @return 借书成功返回true,借书失败返回false
	 */
        public boolean borrow(SB sb) {
                // 1.首先依据要借的书名来获取书籍对象
                Book b = findByName(sb.getBname());
                
                // 2.有书则借书,并返回true;没有书则不借书,并返回false
                if(b!=null&&b.getNum()>0){
                        // 往 sb 表中插入相关信息:学生姓名,书籍名称,借书时间。自增id和还书时间不用插入。
                        // 请补全sql语句
                        String sql1 = "insert into sb(sname,bname,begintime) values(?,?,?)";
                        ou.add(sql1,sb.getSname(),sb.getBname(),DateUtil.convertFromDateToString(sb.getBeginTime()));
                        // 更新 book 表中对应书籍的数量减1
                        // 请补全sql语句
                        String sql2 = "update book set num=num-1 where name=?";
                        ou.update(sql2, sb.getBname());
                        return true;
                }else{
                        return false;
                }
        }
   /**
	 * 还书
	 * @param sb 需要归还的书籍信息
	 * @return 还书成功返回true,还书失败返回false
	 */
	public boolean giveBack(SB sb){
                //1.首先查询某人是否在某个时间借阅了某书,但是还没有归还
                // 请补全sql语句
                String sql = "select * from sb where sname=? and bname=? and begintime=? and endtime is null";
                String btime = DateUtil.convertFromDateToString(sb.getBeginTime());
                SB f = ou.getOne(sql, SB.class, sb.getSname(),sb.getBname(), btime);

                //2.借了则归还,并返回true;没有借则不用归还,并返回false
                if(f!=null){
                        // 根据借书人、借书名称、借书时间来更新 sb 表中的还书时间为当前时间
                        // 请补全sql语句
                        String sql1 = "update sb set endtime=? where sname=? and bname=? and begintime=?";
                        ou.update(sql1, DateUtil.convertFromDateToString(new Date()),sb.getSname(),sb.getBname(),DateUtil.convertFromDateToString(sb.getBeginTime()));
                        // 更新 book 表中对应书籍的数量加1
                        // 请补全sql语句
                        String sql2 = "update book set num=num+1 where name=?";
                        ou.update(sql2, sb.getBname());
                        return true;
                }else{
                        return false;
                }
        }

20211030 1+X 中级实操考试(id:2498)

public class Member {
	private String name;//会员名称
	private String pwd;//会员密码
	private float score;//会员积分
	private int rank;//会员等级

	//已经提供Member类的属性,补充完成该类的有参(四个参数)及无参构造方法
	public Member() {
		
	}

	public Member(String name, String pwd, float score, int rank) {
		this.name = name;
		this.pwd = pwd;
		this.score = score;
		this.rank = rank;
	}
//请修改该方法,并且在赋值时,商品数量不能超过100
	public void setNum(int num) {
		if(num<=100){
			this.num = num;
		}
	}
/**
	 * 使用全局变量: sdf,将字符串转换为java.util.Date类型并返回
	 * 注意,不能声明任何形式的异常抛出,否则测试用例无法通过
	 * @param stringDate
	 * @return
	 */
	public static Date convertFromStringToDate(String stringDate) {
		// 补全代码:
		Date date = null;
		try {
			date = sdf.parse(stringDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
/**
	 * 使用全局变量: sdf,将日期转换成字符串
	 * @param date 需要被转换的日期
	 * @return 转换之后的字符串形式的日期
	 */
	public static String convertFromDateToString(Date date) {
		// 补全或替换代码
		return sdf.format(date);
	}
 /**
	 * 查询所有商品中价钱最贵的商品名称
	 * @return 返回商品名称
	 */
	public String queryExpensiveGoods() {
                // 请补全sql语句
                String sql = "select * from goods where price=(select max(price) from goods)";
                Goods g = goodsUtil.getOne(sql, Goods.class);
                return g.getName();
        }
  /**
	 * 查询所有商品的总价值金额
	 * @return 返回所有商品的总价值金额
	 */
	public double querySum() {
                String sql = "select * from goods";
                double sum = 0;
                List<Goods> list = goodsUtil.getList(sql, Goods.class);
                for (Goods goods : list) {
                        // 请补全代码
                       sum += goods.getNum()*goods.getPrice();
                }
                return sum;
        }
/**
	 * 给每个会员的密码加密
	 * 加密规则:密码的逆序。
	 * 如:原来的密码是123,加密后为321。
	 */
	public void updatePwd(){
                // 请补全sql语句
                String sql = "update member set pwd=reverse(pwd)";
                memberUtil.update(sql); 
        }
 /**
	 * 根据会员的积分来更新会员的等级
	 * 0<=score<100分,等级为0
	 * 100<=score<200分,等级为1
	 * 200<=score<300分,等级为2
	 * 300<=score<400分,等级为3
	 * 400<=score<500分,等级为4
	 * 500<=score分,等级为5
	 * @return
	 */
	public void updateRank() {
                // 请补全sql语句
                String sql = "update member set `rank`=case when score<100 then 0 when score<200 then 1 when score<300 then 2 when score<400 then 3 when score<500 then 4 else 5 end";
				//String sql = "update member set `rank`=if(score<500,floor(score/100),5)"
                memberUtil.update(sql); 
        }
/**
	 * 查询一共有多少笔订单
	 * @return 返回订单数量
	 */
	public int queryNum() {
                String sql = "select * from `order`;";
                List<Order> o = orderUtil.getList(sql, Order.class); 
                Set<Integer> s = new HashSet<Integer>();
                for (Order order : o) {
                        // 请补全语句
                        s.add(order.getId());
                }
                return s.size();
        }
/**
	 * 查询消费金额最多的人
	 * @return 返回会员名称
	 */
	public String queryMax() {
                // 请补全sql语句
                String sql = "select * from `order` where mname=(select mname from `order` group by mname order by sum(num*price) desc limit 1)";
                Order o = orderUtil.getOne(sql, Order.class); 
                return o.getMname();
        }

20211127 1+X 中级实操考试(id:2660)

public class Student {
	private String name;//学生姓名
	private String pwd;//学生密码
	private int age;//学生年龄
	private int grade;//学生年级
	private int rate;//学生综合评级

	//已经提供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;
	}

	public Student() {
		
	}
//请修改该方法,并且在赋值时,课程难度只能为:高、中、低这三种之一,其余值不做任何处理。
	public void setDifficulty(String difficulty) {
		if(difficulty.equals("高")||difficulty.equals("中")||difficulty.equals("低")){
			this.difficulty = difficulty;
		}
	}
//请修改该方法,以保证打印对象时输出格式如下:(sname=zs;cname=语文;score=80)
	@Override
	public String toString() {
		
		return "(sname=" + sname + ";cname=" + cname + ";score=" + score + ")";
	}
/**
	 * 插入学生
	 * @param s 学生对象
	 * @return
	 */
	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());
        }
/**
	 * 查询学生总人数
	 * @return 返回总人数
	 */
	public int queryNum() {
                String sql = "select * from student";
                List<Student> list = studentUtil.getList(sql, Student.class);
                // 请修改以下代码,保证返回值为总人数,假设所有学生名字都不一样
                int num = list.size();
                return num;
        }
/**
	 * 查询最小年龄的学生姓名
	 * @return 返回学生姓名
	 */
	public String queryMinAge() {
                // 请补全sql语句
                String sql = "select * from student order by age limit 1";
                Student g = studentUtil.getOne(sql, Student.class);
                return g.getName();
        }
/**
	 * 根据课程名称来查询课程
	 * @return 返回课程对象
	 */
	public Course queryCourse(String name) {
                // 请补全sql语句
                String sql = "select * from course where name=?";
                return courseUtil.getOne(sql, Course.class, name);
        }
/**
	 * 根据课程名称来更新课程难度
	 * @return 更新成功返回true,没有更新成功返回false
	 */
	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;  
                }
        }
/**
	 * 查询平均成绩最高的学生姓名
	 * @return 返回学生姓名
	 */
	public String queryAvgMax() {
                // 请补全sql语句
                String sql = "select * from score where sname=(select sname from score group by sname order by avg(score) desc limit 1)";
                Score s = scoreUtil.getOne(sql, Score.class);
                return s.getSname();
        }
/**
	 * 查询至少考了2门课程的学生姓名
	 * @return 返回所有满足条件的学生姓名的集合
	 */
	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;
        }

 20211219 1+X 中级实操考试(id:2846)

//请修改该方法,并且在赋值时,课程难度只能为:高、中、低这三种之一,其余值不做任何处理。
	public void setDifficulty(String difficulty) {
		if(difficulty.equals("高")||difficulty.equals("中")||difficulty.equals("低") ){
			this.difficulty = difficulty;
		}
	}
//请修改该方法,以保证打印对象时输出格式如下:[sname:zs;cname:语文;score:80]
	@Override
	public String toString() {
		
		return "[sname:"+this.sname+";cname:"+this.cname+";score:"+this.score+"]";
	}
/**
	 * 根据课程名称来更新课程难度
	 * @return 更新成功返回true,没有更新成功返回false
	 */
	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;  
                }
        }
/**
	 * 根据课程名称来查询课程
	 * @return 返回课程对象
	 */
	public Course queryCourse(String name) {
                // 请补全sql语句
                String sql = "select * from course where name=?";
                return courseUtil.getOne(sql, Course.class, name);
        }
/**
	 * 查询至少考了2门课程的学生姓名
	 * @return 返回所有满足条件的学生姓名的集合
	 */
	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;
        }
/**
	 * 查询平均成绩最大的学生姓名
	 * @return 返回学生姓名
	 */
	public String queryAvgMax() {
                // 请补全sql语句
                String sql = "select * from score where sname=(select sname from score group by sname order by avg(score) desc limit 1)";
                Score s = scoreUtil.getOne(sql, Score.class);
                return s.getSname();
        }
/**
	 * 查询最大年龄的学生姓名
	 * @return 返回学生姓名
	 */
	public String queryMaxAge() {
                // 请补全sql语句
                String sql = "select * from student where age =(select max(age) from student)";
                Student g = studentUtil.getOne(sql, Student.class);
                return g.getName();
        }
/**
	 * 查询年龄大于20岁的学生总人数
	 * @return 返回总人数
	 */
	public int queryNum() {
                String sql = "select * from student where age>20";
                List<Student> list = studentUtil.getList(sql, Student.class);
                // 请修改以下代码,保证返回值为总人数,假设所有学生名字都不一样
                int num = list.size();
                return num;
        }
/**
	 * 插入学生
	 * @param s 学生对象
	 * @return
	 */
	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());
        }

 20220319 1+X 中级实操考试(id:3097)

/**
	 * 依据书名查询书籍
         * @param bname 书名
	 * @return 有的话返回书籍对象(唯一),没有的话返回null
	 */
	public Book findByName(String bname){
                // 请补全sql语句
                String sql = "select * from book where name=?";
                Book b = ou.getOne(sql, Book.class, bname);
                return b;
        }
/**
	 * 查询所有书籍中价钱最贵的书籍名称
	 * @return 返回书籍名称
	 */
	public String queryExpensiveBook(){
                // 请补全sql语句
                String sql = "select * from book where price=(select max(price) from book)";
                Book b = ou.getOne(sql, Book.class);
                return b.getName();
        }
/**
	 * 依据学生的姓名来删除学生
	 * @param name 学生姓名
	 * @return 存在名字则删除,并返回true;不存在则不删除,并返回false
	 */
	public boolean deleteStudent(String name){
              // 请补全sql语句
              String sql = "delete from student where name=?";
              int a = ou.delete(sql, name);
              if(a>0){
                        return true;
              }else{
                        return false;  
              }
        }
/**
	 * 根据学生姓名、旧密码、新密码来更新密码
	 * 如果学生姓名和旧密码不正确,则不更新
	 * 如果学生姓名和旧密码正确,则更新
	 *
	 * @param name 姓名
	 * @param oldPwd 旧密码
	 * @param newPwd 新密码
	 */
	public void changePwd(String name,String oldPwd,String newPwd){
                // 1.先判断学生姓名和旧密码是否正确
                // 请补全sql语句
                String sql1 = "select * from student where name=? and pwd=?";
                Student s = ou.getOne(sql1, Student.class, name, oldPwd);

                // 2.姓名和旧密码正确,则更新;姓名和旧密码不正确,则不更新
                if(s!=null){
                        // 请补全sql语句
                        String sql2 = "update student set pwd=? where name=?";
                        ou.update(sql2, newPwd, name);
                }
        }
/**
	 * 借书
	 * @param sb 需要借阅的书籍信息
	 * @return 借书成功返回true,借书失败返回false
	 */
        public boolean borrow(SB sb) {
                // 1.首先依据要借的书名来获取书籍对象
                Book b = findByName(sb.getBname());
                
                // 2.有书则借书,并返回true;没有书则不借书,并返回false
                if(b!=null&&b.getNum()>0){
                        // 往 sb 表中插入相关信息:学生姓名,书籍名称,借书时间。自增id和还书时间不用插入。
                        // 请补全sql语句
                        String sql1 = "insert into sb(sname,bname,begintime) values(?,?,?)";
                        ou.add(sql1,sb.getSname(),sb.getBname(),DateUtil.convertFromDateToString(sb.getBeginTime()));
                        // 更新 book 表中对应书籍的数量减1
                        // 请补全sql语句
                        String sql2 = "update book set num=num-1 where name=?";
                        ou.update(sql2, sb.getBname());
                        return true;
                }else{
                        return false;
                }
        }
/**
	 * 还书
	 * @param sb 需要归还的书籍信息
	 * @return 还书成功返回true,还书失败返回false
	 */
	public boolean giveBack(SB sb){
                //1.首先查询某人是否在某个时间借阅了某书,但是还没有归还
                // 请补全sql语句
                String sql = "select * from sb where sname=? and bname=? and begintime=? and endtime is null";
                String btime = DateUtil.convertFromDateToString(sb.getBeginTime());
                SB f = ou.getOne(sql, SB.class, sb.getSname(),sb.getBname(), btime);

                //2.借了则归还,并返回true;没有借则不用归还,并返回false
                if(f!=null){
                        // 根据借书人、借书名称、借书时间来更新 sb 表中的还书时间为当前时间
                        // 请补全sql语句
                        String sql1 = "update sb set endtime=? where sname=? and bname=? and begintime=?";
                        ou.update(sql1, DateUtil.convertFromDateToString(new Date()),sb.getSname(),sb.getBname(),DateUtil.convertFromDateToString(sb.getBeginTime()));
                        // 更新 book 表中对应书籍的数量加1
                        // 请补全sql语句
                        String sql2 = "update book set num=num+1 where name=?";
                        ou.update(sql2, sb.getBname());
                        return true;
                }else{
                        return false;
                }
        }
/**
	 * 使用全局变量: sdf,将字符串转换为java.util.Date类型并返回
	 * 注意,不能声明任何形式的异常抛出,否则测试用例无法通过
	 * @param stringDate
	 * @return
	 */
	public static Date convertFromStringToDate(String stringDate) {
		// 补全代码:
		Date date = null;
		try {
			date = sdf.parse(stringDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
/**
	 * 使用全局变量: sdf,将日期转换成字符串
	 * @param date 需要被转换的日期
	 * @return 转换之后的字符串形式的日期
	 */
	public static String convertFromDateToString(Date date) {
		
		return sdf.format(date);
	}

 20220521 1+X 中级实操考试(id:3352) 

// 缺失代码:请补全以下方法,要求工资数量的范围在:1000<=num<10000 之间
	// 当参数在规定范围外时,不做任何动作
	public void setNum(int num) {
		if(num>=1000 && num<10000){
			this.num = num;
		}
	}
// 请修改该方法,以保证打印对象时输出格式如下:
	// {id:'001';name:'zs';age:20;sex:'男';sage:3}
	@Override
	public String toString() {
		return "{id:'"+this.id+"';name:'"+this.name+"';age:"+this.age+";sex:'"+this.sex+"';sage:"+this.sage+"}";
	}
/**
	 * 依据职工姓名查询职工
	 * @param name 职工姓名
	 * @return 有的话返回职工对象,没有的话返回null
	 */
	public Staff queryStaff(String name){
                // 请补全sql语句
                String sql = "select * from staff where name=?";
                Staff b = staffUtil.getOne(sql, Staff.class, name);
                return b;
        }
/**
	 * 查询某位职工某年某月的工资
	 * @param name 职工姓名
	 * @param year 年份
	 * @param month 月份
	 * @return 返回工资
	 */
	public int querySalary(String name,int year,int month){
                // 请补全sql语句
                String sql = "select sa.* from staff st,salary sa where st.id=sa.id and st.name=? and sa.year=? and sa.month=?";
                Salary sa = salaryUtil.getOne(sql, Salary.class, name, year, month);
                return sa.getNum();
        }
/**
	 * 查询工龄最高的职工
	 * @return 返回工龄最高的职工对象
	 */
	public Staff queryMaxSage(){
                // 请补全sql语句
                String sql = "select * from staff order by sage desc limit 1";
                Staff st = staffUtil.getOne(sql, Staff.class);
                return st;
        }
/**
	 * 查询某位职工的最高工资
	 * @param name 职工姓名
	 * @return 返回该职工的最高工资
	 */
	public int queryMaxSalary(String name){
                // 请补全sql语句
                String sql = "select sa.* from staff st,salary sa where st.id=sa.id and st.name=? order by num desc limit 1";
                Salary s = salaryUtil.getOne(sql, Salary.class, name);
                return s.getNum();
        }
/**
	 * 使所有职工的年龄加1
	 */
	public void updateAge(){
               // 请补全sql语句
               String sql = "update staff set age=age+1";
               int i = staffUtil.update(sql);
        }

 20220625 1+X 中级实操考试(id:3411) 

// 请修改该方法,以保证打印对象时输出格式如下:
	// {id:"001";name:"zs";age:20;sex:"男";provice:"四川"}
	@Override
	public String toString() {
		return "{id:\""+this.id+"\";name:\""+this.name+"\";age:"+this.age+";sex:\""+this.sex+"\";provice:\""+this.provice+"\"}";
	}
// 缺失代码:请补全以下方法,要求英语成绩的范围在:0<=num<150 之间
	// 当参数在规定范围外时,不做任何动作
	public void setEnglish(int english) {
		if(english>=0 && english<=150){
			this.english = english;
		}
	}
/**
	 * 依据学生考号查询学生信息
	 * @param id 学生考号
	 * @return 有的话返回学生对象,没有的话返回null
	 */
	public Info queryInfo(String id){
                // 请补全sql语句
                String sql = "select * from info where id=?";
                Info i = infoUtil.getOne(sql, Info.class, id);
                return i;
        }
/**
	 * 依据学生考号查询学生成绩,返回4门成绩之和
	 * @param id 学生考号
	 * @return 返回4门成绩之和
	 */
	public int querySum(String id){
                // 请补全sql语句
                String sql = "select * from score where id=?";
                Score s = scoreUtil.getOne(sql, Score.class, id);
                int sum = s.getChinese() + s.getMaths() + s.getEnglish() + s.getComposite();
                return sum;
        }
/**
	 * 依据学生姓名查询学生成绩,返回4门成绩之和
	 * @param name 学生姓名
	 * @return 返回4门成绩之和
	 */
	public int querySumByName(String name){
                // 请补全sql语句
                String sql = "select s.* from info i,score s where i.id=s.id and i.name=?";
                Score s = scoreUtil.getOne(sql, Score.class, name);
                int sum = s.getChinese() + s.getMaths() + s.getEnglish() + s.getComposite();
                return sum;
        }
/**
	 * 查询4门成绩之和的最大值
	 * @return 返回最大值
	 */
	public int queryMaxSum(){
                // 请补全sql语句
                String sql = "select * from score order by chinese+maths+english+composite desc limit 1";
                Score s = scoreUtil.getOne(sql, Score.class);
                int sum = s.getChinese() + s.getMaths() + s.getEnglish() + s.getComposite();
                return sum;
        }
/**
	 * 依据姓名更新年龄
	 * @return name 姓名
	 * @return age 年龄
	 */
	public void updateAge(String name,int age){
               // 请补全sql语句
               String sql = "update info set age=? where name=?";
               int i = infoUtil.update(sql,age,name);
        }

  20220917 1+X 中级实操考试(id:3475)

// 缺失代码:请补全以下方法,要求客户资金的范围在:0<=num 
	// 当参数在规定范围外时,不做任何动作
	public void setNum(double num) {
		if(num>=0){
			this.num = num;
		}
	}
// 请修改该方法,以保证打印对象时输出格式如下:
	// {id:"001";name:"zs";age:20;sex:"男";phone:"18812349876"}
	@Override
	public String toString() {
		return "{id:\""+this.id+"\";name:\""+this.name"\";age:"+this.age+";sex:\""+this.sex +"\";phone:\""+this.phone+"\"}";
	}
/**
	 * 依据客户卡号查询客户资金
	 * @param id 客户卡号
	 * @return 有的话返回金额,没有的话返回0
	 */
	public double queryNum(String id){
                // 请补全sql语句
                String sql = "select * from account where id=?";
                Account a = accountUtil.getOne(sql, Account.class, id);
                if(a!=null){
                        return a.getNum();
                }else{
                        return 0;
                }
        }
/**
	 * 依据客户姓名查询客户资金
	 * @param name 客户姓名
	 * @return 有的话返回金额,没有的话返回0
	 */
	public double queryNum2(String name){
                // 请补全sql语句
                String sql = "select * from account where id=(select id from info where name=?)";
                Account a = accountUtil.getOne(sql, Account.class, name);
                if(a!=null){
                        return a.getNum();
                }else{
                        return 0;
                }
        }
/**
	 * 查询有多少客户是信用卡客户(credit=true表示为信用卡用户)
	 * @return 返回人数
	 */
	public int queryCredit(){
                String sql = "select * from account where credit=true";
                List<Account> li = accountUtil.getList(sql, Account.class);
                // 请修改以下语句
                int num = li.size();
                return num;
        }
/**
	                   * 查询资金最大的人
	                  * @return 返回姓名
	                  */
	public String queryName(){
                // 请补全sql语句
String sql = "select * from info where id=(select id from account order by num desc limit 1)";
                Info i = infoUtil.getOne(sql, Info.class);
                return i.getName();
        }
/**
	 * 查询客户姓名中含有某个字母s的人数
	 * @param s 某个字母
	 * @return 返回人数
	 */
	public int querySum(String s){
               // 请补全sql语句
               String sql = "select * from info where name like '%"+s+"%'";
               List<Info> li = infoUtil.getList(sql, Info.class);
               int num = li.size();
               return num;
        }

   20221023 1+X 中级实操考试(id:3587)

// 缺失代码:请补全以下方法,要求客户资金的范围在:0<=num 
	// 当参数在规定范围外时,不做任何动作
	public void setNum(double num) {
		if(num>=0){
			this.num = num;
		}


	}
// 请修改该方法,以保证打印对象时输出格式如下:
	// {id:"001";name:"zs";age:20;sex:"男";phone:"18812349876"}
	@Override
	public String toString() {
		return "{id:\""+this.id+"\";name:\""+this.name+"\";age:"+this.age+";sex:\""+this.sex+"\";phone:\""+this.phone+"\"}";

	}
/**
	 * 依据客户卡号查询客户资金
	 * @param id 客户卡号
	 * @return 有的话返回金额,没有的话返回0
	 */
	public double queryNum(String id){
                // 请补全sql语句
                String sql = "select * from account where id=?";
                Account a = accountUtil.getOne(sql, Account.class, id);
                if(a!=null){
                        return a.getNum();
                }else{
                        return 0;
                }
        }
/**
	 * 依据客户姓名查询客户资金
	 * @param name 客户姓名
	 * @return 有的话返回金额,没有的话返回0
	 */
	public double queryNum2(String name){
                // 请补全sql语句
                String sql = "select * from account where id=(select id from info where name=?)";
                Account a = accountUtil.getOne(sql, Account.class, name);
                if(a!=null){
                        return a.getNum();
                }else{
                        return 0;
                }
        }
/**
	 * 查询有多少客户是贷款客户(credit=true表示为贷款用户)
	 * @return 返回人数
	 */
	public int queryCredit(){
                String sql = "select * from account where credit=true";
                List<Account> li = accountUtil.getList(sql, Account.class);
                // 请修改以下语句
                int num = li.size();
                return num;
        }
/**
         * 查询资金最大的人
         * @return 返回姓名
         */
	public String queryName(){
                // 请补全sql语句
                String sql = "select * from info where id=(select id from account order by num desc limit 1)";
                Info i = infoUtil.getOne(sql, Info.class);
                return i.getName();
        }
/**
	 * 查询客户姓名中含有某个字母s的人数
	 * @param s 某个字母
	 * @return 返回人数
	 */
	public int querySum(String s){
               // 请补全sql语句
               String sql = "select * from info where name like '%"+s+"%'";
               List<Info> li = infoUtil.getList(sql, Info.class);
               int num = li.size();
               return num;
        }

   20221119 1+X 中级实操考试(id:3609)

// 缺失代码:请补全以下方法,要求员工绩效分数的范围在:[0,100] 之间,包括0和100。
	// 当参数在规定范围外时,不做任何动作
	public void setScore(int score) {
		if(score>=0 && score<=100){
			this.score = score;
		}
	}
// 请修改该方法,以保证打印对象时输出格式如下:
	// {name:"zs";age:20;sex:"男";phone:"18812349876"}
	@Override
	public String toString() {
		return "{name:\""+this.name+"\";age:"+
				this.age+";sex:\""+this.sex+"\";phone:\""+this.phone+"\"}";
	}
/**
	 * 依据员工姓名查询员工信息
	 * @param name 员工姓名
	 * @return 有的话返回对象,没有的话返回null
	 */
	public Info queryByName(String name){
                // 请补全sql语句
                String sql = "select * from info where name=?";
                Info i = infoUtil.getOne(sql, Info.class, name); 
                return i;
        }
/**
	 * 依据员工姓名和绩效日期查询绩效分
	 * @param name 员工姓名
	 * @param time 绩效日期
	 * @return 有的话返回绩效分,没有的话返回0
	 */
	public int queryScore(String name, String time){
                // 请补全sql语句
                String sql = "select * from account where name=? and time=?";
                Account i = accountUtil.getOne(sql, Account.class, name, time); 
                if(i==null){
                        return 0;
                }else{
                        return i.getScore();
                }
        }
/**
	 * 查询绩效分最高的员工姓名
	 * @return 返回员工姓名
	 */
	public String queryMaxScore(){
                // 请补全sql语句
                String sql = "select * from account order by score desc limit 1";
                Account i = accountUtil.getOne(sql, Account.class); 
                return i.getName();
        }
/**
         * 查询平均绩效分最高的员工姓名
         * @return 返回姓名
         */
	public String queryMaxAvg() {
                // 请补全sql语句
                String sql = "select * from account where name=(select name from account group by name order by avg(score) desc limit 1)";
                Account i = accountUtil.getOne(sql, Account.class); 
                return i.getName();
        }
/**
	 * 查询员工绩效分最高分与最低分差值最大的员工姓名
	 * @return 返回姓名
	 */
	public String queryMaxMin() {
                // 请补全sql语句
                String sql = "select * from account where name=(select name from account group by name order by max(score)-min(score) desc limit 1)";
                Account i = accountUtil.getOne(sql, Account.class); 
                return i.getName();
        }

    20221224 1+X 中级实操考试(id:3621)

// 缺失代码:请补全以下方法,要求等级只能是A、B、C、D、E这5种之一
	// 当参数在规定范围外时,不做任何动作
	public void setLevel(String level) {
		if(level.equals("A")||level.equals("B")||level.equals("C")||
				level.equals("D")||level.equals("E")){
			this.level = level;
		}
	}
// 请修改该方法,以保证打印对象时输出格式如下:
	// [name='zs';age=20;sex='男';phone='18812349876']
	@Override
	public String toString() {
		return "[name='"+this.name+"';age="+this.age+";sex='"+this.sex+"';phone='"+this.phone+"']";
	}
/**
	 * 依据员工姓名查询员工信息
	 * @param name 员工姓名
	 * @return 有的话返回对象,没有的话返回null
	 */
	public Info queryByName(String name){
                // 请补全sql语句
                String sql = "select * from info where name=?";
                Info i = infoUtil.getOne(sql, Info.class, name); 
                return i;
        }
/**
	 * 依据员工姓名查询评级等级
	 * @param name 员工姓名
	 * @return 有的话返评级等级,没有的话返回null
	 */
	public String queryLevel(String name) {
                // 请补全sql语句
                String sql = "select * from account where name=?";
                Account i = accountUtil.getOne(sql, Account.class, name); 
                if(i==null){
                        return null;
                }
                return i.getLevel();
        }
/**
	 * 依据以下规则,检查员工评级等级是否正确
         * 90<=score<=100 level=A
         * 80<=score<=89 level=B
         * 70<=score<=79 level=C
         * 60<=score<=69 level=D
         * 0<=score<=59 level=E
	 * @param name 员工姓名
	 * @return 正确返回true,错误返回false
	 */
	public Boolean checkLevel(String name) {
                String sql = "select * from account where name=?";
                Account i = accountUtil.getOne(sql, Account.class, name); 
                int score = i.getScore();
                String level = i.getLevel();
                // 请补全代码实现该功能
                if(level.equals("A") && score>=90 && score<=100){
                        return true;
                }else if(level.equals("B") && score>=80 && score<=89){
                        return true;
                }else if(level.equals("C") && score>=70 && score<=79){
                        return true;
                }else if(level.equals("D") && score>=60 && score<=69){
                        return true;
                }else if(level.equals("E") && score>=0 && score<=59){
                        return true;
                }
                return false;
        }
/**
	 * 依据以下规则,更新所有的评级等级
	 * 90<=score<=100 level=A
         * 80<=score<=89 level=B
         * 70<=score<=79 level=C
         * 60<=score<=69 level=D
         * 0<=score<=59 level=E
	 */
	public void updateLevel() {
                // 请补全sql语句
                String sql = "update account set level=case when score>=90 and score<=100 then 'A' when score>=80 and score<=89 then 'B' when score>=70 and score<=79 then 'C' when score>=60 and score<=69 then 'D' when score>=0 and score<=59 then 'E' end";
                accountUtil.update(sql); 
        }
/**
	 * 查询每个评级等级对应有多少人
	 * @param level 评级等级
	 * @return 返回人数
	 */
	public int queryNum(String level) {
                // 请补全sql语句
                String sql = "select * from account where level=?";
                List<Account> li = accountUtil.getList(sql, Account.class, level); 
                return li.size();
        }

     20230318 1+X 中级实操考试(id:3713)

// 请补全以下方法,要求下班时间不能大于20:00:00
    // 时间格式如:2023-03-08 18:19:20
	// 当参数在规定范围外时,不做任何动作
	public void setEndtime(String endtime) {
		String[] s1 = endtime.split(" ");
		String time = "20:00:00";
		// 缺失代码:
		if(s1[1].compareTo(time)<=0){
			this.endtime = endtime;
		}
	}
// 请修改该方法,以保证打印对象时输出格式如下:
	// [name='zs';age=20;sex='男';phone='18812349876']
	@Override
	public String toString() {
		return "[name='"+this.name+"';age="+this.age+";sex='"+this.sex+"';phone='"+this.phone+"']";
	}
 /**
	 * 依据员工姓名查询员工信息
	 * @param name 员工姓名
	 * @return 有的话返回对象,没有的话返回null
	 */
	public Info queryByName(String name){
        // 请补全sql代码
        String sql = "select * from info where name=?";
        Info info = JDBCUtil.getSingleResult(sql, Info.class, name);
        return info;
    }
/**
	 * 依据员工性别查询人数
	 * @param sex 员工性别
	 * @return 返回人数
	 */
	public int queryNum(String sex) {
        // 请补全sql语句
        String sql = "select * from info where sex=?";
        List<Info> list = JDBCUtil.getResult(sql, Info.class, sex); 
        return list.size();
    }
/**
     * 查看员工考勤是否正常
     * 规则如下:
     * 全天至少工作9个小时
     * 
     * 需求:
     * 员工考勤正常的话,返回true,考勤异常的话,返回false
     *
     * @param name 员工姓名
     * @param date 考勤日期,如:2023-03-10
     */
	public Boolean check(String name,String date) {
        String sql = "select * from account where name=? and substr(begintime,1,10)=?";
        Account a = JDBCUtil.getSingleResult(sql, Account.class, name, date);
        boolean flag = false;
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date begintime = null;
        Date endtime = null;
        // 请补全代码实现该功能
        try {
            begintime = dfs.parse(a.getBegintime());
            endtime = dfs.parse(a.getEndtime());
            double between = (endtime.getTime()-begintime.getTime())*1.0/(1000*3600);
            if(between>=9){
                flag = true;
            }else{
                flag = false;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return flag;
    }
/**
	 * 依据员工姓名查询其哪天上班时间最早
	 * @param sex 员工性别
	 * @return 返回最早的上班时间
	 */
	public String queryTime(String name) {
        // 请补全sql语句
        String sql = "select * from account where name=? order by substr(begintime,12) limit 1";
        Account a = JDBCUtil.getSingleResult(sql, Account.class, name); 
        return a.getBegintime();
    }
/**
	 * 更新所有人的年龄,男人加1,女人加2
	 */
	public void updateAge() {
        // 请补全sql语句
        String sql = "update info set age=case when sex='男' then age+1 else age+2 end";
        JDBCUtil.executeSql(sql); 
    }
  • 19
    点赞
  • 63
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浪里个浪的1024

你的鼓励将是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值