首页 / 更多教程 / 第二次数据库作业--view
第二次数据库作业--view
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了第二次数据库作业--view,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含10488字,纯文字阅读大概需要15分钟。
内容图文
![第二次数据库作业--view](/upload/InfoBanner/zyjiaocheng/462/e126d6c49bd144a19f3a1aa70dc683ba.jpg)
package view; import action.C2SAction; import action.CourseAction; import dao.C2SDao; import model.Course; import java.sql.SQLException; import java.util.List; import java.util.Scanner; import java.util.regex.Pattern; /** * Created by yinus * Date:2016/4/6 * Time:19:45 */ public class CourseView { private static final String OPERATE_EXIT = "EXIT"; private static final String OPERATE_ADD = "ADD"; private static final String OPERATE_UPDATE = "UPDATE"; private static final String OPERATE_QUERY = "QUERY"; private static final String OPERATE_DELETE = "DELETE"; private static final String PROMPT="COURSE[A/D/U/Q/E]>"; private static final String Menu =""+ "[ADD]ADD COURSE\n"+ "[DELETE]DELETE COURSE\n"+ "[UPDATE]UPDATE COURSE\n"+ "[QUERY]QUERY COURSE\n"+ "[EXIT]EXIT\n"+ "IGNORE CASE & MAY USE THE FIRST LETTER TO OPERATE" + PROMPT; public static void view() throws SQLException { System.out.println(Menu); Scanner input = new Scanner(System.in); while (input.hasNext()) { String keyWord = input.next().toUpperCase(); if (keyWord.equals(OPERATE_EXIT) || keyWord.substring(0, 1).equals(OPERATE_EXIT.substring(0,1))) { break; } else if (keyWord.equals(OPERATE_QUERY) || keyWord.substring(0, 1).equals(OPERATE_QUERY.substring(0,1))) { System.out.println("please enter the id or title of the course to be queried"); String str = input.next(); CourseAction courseAction = new CourseAction(); if (Pattern.matches("\\d+", str)) { Course course = courseAction.queryById(Integer.parseInt(str)); System.out.println(course); } else { List<Course> courses = courseAction.queryByName(str); courses.forEach(System.out::println); } System.out.print(PROMPT); } else if (keyWord.equals(OPERATE_ADD) || keyWord.substring(0, 1).equals(OPERATE_ADD.substring(0,1))) { CourseAction courseAction = new CourseAction(); System.out.println("please enter the id and title of the course to be added ,separated by spaces"); int id = input.nextInt(); String title = input.next(); courseAction.add(new Course(id, title)); System.out.println("added successfully"); System.out.print(PROMPT); } else if (keyWord.equals(OPERATE_DELETE) || keyWord.substring(0, 1).equals(OPERATE_DELETE.substring(0,1))) { CourseAction courseAction = new CourseAction(); System.out.println("please enter the id of the course to be delete"); int id = input.nextInt(); courseAction.delete(id); C2SAction ca =new C2SAction(); ca.delete(id,false); System.out.println("deleted successfully"); System.out.print(PROMPT); } else if (keyWord.equals(OPERATE_UPDATE) || keyWord.substring(0, 1).equals(OPERATE_UPDATE.substring(0,1))) { System.out.println("please enter the id of the course to be updated"); int id = input.nextInt(); CourseAction courseAction = new CourseAction(); Course course=courseAction.queryById(id); System.out.println("please enter the new title of the course"); String title = input.next(); course.setTitle(title); courseAction.update(course); System.out.println("updated successfully"); System.out.print(PROMPT); } } } }
package view; import action.C2SAction; import action.StudentAction; import model.Student; import java.sql.SQLException; import java.util.List; import java.util.Scanner; import java.util.regex.Pattern; /** * Created by yinus * Date:2016/4/6 * Time:19:45 */ public class StudentView { private static final String OPERATE_EXIT = "EXIT"; private static final String OPERATE_ADD = "ADD"; private static final String OPERATE_UPDATE = "UPDATE"; private static final String OPERATE_QUERY = "QUERY"; private static final String OPERATE_DELETE = "DELETE"; private static final String PROMPT="STUDENT[A/D/U/Q/E]>"; private static final String Menu =""+ "[ADD]ADD COURSE\n"+ "[DELETE]DELETE COURSE\n"+ "[UPDATE]UPDATE COURSE\n"+ "[QUERY]QUERY COURSE\n"+ "[EXIT]EXIT\n"+ "IGNORE CASE & MAY USE THE FIRST LETTER TO OPERATE" + PROMPT; public static void view() throws SQLException { System.out.print(Menu); Scanner input = new Scanner(System.in); while (input.hasNext()){ String keyWord = input.next().toUpperCase(); if (keyWord.equals(OPERATE_EXIT) || keyWord.substring(0, 1).equals(OPERATE_EXIT.substring(0,1))) { break; } else if (keyWord.equals(OPERATE_QUERY) || keyWord.substring(0, 1).equals(OPERATE_QUERY.substring(0,1))){ System.out.println("please enter the id or name of the student to be queried"); String str = input.next(); StudentAction studentAction = new StudentAction(); if (Pattern.matches("\\d+",str)) { Student student = studentAction.queryById(Integer.parseInt(str)); System.out.println(student); } else{ List<Student> students = studentAction.queryByName(str); students.forEach(System.out::println); } System.out.print(PROMPT); } else if (keyWord.equals(OPERATE_ADD) || keyWord.substring(0, 1).equals(OPERATE_ADD.substring(0,1))){ StudentAction studentAction = new StudentAction(); System.out.println("please enter the id and name of the student to be added ,separated by spaces"); int id = input.nextInt(); String name = input.next(); studentAction.add(new Student(id,name)); System.out.println("added successfully"); System.out.print(PROMPT); } else if (keyWord.equals(OPERATE_DELETE) || keyWord.substring(0, 1).equals(OPERATE_DELETE.substring(0,1))){ StudentAction studentAction = new StudentAction(); System.out.println("please enter the id of the student to be deleted"); int id = input.nextInt(); studentAction.delete(id); C2SAction ca = new C2SAction(); ca.delete(id,true); System.out.println("deleted successfully"); System.out.print(PROMPT); } else if (keyWord.equals(OPERATE_UPDATE) || keyWord.substring(0, 1).equals(OPERATE_UPDATE.substring(0,1))){ System.out.println("please enter the id of the student to updated"); int id = input.nextInt(); StudentAction studentAction = new StudentAction(); Student student = studentAction.queryById(id); System.out.println("enter the new name of the student"); String name = input.next(); student.setName(name); studentAction.update(student); System.out.println("updated successfully"); System.out.print(PROMPT); } } } }
第二次数据库作业--view
标签:
本文系统来源:http://www.cnblogs.com/ycy1025/p/5374285.html
内容总结
以上是互联网集市为您收集整理的第二次数据库作业--view全部内容,希望文章能够帮你解决第二次数据库作业--view所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。