计算机软件技术实习(实验准备)——小型信息管理系统的设计与实现

实验内容:

  1.  设计一个简单的学生信息管理的程序,教学管理人员能够使用该程序对学生基本信息、课程信息进行管理,包括数据的添加、修改删除和浏览;能够对学生选课进行管理,包括添加学生选课信息、录入成绩;能使用查询功能,快速查看到指定学生的选课信息;能够对学生选课情况进行简单的统计,包括所选的总的课程数、总学分数及平均成绩。
  2. 在添加学生基本信息、课程基本信息相关数据时,学号和课程号不能重复;在添加学生选课信息时,要求该学生和课程必须是存在的,而且不能添加重复的选课信息。
  3. 应用程序提供操作界面,可以方便用户进行功能选择,实现 信息的管理和查询,并可以清晰地显示相关信息。
  4. 选做1:航空客运订票管理系统,要求系统能为客户提供下列服务:

①查询航线:根据旅客提出的终点站名输出下列信息:航班号、飞机号、星期几飞行,最近一天航班的日期和余票额;

②承办订票业务:根据客户提出的要求(日期、航班号、订票数额)查询该航班票额情况,若尚有余额,则为客户办理订票手续,输出座位号;若已满员或余票额少于订票额,则需要重新询问客户要求。

③承办退票业务:根据客户提供的情况(日期、航班、退票数额),为客户办理退票手续。

  1. 选做2:远程教育机构信息管理系统

系统为三种类型的用户提供服务: 学生、教师和管理员。要求向三种类型的用户分别提供不同的界面。

     ①学生用户将提供以下功能: 

选课报名: 该功能将允许学生搜索课程并查看机构提供的关于该课程的信息,并可以选择报名。

查看课程资料: 该功能将允许学生查看他们已报名参加的课程资料。

更改密码: 该功能允许学生更改登录帐户的密码。

② 教师用户将提供以下功能:

查看课程资料: 该功能将允许教师查看他们教授的课程和选课学生的资料。

更改密码: 该功能允许学生更改登录帐户的密码。

     ③ 管理员用户将提供以下功能:

课程资料的管理: 该功能将实现对课程资料的增删改查。

学生资料的管理: 该功能将实现对学生资料的增删改查。

教师资料的管理: 该功能将实现对教师资料的增删改查。

更改密码: 该功能允许更改所有登录帐户的密码。

选做3:自行命题的管理信息系统

Mysql.java

package Mysql;


import java.sql.*;

public class Mysql {
	Connection con=null;
	public Mysql(String username,String password) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("加载驱动成功");
		}catch (Exception e) {
			System.out.println("加载驱动失败");
		}
		
		String url="jdbc:mysql://localhost:3306/studentsystem?characterEncoding=utf-8&useSSL=false";
		try {
			con=DriverManager.getConnection(url,username,password);
			System.out.println("连接数据库成功");
		}catch(SQLException e) {
			System.out.println("连接数据库失败");
		}
	}
}

 Test.java

package Mysql;

public class test {
	
	public static void main(String[] args) {
		Mysql a = new Mysql("root","***");
	}

}

studentSystem.dao

AdminDao.java

package studentSystem.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import studentSystem.model.Admin;

public class AdminDao extends BaseDao{

	public Admin selectAdmin(String name,String password) {
		String sqlStr = "select * from s_admin where name = ? and password = ?";
		Admin admin = null;
		try {
			this.pStatement = this.con.prepareStatement(sqlStr);
			this.pStatement.setString(1, name);
			this.pStatement.setString(2, password);
			
			ResultSet executeQuery = this.pStatement.executeQuery();
			if(executeQuery.next()) {
				admin = new Admin(executeQuery.getInt(1),executeQuery.getString(2),executeQuery.getString(3));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			this.close();
		}
		return admin;
	}
}

 BaseDao.java

package studentSystem.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import studentSystem.util.DbUtil;

public abstract class BaseDao {

	protected Connection con = DbUtil.getConnection();
	
	protected PreparedStatement pStatement = null;
	
