java编写学生成绩管理系统代码

 

//student

import java.sql.*;

 

public class Student

{

       private String id;

       private String name;

       private int math;

       private int english;

       private int java;

       private int computer;

 

       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 int getMath()

       {

              return math;

       }

 

       public void setMath(int math)

       {

              this.math = math;

       }

 

       public int getEnglish()

       {

              return english;

       }

 

       public void setEnglish(int english)

       {

              this.english = english;

       }

 

       public int getJava()

       {

              return java;

       }

 

       public void setJava(int java)

       {

              this.java = java;

       }

 

       public int getComputer()

       {

              return computer;

       }

 

       public void setComputer(int computer)

       {

              this.computer = computer;

       }

 

       public static void main(String[] args) throws Exception

       {

              String id;

              String cid;

              String name;

              int math;

              int english;

              int java;

              int computer;

              String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";

              String conStr = "jdbc:odbc:student";

              Connection con = null;

              Statement stmt = null;

              ResultSet rs = null;

              Class.forName(DBDriver);

              con = DriverManager.getConnection(conStr, "student", "123");

              stmt = con.createStatement();

              String s = "\n\n\t\t\t学 生 成 绩\n\n\t\t 1 新 增\n\t\t 2 更 改\n\t\t 3 删 除\n\t\t 4 查 找\n\t\t 5 显 示\n\t\t 0 退 出\n\n";

              System.out.print(s);

              int choice = Keyboard.getInteger();

              switch (choice)

              {

 

                     // 添加学生

                     case 1:

                            System.out.print("请输入学生信息\n");

                            System.out.print("学号:");

                            id = Keyboard.getString();

                            System.out.print("姓名:");

                            name = Keyboard.getString();

                            System.out.print("数学:");

                            math = Keyboard.getInteger();

                            System.out.print("英语:");

                            english = Keyboard.getInteger();

                            System.out.print("JAVA:");

                            java = Keyboard.getInteger();

                            System.out.print("计算机:");

                            computer = Keyboard.getInteger();

                            stmt.executeUpdate("insert into lxh1 values('" + id + "','"

                                          + name + "','" + math + "','" + english + "','" + java

                                          + "','" + computer + "')");

                            System.out.println("\n添加完成。");

                            break;

 

                     // 更改成绩

                     case 2:

 

                                   System.out.println("请输入要改的学生学号:");

                                   cid = Keyboard.getString();

                                   System.out.println("数学:");

                                   math = Keyboard.getInteger();

                                   System.out.println("英语:");

                                   english = Keyboard.getInteger();

                                   System.out.println("JAVA:");

                                   java = Keyboard.getInteger();

                                   System.out.println("计算机:");

                                   computer = Keyboard.getInteger();

                                   stmt.executeUpdate("update lxh1 set math='" + math + "',english='"

                                                 + english + "',java='" + java + "',computer='" + computer

                                                 + "' where sno=" + cid + "");

                                   System.out.println("\n修改完成");

                                   break;

 

 

                     // 删除指定学生

                     case 3:

                            System.out.println("请输入要改的学生学号:");

                            cid = Keyboard.getString();

                            stmt.executeUpdate("delete from lxh1 where sno=" + cid + "");

                            System.out.println("\n删除完成");

                            break;

 

                     // 显示指定学生

                     case 4:

                            System.out.println("请输入查找的学生学号:");

                            cid = Keyboard.getString();

                            System.out.println("\n" + cid

                                          + "号学生信息\n\n学号\t姓名\t数学\t英语\tJAVA\t计算机\t");

                            rs = stmt.executeQuery("select * from lxh1 where sno=" + cid

                                          + "");

                            while (rs.next())

                            {

                                   System.out.println(rs.getInt("sno") + "\t"

                                                 + rs.getString("sname") + "\t" + rs.getString("math")

                                                 + "\t" + rs.getString("english") + "\t"

                                                 + rs.getString("java") + "\t"

                                                 + rs.getString("computer") + "\t");

                            }

                           

                            break;

 

                     case 5:

                            // 输出全部信息

                            System.out.println("\n全部学生信息\n\n学号\t姓名\t数学\t英语\tJAVA\t计算机\t平均成绩");

                            rs = stmt.executeQuery("select * from lxh1 order by math desc");

                            while (rs.next())

                            {

                                   int a = rs.getInt("math");

                                   int b = rs.getInt("english");

                                   int c = rs.getInt("java");

                                   int d = rs.getInt("computer");

                                   System.out.println(rs.getString("sno") + "\t"

                                                 + rs.getString("sname") + "\t" + a + "\t" + b + "\t"

                                                 + c + "\t" + d + "\t" + ((a + b + c + d) / 4));

                            }

                            ;

 

                            // 输出平均分

                            System.out.println("\n各科平均分\n\n数学\t英语\tJAVA\t计算机\t");

                            rs = stmt

                                          .executeQuery("select avg(math),avg(english),avg(java),avg(computer) from lxh1");

                            while (rs.next())

                            {

                                   System.out.println(rs.getInt(1) + "\t" + rs.getInt(2) + "\t"

                                                 + rs.getInt(3) + "\t" + rs.getInt(4));

                            }

                            ;

 

                            // 输出最高分

                            System.out.println("\n各科最高分\n\n数学\t英语\tJAVA\t计算机\t");

                            rs = stmt.executeQuery("select max(math),max(english),max(java),max(computer) from lxh1");

                            while (rs.next())

                            {

                                   System.out.println(rs.getInt(1) + "\t" + rs.getInt(2) + "\t"

                                                 + rs.getInt(3) + "\t" + rs.getInt(4));

                            }

                            ;

 

                            // 输出最低分

                            System.out.println("\n各科最低分\n\n数学\t英语\tJAVA\t计算机\t");

                            rs = stmt

                                          .executeQuery("select min(math),min(english),min(java),min(computer) from lxh1");

                            while (rs.next())

                            {

                                   System.out.println(rs.getInt(1) + "\t" + rs.getInt(2) + "\t"

                                                 + rs.getInt(3) + "\t" + rs.getInt(4));

                            }

                            ;

                            break;

 

                     case 0:

                            break;

 

                     default:

                            System.out.println("感谢您的使用,再见!");

              }

              ;

              stmt.close();

              con.close();

       }

}

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值