java面向对象高级分层实例_测试类(main方法所在的类)

来源:互联网 发布:网络电视机顶盒直播软件哪个好 编辑:程序博客网 时间:2024/06/08 05:17
package bdqn.studentSys;/** * main类 * @author Administrator * */import java.util.*;import bdqn.studentSys.Dao.StudentDao;import bdqn.studentSys.Dao.impl.StudentDaoImpl;import bdqn.studentSys.entity.Student;public class StudentSys {public static void main(String []args){Scanner in=new Scanner(System.in);//查询全部学生getAllStudent();//添加System.out.println("==============添加学生信息==============");System.out.println("请输入学生姓名:");String name=in.next();System.out.println("请输入学生密码:");String pwd=in.next();System.out.println("请输入学生年龄:");int age=in.nextInt();System.out.println("请输入学生性别:");String sex=in.next();Student stu=new Student();stu.setName(name);stu.setPwd(pwd);stu.setAge(age);stu.setSex(sex);addStudent(stu);//修改System.out.println("==============修改学生信息==============");System.out.println("请输入要修改的学生学号:");int no=in.nextInt();System.out.println("请输入学生姓名:");String name1=in.next();System.out.println("请输入学生密码:");String pwd1=in.next();System.out.println("请输入学生年龄:");int age1=in.nextInt();System.out.println("请输入学生性别:");String sex1=in.next();Student stu1=new Student();stu.setName(name1);stu.setPwd(pwd1);stu.setAge(age1);stu.setSex(sex1);updateStudent(stu1);//删除System.out.println("==============删除学生信息==============");System.out.println("请输入要删除的学生学号:");int no1=in.nextInt();delStudent(no1);}static StudentDao sdao=new StudentDaoImpl();//查询全部学生static void getAllStudent(){List<Student> slist=sdao.getAllStudent();System.out.println("姓名\t\t密码\t\t年龄\t\t性别");for (Student stu : slist) {System.out.print(stu.getName()+"\t\t");System.out.print(stu.getPwd()+"\t\t");System.out.print(stu.getAge()+"\t\t");System.out.println(stu.getSex()+"\t\t");}}//添加学生信息static void addStudent(Student stu){int rel=sdao.addStudent(stu);try {if(rel>0){System.out.println("添加成功!");}else{System.out.println("添加失败!");}} catch (Exception e) {System.out.println("操作异常!"+e);}}//修改学生信息static void updateStudent(Student stu){int rel=sdao.UpdateStudent(stu);try {if(rel>0){System.out.println("修改成功!");}else{System.out.println("添加失败!");}} catch (Exception e) {// TODO: handle exceptionSystem.out.println("操作异常"+e);}}//删除学生信息static void delStudent(int stuno){int rel=sdao.delStudent(stuno);try {if(rel>0){System.out.println("删除成功!");}else{System.out.println("删除失败");}} catch (Exception e) {// TODO: handle exceptionSystem.out.println("操作异常"+e);}}}

1 0