	protected void close() {
		try {
			this.con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

StudentDao.java

package studentSystem.dao;

import studentSystem.model.Student;

public interface StudentDao {

	public int insert(Student stu);
}

 studentSystem.dao.impl

StudentDaoImpl.java

package studentSystem.dao.impl;

import studentSystem.dao.AdminDao;
import studentSystem.dao.StudentDao;
import studentSystem.model.Student;
import studentSystem.util.DbUtil;

public class StudentDaoImpl implements StudentDao{

	@Override
	public int insert(Student stu) {
		// TODO Auto-generated method stub
		String sqlStr="insert into s_student values(seq_stu.nextval,?,?,?,?,?)";
		String [] prams= {stu.getId(),stu.getName(),stu.getGender(),stu.getChinese(),stu.getMath(),stu.getEnglish()};
		
		int update = DbUtil.executeUpdate(sqlStr,prams);
		
			
		
		return update;
	}

}

studentSytem.model

Admin.java

package studentSystem.model;

public class Admin {

	private int id;
	private String name;
	private String password;
	
	public Admin() {
		
	}
	public Admin(String name ,String password) {
		this.name = name;
		this.password = password;
	}
	public Admin(int id,String name,String password) {
		this.id = id;
		this.name = name;
		this.password = password;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String toString() {
		return name+" "+password;
	}
}

Student.java

package studentSystem.model;

public class Student {

	private String id;
	private String name;
	private String gender;
	private String chinese;
	private String math;
	private String english;
	
	
	
	public Student(String id, String name, String gender,String chinese,String maths,String english) {
		super();
		this.id = id;
		this.name = name;
		this.gender = gender;
		this.chinese = chinese;
		this.math = math;
		this.english = english;
		
	}



	public String getId() {
		return id;
	}



	public void setId(String id) {
		this.id = id;
	}



	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}



	public String getGender() {
		return gender;
	}



	public void setGender(String gender) {
		this.gender = gender;
	}



	public String getChinese() {
		return chinese;
	}



	public void setChinese(String chinese) {
		this.chinese = chinese;
	}



	public String getMath() {
		return math;
	}



	public void setMath(String math) {
		this.math = math;
	}



	public String getEnglish() {
		return english;
	}



	public void setEnglish(String english) {
		this.english = english;
	}
}

UserType.java

package studentSystem.model;

public class Student {

	private String id;
	private String name;
	private String gender;
	private String chinese;
	private String math;
	private String english;
	
	
	
	public Student(String id, String name, String gender,String chinese,String maths,String english) {
		super();
		this.id = id;
		this.name = name;
		this.gender = gender;
		this.chinese = chinese;
		this.math = math;
		this.english = english;
		
	}



	public String getId() {
		return id;
	}



	public void setId(String id) {
		this.id = id;
	}



	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}



	public String getGender() {
		return gender;
	}



	public void setGender(String gender) {
		this.gender = gender;
	}



	public String getChinese() {
		return chinese;
	}



	public void setChinese(String chinese) {
		this.chinese = chinese;
	}



	public String getMath() {
		return math;
	}



	public void setMath(String math) {
		this.math = math;
	}



	public String getEnglish() {
		return english;
	}



	public void setEnglish(String english) {
		this.english = english;
	}
}

studentSystem.util

Dbutil.java

package studentSystem.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DbUtil {

	private static String jdbcDriver = "com.mysql.jdbc.Driver";
	private static ReadProperties rp = ReadProperties.initial();
	
	public static Connection getConnection() {
		
		try {
			Class.forName(jdbcDriver);
			
			Connection connection = DriverManager.getConnection(rp.dbUrl, rp.dbUsername, rp.dbPassword);
			return connection;
			
		}catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static int executeUpdate(String sqlStr, String[] prams) {
		// TODO Auto-generated method stub
		return 0;
	}

}

ReadProperties.java

package studentSystem.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ReadProperties {

	private static ReadProperties rp;
	
	public String dbUrl;
	public String dbUsername;
	public String dbPassword;
	
	private ReadProperties() {
		loadProperties();
	}
	
	public static ReadProperties initial() {
		if(rp==null)
			rp = new ReadProperties();
		return rp;
	}
	private void loadProperties() {
		InputStream ips = getClass().getResourceAsStream("/db.properties");
		Properties properties = new Properties();
		
		try {
			properties.load(ips);
			this.dbUrl = properties.getProperty("dburl");
			this.dbUsername = properties.getProperty("username");
			this.dbPassword = properties.getProperty("password");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

studentSystem.view

IndexFrame.java

package studentSystem.view;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import studentSystem.model.Admin;
import studentSystem.model.UserType;
import studentSystem.view.student.AddStudentFrame;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import java.awt.Font;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.awt.event.ActionEvent;
import javax.swing.JDesktopPane;
import java.awt.BorderLayout;
import java.awt.Color;

public class IndexFrame extends JFrame {
	private JDesktopPane desktopPane;
	
	private static UserType userType;
	private static Admin admin;
	public static AddStudentFrame addStudentFrame = null;
	/**
	 * Create the frame.
	 */
	public IndexFrame(UserType u,Admin a) {
		
		userType = u;
		admin = a;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 600);
		setLocationRelativeTo(null);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("学生信息");
		mnNewMenu.setFont(new Font("微软雅黑", Font.BOLD, 15));
		menuBar.add(mnNewMenu);
		
		JMenuItem mntmNewMenuItem = new JMenuItem("添加信息");
		mntmNewMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				addStudentInfo(ae);
			}
		});
		mntmNewMenuItem.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 14));
		mnNewMenu.add(mntmNewMenuItem);
		
		JMenuItem mntmNewMenuItem_1 = new JMenuItem("学生列表");
		mntmNewMenuItem_1.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 14));
		mnNewMenu.add(mntmNewMenuItem_1);
		
