📄 c1_1.java
字号:
import java.awt.*;
import java.io.*;
import java.sql.*;
/**************************************************************************************************************/
/*********************************************学生类的定义***************************************************/
/*************************************************************************************************************/
class student
{
public String name;
public String department;
public String sex;
public String num;
public String birthday;
public int[] course={0,0,0,0,0,0,0,0};
public String password;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////构造函数//////////////////////////////////////////////////
student(String name,String department,String birthday,String sex,String num,String password)
{
this.name=name;
this.department=department;
this.birthday=birthday;
this.sex=sex;
this.num=num;
this.password=password;
}
student()//不带参数的构造函数
{
BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("请输入姓名:");
name=keyin.readLine();
System.out.println("请输入专业:");
department=keyin.readLine();
System.out.println("请输入生日 格式如:1987\\08\\23");
birthday=keyin.readLine();
System.out.println("请输入性别(F/M):");
sex=keyin.readLine();
System.out.println("请输入学号:");
num=keyin.readLine();
}
catch(IOException E)
{ System.out.println("I/O错误!");}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////显示函数//////////////////////////////////////////////////
void show( )
{
System.out.println("姓名: "+name);
System.out.println("专业:"+department);
System.out.println("出生日期 :"+birthday);
System.out.println("性别: "+sex);
System.out.println("学号: "+num);
System.out.println("密码: "+password);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////显示课程函数//////////////////////////////////////////////
void c_show()
{
System.out.println("\t课程编号\t课程名\t\t成绩");
String conURL="jdbc:odbc:student";
try
{
Connection con=DriverManager.getConnection(conURL);
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select * From C,SC where C.ID=SC.CID and SC.SID="+this.num);
while(rs.next())
{
System.out.println("\t"+rs.getString("ID")+"\t"+rs.getString("Name")+""+rs.getString("Score"));
}
s.close();
con.close();
}
catch(SQLException e)
{
System.out.println("SQLException:"+e.getMessage());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////修改密码函数//////////////////////////////////////////////
void changepaw(String type)
{
String newpaw,newpaw1;
BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("请输入你现在的密码:");
newpaw=keyin.readLine();
if(newpaw.equalsIgnoreCase(password))
{
System.out.println("请输入你的新密码:");
newpaw=keyin.readLine();
System.out.println("请再次输入密码:");
newpaw1=keyin.readLine();
if(newpaw.equalsIgnoreCase(newpaw1))
{
password=newpaw;
String conURL="jdbc:odbc:student";
try
{
Connection con=DriverManager.getConnection(conURL);
Statement s=con.createStatement();
s.executeUpdate("UPDATE "+type+" set password='"+newpaw+"' where ID="+this.num);
s.close();
con.close();
System.out.println("新密码设置成功!");
System.out.println(newpaw);
}
catch(SQLException e)
{
System.out.println("SQLException:"+e.getMessage());
}
}
else
System.out.println("对不起!你的新密码不一致.修改失败!请重新设置!");
}
else
System.out.println("对不起,密码不正确!");
}
catch(IOException E)
{ System.out.println("I/O错误!");}
}
void chose()
{
String no="00000",ID="0000000001";
BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
String conURL="jdbc:odbc:student";
try
{
Connection con=DriverManager.getConnection(conURL);
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select ID,Name From C");
while(rs.next())
{
System.out.println("\t"+rs.getString("ID")+"\t"+rs.getString("Name"));
}
s.close();
Statement s1=con.createStatement();
try
{
System.out.println("请输入你选择的课程序号:");
no=keyin.readLine();
}
catch (IOException E)
{ System.out.println("I/O错误!");}
ID="insert into SC(SID,Score,CID) values('"+this.num+"',0,'"+no+"')";
System.out.println(ID);
s1.executeUpdate(ID);
con.close();
}
catch(SQLException e)
{
System.out.println("SQLException:"+e.getMessage());
}
}
}
/**************************************************************************************************************/
/*********************************************课程类的定义***************************************************/
/*************************************************************************************************************/
class coures
{
public String name;
public int num;
public int s_num;
public String tnum;
public coures( )
{
BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("请输入课程名称:");
this.name=keyin.readLine( );
System.out.println("请输入授课教师工号:");
this.tnum=keyin.readLine( );
System.out.println(" 请输入课程编号:");
this.num=System.in.read( );
}
catch(IOException E)
{ System.out.println("I/O错误!");}
}
public void show()
{
System.out.println("课程名:"+name);
System.out.println("课程号:"+num);
System.out.println("授课老师:"+tnum);
}
}
/**************************************************************************************************************/
/*********************************************教师类的定义***************************************************/
/*************************************************************************************************************/
class teacher extends student
{
String post;
public teacher(String name,String department,String birthday,String sex,String num,String password,String post)
{
super(name,department,birthday,sex,num,password);
this.post=post;
}
teacher()
{
super();
BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
try
{ System.out.println("请输入职称:");
post=keyin.readLine();
}
catch(IOException E)
{ System.out.println("I/O错误!");}
}
public void show()
{
super.show();
System.out.println("职称: "+post);
}
public void course()
{
System.out.println("\t\t课程编号\t课程名");
String conURL="jdbc:odbc:student";
try
{
Connection con=DriverManager.getConnection(conURL);
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select * From C where C.TID='"+this.num +"'");
while(rs.next())
{
System.out.println("\t"+rs.getString("ID")+"\t"+rs.getString("Name"));
}
s.close();
con.close();
}
catch(SQLException e)
{
System.out.println("SQLException:"+e.getMessage());
}
}
public void score()
{
String id=" ";
String conURL="jdbc:odbc:student";
BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
try
{
Connection con=DriverManager.getConnection(conURL);
Statement s=con.createStatement();
try
{
System.out.println("请输入你想要察看的课程编号");
id=keyin.readLine();
}
catch(IOException E)
{ System.out.println("I/O错误!");}
System.out.println("\t\t课程编号\t课程名");
ResultSet rs=s.executeQuery("select Name,Score From SC,S where S.ID=SC.SID and SC.CID='"+id+"'");
while(rs.next())
{
System.out.println("\t"+rs.getString("Name")+"\t"+rs.getString("Score"));
}
s.close();
con.close();
}
catch(SQLException e)
{
System.out.println("SQLException:"+e.getMessage());
}
}
public void loadscore() //缺少
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -