lListStudent students = new ArrayListStudent();
我们提供的服务有:网站设计、成都做网站、微信公众号开发、网站优化、网站认证、博野ssl等。为上千企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的博野网站制作公司
BufferedReader br = new BufferedReader(new FileReader("D:\student.txt"));
String tmpStr = br.readLine();
while(tmpStr != null){
int firstIndex = tmpStr.indexOf(" ");
int secondIndex = tmpStr.indexOf(" ",firstIndex + 1);
int thirdIndex = tmpStr.indexOf(" ", secondIndex + 1);
int forthIndex = tmpStr.indexOf(" ", thirdIndex + 1);
Integer stuId = Integer.parseInt(tmpStr.substring(0,firstIndex));
String stuName = tmpStr.substring(firstIndex + 1,secondIndex);
Integer stuYW = Integer.parseInt(tmpStr.substring(secondIndex + 1,thirdIndex));
Integer stuSX = Integer.parseInt(tmpStr.substring(thirdIndex + 1,forthIndex));
Integer stuYY = Integer.parseInt(tmpStr.substring(forthIndex + 1));
Student student = new Student();
student.setStuId(stuId);
student.setStuName(stuName);
student.setStuYW(stuYW);
student.setStuSX(stuSX);
student.setStuYY(stuYY);
students.add(student);
tmpStr.readLine();
}
//创建一个学生实体类 封装stuId stuName stuYW stuSx stuYY 这5个属性。。。
//已经帮你把数据拆分出来 并以Student 对象的形式放入集合中了 接下来 给分吧 哇咔咔
package jdbcproj;
import java.sql.*;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
public class MainFrame extends JFrame {
private JPanel contentPane;
private JTextField txtname;
private JTextField txtpassword;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrame frame = new MainFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 661, 399);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("\u7528\u6237\u540D");
lblNewLabel.setBounds(114, 51, 72, 18);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("\u5BC6\u7801");
lblNewLabel_1.setBounds(114, 106, 72, 18);
contentPane.add(lblNewLabel_1);
txtname = new JTextField();
txtname.setBounds(261, 48, 86, 24);
contentPane.add(txtname);
txtname.setColumns(10);
txtpassword = new JTextField();
txtpassword.setBounds(261, 103, 86, 24);
contentPane.add(txtpassword);
txtpassword.setColumns(10);
JButton btnadd = new JButton("\u589E\u52A0");
btnadd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(txtname.getText().equals("")||txtpassword.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(), "用户名和密码不能为空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Users u=new Users();
u.setPwd(txtpassword.getText());
u.setUsername(txtname.getText());
UserDAO usdo=new UserDAO();
usdo.addUser(u);
}
}
});
btnadd.setBounds(45, 205, 113, 27);
contentPane.add(btnadd);
JButton btndelete = new JButton("\u5220\u9664");
btndelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(txtname.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(), "用户名不能为空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
UserDAO usdo=new UserDAO();
usdo.delUser(txtname.getText())
}
}
});
btndelete.setBounds(172, 205, 113, 27);
contentPane.add(btndelete);
JButton btnupdate = new JButton("\u4FEE\u6539");
btnupdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(txtname.getText().equals("")||txtpassword.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(), "用户名和密码不能为空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Users u=new Users();
u.setPwd(txtpassword.getText());
u.setUsername(txtname.getText());
UserDAO usdo=new UserDAO();
usdo.updateUser(u)
}
}
});
btnupdate.setBounds(300, 205, 113, 27);
contentPane.add(btnupdate);
JButton btnfind = new JButton("\u67E5\u8BE2");
btnfind.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(txtname.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(), "用户名不能为空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Users u=new Users();
UserDAO usdo=new UserDAO();
u=usdo.findUser(txtname.getText(), txtpassword.getText());
if(u!=null){
JOptionPane.showMessageDialog(getContentPane(), "该用户存在!","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
JOptionPane.showMessageDialog(getContentPane(), "该用户不存在!","提示信息框",JOptionPane.WARNING_MESSAGE);
}
}
}
});
btnfind.setBounds(427, 205, 113, 27);
contentPane.add(btnfind);
//记得要写这个
setVisible(true);
}
}
完成了,希望能帮到你
刚开始会叫你输入编号选择功能
import java.io.*;
public class student {
public static void main(String args[]) throws IOException{
int[] stud = {77,99,55,46,82,75,65,31,74,85};
System.out.println("请选择功能:");//输入编号选择功能
System.out.println("1、输入学号,查询该学生成绩:");
System.out.println("2、输入成绩,查询学生学号:");
System.out.println("3、输入学号,删除该学生成绩");
System.out.println("请选择编号:");
BufferedReader td = new BufferedReader(new InputStreamReader(System.in));
String temp = td.readLine();
int choice = Integer.valueOf(temp);
if(choice == 1){//一为查询学生成绩
System.out.println("请输入学号:");
BufferedReader sd = new BufferedReader(new InputStreamReader(System.in));
String temp_sd = sd.readLine();
int No = Integer.valueOf(temp_sd);
System.out.print("学号为 "+No+" 的学生成绩为: " + stud[No-1] +"分");
}
if(choice == 2){//二为查询学生编号
System.out.println("请输入成绩:");
BufferedReader sd = new BufferedReader(new InputStreamReader(System.in));
String chengji = sd.readLine();
int temp_cj = Integer.valueOf(chengji);
for(int i=0;istud.length;i++){
if(temp_cj == stud[i]){
System.out.print("成绩为 "+ temp_cj+ "的学生的学号为: "+(i+1));
}
}
}
if(choice == 3){//三为删除操作
System.out.println("请输入学号:");
BufferedReader sd = new BufferedReader(new InputStreamReader(System.in));
String temp_sd = sd.readLine();
int No = Integer.valueOf(temp_sd);
stud[No-1]=0;//直接赋值为0,不删除学生
System.out.print("学号为 "+No+" 的学生成绩为: " + stud[No-1] +"分");
}
}
}
用java写的话,可以用List来实现学生管理系统:\x0d\x0a首先,管理系统是针对学生对象的,所以我们先把学生对象就写出来:\x0d\x0apackage bean;\x0d\x0apublic class Student {\x0d\x0a String name;\x0d\x0a String studentId;\x0d\x0a String sex;\x0d\x0a int grade;\x0d\x0a public Student(String name,String studentId,String sex,int grade){\x0d\x0a this.name= name;\x0d\x0a this.studentId= studentId;\x0d\x0a this.sex = sex;\x0d\x0a this.grade = grade; \x0d\x0a }\x0d\x0a public int getGrade(){\x0d\x0a return grade;\x0d\x0a }\x0d\x0a public String getName(){\x0d\x0a return name;\x0d\x0a }\x0d\x0a public String getSex(){\x0d\x0a return sex;\x0d\x0a }\x0d\x0a public void setGrade(int g){\x0d\x0a this.grade = g;\x0d\x0a }\x0d\x0a public String getStudentId(){\x0d\x0a return studentId;\x0d\x0a }\x0d\x0a}\x0d\x0a这里面定义了一些得到当前学生对象数据的一些get方法,和成绩修改的set方法,代码很简单,就不做详细的解答。\x0d\x0a就下来就是我们的正文了。\x0d\x0a虽然我们暂时不用swing来做界面,但是总得要看的过去吧,所以,先做了一个比较简单的界面:\x0d\x0a System.out.println("***************");\x0d\x0a System.out.println("*欢迎来到学生管理系统 *");\x0d\x0a System.out.println("*1:增加学生 *");\x0d\x0a System.out.println("*2:删除学生 *");\x0d\x0a System.out.println("*3:修改成绩 *");\x0d\x0a System.out.println("*4:查询成绩 *");\x0d\x0a System.out.println("***************");\x0d\x0a System.out.println("您想选择的操作是:");\x0d\x0a这里可以看到,我们的是用一个1234来选择项目,说以不得不讲一下Java如何获取到键盘所输入的数据---------Scanner ,要使用这个,首先需要import进来一个包:\x0d\x0a例如这里:\x0d\x0aimport java.util.*;\x0d\x0a之后的两行代码搞定输入:\x0d\x0aScanner sc = new Scanner(System.in);\x0d\x0a int choice = sc.nextInt();\x0d\x0a接下来就是各个功能的实现:\x0d\x0a\x0d\x0apackage test;\x0d\x0aimport java.util.*;\x0d\x0aimport bean.Student;\x0d\x0apublic class Manager {\x0d\x0a static List StudentList = new LinkedList();\x0d\x0a public static void main(String[] agrs){\x0d\x0a select(StudentList); \x0d\x0a }\x0d\x0a private static void select(List StudentList ){\x0d\x0a System.out.println("***************");\x0d\x0a System.out.println("*欢迎来到学生管理系统 *");\x0d\x0a System.out.println("*1:增加学生 *");\x0d\x0a System.out.println("*2:删除学生 *");\x0d\x0a System.out.println("*3:修改成绩 *");\x0d\x0a System.out.println("*4:查询成绩 *");\x0d\x0a System.out.println("***************");\x0d\x0a System.out.println("您想选择的操作是:");\x0d\x0a Scanner sc = new Scanner(System.in);\x0d\x0a int choice = sc.nextInt(); \x0d\x0a switch(choice){\x0d\x0a //增加学生\x0d\x0a case 1:\x0d\x0a System.out.print("请输入学生的姓名:");\x0d\x0a Scanner Sname = new Scanner(System.in);\x0d\x0a String name = Sname.nextLine();\x0d\x0a System.out.print("请输入学生的性别:");\x0d\x0a Scanner Ssex = new Scanner(System.in);\x0d\x0a String sex = Ssex.nextLine();\x0d\x0a System.out.print("请输入学生的学号:");\x0d\x0a Scanner SId = new Scanner(System.in);\x0d\x0a String studentId = SId.nextLine();\x0d\x0a System.out.print("请输入学生的成绩:");\x0d\x0a Scanner Sgrade = new Scanner(System.in);\x0d\x0a int grade = Sgrade.nextInt();\x0d\x0a StudentList.add(new Student(name,studentId,sex,grade));\x0d\x0a System.out.println("添加成功!!!!!");\x0d\x0a select(StudentList);\x0d\x0a break;\x0d\x0a //删除学生成绩\x0d\x0a case 2:\x0d\x0a System.out.print("请告诉我需要删除学生的学号:");\x0d\x0a Scanner Sid = new Scanner(System.in);\x0d\x0a String SstudentId = Sid.nextLine();\x0d\x0a boolean isfindDelete = false;\x0d\x0a for (int i = 0; i
回答于 2022-11-16
本文题目:java教学管理系统代码 javaweb教务管理系统源码
文章起源:https://www.cdcxhl.com/article12/ddedpdc.html
成都网站建设公司_创新互联,为您提供企业建站、自适应网站、微信公众号、全网营销推广、做网站、静态网站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联