		JMenu mnNewMenu_1 = new JMenu("课程管理");
		mnNewMenu_1.setFont(new Font("微软雅黑", Font.BOLD, 15));
		menuBar.add(mnNewMenu_1);
		
		JMenuItem mntmNewMenuItem_2 = new JMenuItem("添加");
		mntmNewMenuItem_2.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 14));
		mnNewMenu_1.add(mntmNewMenuItem_2);
		
		JMenuItem mntmNewMenuItem_3 = new JMenuItem("课程列表");
		mntmNewMenuItem_3.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 14));
		mnNewMenu_1.add(mntmNewMenuItem_3);
		
		desktopPane = new JDesktopPane();
		desktopPane.setBackground(new Color(192, 192, 192));
		getContentPane().add(desktopPane, BorderLayout.CENTER);
	}
	

	protected void addStudentInfo(ActionEvent ae) {
		// TODO Auto-generated method stub
		if(addStudentFrame == null) {
			addStudentFrame = new AddStudentFrame();
			desktopPane.add(addStudentFrame);
		}
		
		addStudentFrame.setBounds((900-addStudentFrame.getWidth())/2,(600-addStudentFrame.getHeight())/2,500,400);
		addStudentFrame.setVisible(true);
		try {
			addStudentFrame.setSelected(true);
		}catch(PropertyVetoException e) {
			e.printStackTrace();
		}
	}
}

LoginFrame.java

package studentSystem.view;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import studentSystem.dao.AdminDao;
import studentSystem.model.Admin;
import studentSystem.model.UserType;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

@SuppressWarnings("serial")
public class LoginFrame extends JFrame {

	private JPanel contentPane;
	private JTextField adminName;
	private final JPasswordField adminPsd = new JPasswordField();
	private JComboBox<String> adminTypecomb;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LoginFrame frame = new LoginFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LoginFrame() {
		setTitle("登录系统");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 460, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("学生信息管理系统");
		lblNewLabel.setBounds(129, 10, 211, 51);
		lblNewLabel.setFont(new Font("楷体", Font.PLAIN, 26));
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("用户名:");
		lblNewLabel_1.setBounds(105, 92, 58, 15);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("密码:");
		lblNewLabel_2.setBounds(105, 139, 58, 15);
		contentPane.add(lblNewLabel_2);
		
		adminName = new JTextField();
		adminName.setBounds(160, 84, 157, 31);
		contentPane.add(adminName);
		adminName.setColumns(10);
		adminPsd.setBounds(160, 131, 158, 31);
		contentPane.add(adminPsd);
		
		JButton btnNewButton = new JButton("注册");
		btnNewButton.setBounds(22, 212, 97, 23);
		contentPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("登录");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				confirmButton(ae);
			}
		});
		btnNewButton_1.setBounds(129, 212, 97, 23);
		contentPane.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("重置");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				resetButton(ae);
			}
		});
		btnNewButton_2.setBounds(234, 212, 97, 23);
		contentPane.add(btnNewButton_2);
		
		JButton btnNewButton_2_1 = new JButton("取消");
		btnNewButton_2_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			System.exit(0);
			}
		});
		btnNewButton_2_1.setBounds(339, 212, 97, 23);
		contentPane.add(btnNewButton_2_1);
		
		JLabel lblNewLabel_3 = new JLabel("用户类型:");
		lblNewLabel_3.setBounds(89, 179, 74, 15);
		contentPane.add(lblNewLabel_3);
		
		adminTypecomb = new JComboBox();
		adminTypecomb.setModel(new DefaultComboBoxModel(new UserType[] {UserType.ADMIN,UserType.STUDENT,UserType.TEACHER}));
		adminTypecomb.setBounds(160, 171, 174, 31);
		contentPane.add(adminTypecomb);
		
		btnNewButton.setFocusable(false);
		btnNewButton_1.setFocusable(false);
		btnNewButton_2.setFocusable(false);
		btnNewButton_2_1.setFocusable(false);
		
		setLocationRelativeTo(null);
	}

	protected void confirmButton(ActionEvent ae) {
		// TODO Auto-generated method stub
		String name = this.adminName.getText();
		String password = this.adminPsd.getText();
		 UserType userType = (UserType) this.adminTypecomb.getSelectedItem();
		
		if("系统管理员".equals(userType.getName())) {
			AdminDao adminDao = new AdminDao();
			Admin admin = adminDao.selectAdmin(name, password);
			
			if(admin == null) {
				JOptionPane.showMessageDialog(this, "用户名或密码错误");
				return;
			}
			IndexFrame indexFrame = new IndexFrame(userType,admin);
			indexFrame.setVisible(true);
			this.dispose();
		}else if("学生".equals(userType.getName())) {
			
		}else {
			
		}
	}

	protected void resetButton(ActionEvent ae) {
		// TODO Auto-generated method stub
		this.adminName.setText("");
		this.adminPsd.setText("");
		this.adminTypecomb.setSelectedIndex(0);
	}
}

