一丶团队成员及任务分配
团队成员:
网络1811 简达亮 201821123019(组长)
网络1812 苏雨 201821123048(组员)
网络1811 罗赐 201821123022(组员)
任务分配:
二、项目git地址
https://gitee.com/luoci0213/StudentGradeSystem
三、项目git提交记录截图
四、项目功能架构图与主要功能流程图
思维导图
功能流程图
五、程序功能运行截图:
进入界面
用户选择
登录进入
学生成绩信息
增加学生信息
删除学生信息
修改学生信息
查找学生信息
柱状图
(学生)成绩查询
Excel表格生成
六、项目关键代码
Excel生成:
public void LearningReport() throws SQLException { ArrayList<String> list1 = new ArrayList<String>(); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; String sql = "select * from students "; con = JDBCUtil.getConnection(); ps = con.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { list1.add(0, rs.getString("stunum")); list1.add(1, rs.getString("name")); list1.add(2, rs.getString("classes")); list1.add(3, rs.getString("gender")); list1.add(4, rs.getString("javaScore")); list1.add(5, rs.getString("mathScore")); list1.add(6, rs.getString("englishScore")); System.out.println(); } HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("表"); HSSFRow row1 = sheet.createRow(0); HSSFCell cell = row1.createCell(0); cell.setCellValue("学生成绩表"); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); HSSFRow row2 = sheet.createRow(1); row2.createCell(0).setCellValue("学号"); row2.createCell(1).setCellValue("名字"); row2.createCell(2).setCellValue("班级"); row2.createCell(3).setCellValue("性别"); row2.createCell(4).setCellValue("Java"); row2.createCell(5).setCellValue("Math"); row2.createCell(6).setCellValue("English"); int j = 1; for (int i = 0; i < list1.size(); i++) { HSSFRow row = sheet.createRow(++j); row.createCell(0).setCellValue(list1.get(i++)); row.createCell(1).setCellValue(list1.get(i++)); row.createCell(2).setCellValue(list1.get(i++)); row.createCell(3).setCellValue(list1.get(i++)); row.createCell(4).setCellValue(list1.get(i++)); row.createCell(5).setCellValue(list1.get(i++)); row.createCell(6).setCellValue(list1.get(i)); } try { FileOutputStream fout = new FileOutputStream( "C:\\Users\\ChenYan\\Desktop\\StudentGradeSystem\\StudentGradeSystem\\students.xlsx"); wb.write(fout); fout.close(); } catch (Exception e) { e.printStackTrace(); } finally { JDBCUtil.realeaseAll(rs, null, con); } } @Override public List<Student> findStudentByStunum(String stunum) { Connection con = null; PreparedStatement pt = null; ResultSet rs = null; String sql = "select * from students where stunum like '%" + stunum + "%'"; List<Student> list = new ArrayList<Student>(); try { con = JDBCUtil.getConnection(); pt = con.prepareStatement(sql); rs = pt.executeQuery(); while (rs.next()) { Student stu = new Student(); stu.setId(rs.getInt("id")); stu.setName(rs.getString("name")); stu.setStunum(rs.getString("stunum")); stu.setClasses(rs.getInt("classes")); stu.setGender(rs.getString("gender")); ArrayList<Course> scoreList = new ArrayList<Course>(); Course java = new Course("java", rs.getDouble("javaScore")); Course math = new Course("math", rs.getDouble("mathScore")); Course english = new Course("english", rs.getDouble("englishScore")); scoreList.add(java); scoreList.add(math); scoreList.add(english); stu.setScoreList(scoreList); list.add(stu); } } catch (SQLException e) { e.printStackTrace(); } finally { JDBCUtil.realeaseAll(rs, pt, con); } return list; } @Override public List<Student> findStudentByClass(int classes) { Connection con = null; PreparedStatement pt = null; ResultSet rs = null; List<Student> list = new ArrayList<Student>(); try { con = JDBCUtil.getConnection(); pt = con.prepareStatement("select * from students where classes like '%" + classes + "%'"); rs = pt.executeQuery(); while (rs.next()) { Student stu = new Student(); stu.setId(rs.getInt("id")); stu.setName(rs.getString("name")); stu.setStunum(rs.getString("stunum")); stu.setClasses(rs.getInt("classes")); stu.setGender(rs.getString("gender")); ArrayList<Course> scoreList = new ArrayList<Course>(); Course java = new Course("java", rs.getDouble("javaScore")); Course math = new Course("math", rs.getDouble("mathScore")); Course english = new Course("english", rs.getDouble("englishScore")); scoreList.add(java); scoreList.add(math); scoreList.add(english); stu.setScoreList(scoreList); list.add(stu); } } catch (SQLException e) { e.printStackTrace(); } finally { JDBCUtil.realeaseAll(rs, pt, con); } return list; } @Override public List<Student> findStudentByName(String name) { Connection con = null; PreparedStatement pt = null; ResultSet rs = null; String sql = "select * from students where name like '%" + name + "%'"; List<Student> list = new ArrayList<Student>(); try { con = JDBCUtil.getConnection(); pt = con.prepareStatement(sql); rs = pt.executeQuery(); while (rs.next()) { System.out.println("*"); Student stu = new Student(); stu.setId(rs.getInt("id")); stu.setName(rs.getString("name")); stu.setStunum(rs.getString("stunum")); stu.setClasses(rs.getInt("classes")); stu.setGender(rs.getString("gender")); ArrayList<Course> scoreList = new ArrayList<Course>(); Course java = new Course("java", rs.getDouble("javaScore")); Course math = new Course("math", rs.getDouble("mathScore")); Course english = new Course("english", rs.getDouble("englishScore")); scoreList.add(java); scoreList.add(math); scoreList.add(english); stu.setScoreList(scoreList); list.add(stu); } } catch (SQLException e) { e.printStackTrace(); } finally { JDBCUtil.realeaseAll(rs, pt, con); } return list; } }
柱状图:
public static JFreeChart createChart(CategoryDataset dataset) { // 创建一个JFreeChart JFreeChart chart = ChartFactory.createBarChart("hi", "成绩情况", "人数", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setTitle(new TextTitle("学生成绩统计", new Font("宋体", Font.BOLD + Font.ITALIC, 20))); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setLabelFont(new Font("微软雅黑", Font.BOLD, 12)); return chart; } public static JPanel createPanel(String course) throws SQLException { JFreeChart chart = createChart(createDataset(course)); return new ChartPanel(chart); } }
七、项目代码扫描结果及改正
修改
总结:
第一次通过小组合作结合数据库,GUI等结合完成课程设计。不仅掌握了新的知识并且运用起来。但是实验仍存在不足,没能完善登录系统中的修改密码;程序的功能并不是很多;界面设计没有想象的那么好看。
来源:https://www.cnblogs.com/luoxiaoci1213/p/12168410.html