studentSystem.view.student

AddStudentFrame.java

package studentSystem.view.student;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JList;
import javax.swing.JCheckBox;

public class AddStudentFrame extends JInternalFrame {
	private JTextField studentNameText;
	private JTextField studentIdtext;
	private JRadioButton maleRadioBtn;
	private JRadioButton femaleRadioBtn;
	private JCheckBox chineseCheckBox;
	private JCheckBox mathCheckBox;
	private JCheckBox englishCheckBox;


	/**
	 * Create the frame.
	 */
	public AddStudentFrame() {
		setClosable(true);
		setTitle("正在添加学生信息...");
		setBounds(100, 100, 538, 400);
		getContentPane().setLayout(null);
		
		JLabel lblNewLabel = new JLabel("学生姓名:");
		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		lblNewLabel.setBounds(49, 55, 72, 18);
		getContentPane().add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("学生性别:");
		lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		lblNewLabel_1.setBounds(267, 55, 72, 18);
		getContentPane().add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("学生学号:");
		lblNewLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		lblNewLabel_2.setBounds(49, 141, 72, 18);
		getContentPane().add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("所选课程:");
		lblNewLabel_3.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		lblNewLabel_3.setBounds(267, 143, 64, 15);
		getContentPane().add(lblNewLabel_3);
		
		studentNameText = new JTextField();
		studentNameText.setBounds(131, 55, 104, 21);
		getContentPane().add(studentNameText);
		studentNameText.setColumns(10);
		
		JRadioButton maleRadioBtn = new JRadioButton("男");
		maleRadioBtn.setBounds(332, 54, 47, 23);
		getContentPane().add(maleRadioBtn);
		
		JRadioButton femaleRadioBtn = new JRadioButton("女");
		femaleRadioBtn.setBounds(393, 54, 57, 23);
		getContentPane().add(femaleRadioBtn);
		
		ButtonGroup bg = new ButtonGroup();
		bg.add(maleRadioBtn);
		bg.add(femaleRadioBtn);
		
		JButton btnNewButton = new JButton("确认");
		btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 12));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnNewButton.setBounds(113, 302, 97, 23);
		getContentPane().add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("重置");
		btnNewButton_1.setFont(new Font("微软雅黑", Font.BOLD, 12));
		btnNewButton_1.setBounds(309, 302, 97, 23);
		getContentPane().add(btnNewButton_1);
		
		studentIdtext = new JTextField();
		studentIdtext.setBounds(131, 140, 103, 23);
		getContentPane().add(studentIdtext);
		studentIdtext.setColumns(10);
		
		JCheckBox chineseCheckBox = new JCheckBox("语文");
		chineseCheckBox.setBounds(332, 140, 64, 23);
		getContentPane().add(chineseCheckBox);
		
		JCheckBox mathCheckBox = new JCheckBox("数学");
		mathCheckBox.setBounds(393, 140, 64, 23);
		getContentPane().add(mathCheckBox);
		
		JCheckBox englishCheckBox = new JCheckBox("英语");
		englishCheckBox.setBounds(332, 183, 64, 23);
		getContentPane().add(englishCheckBox);

	}
	
	public void doDefaultCloseAction() {
		this.setVisible(false);
	}
}

module-info.java

studentSystem

/**
 * 
 */
/**
 * @author HP
 *
 */
module studentSystem {
	requires java.desktop;
	requires java.sql;
}

db.properties

dburl = jdbc:mysql://localhost:3306/studentsystem?characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
username = root
password = miao1314520

项目截图:

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值