实现抢课的java程序_求用JAVA为我写一个简单的选课系统程序,实现增,删,改,查功能...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

SQL脚本我已经写好,求高人帮忙。

--创建数据库学生

create database student

go

--使用数据库

use student

go

--创建学生信息表

create table stuInfo

(

sno char(11) not null check(sno like '513%') primary key,

sname char(8) not null,

sex char(2) not null check(sex in ('男','女')),

age int not null check(age between 18 and 50) default(18),

class char(4) not null,

nation char(10) not null

)

go

--创建课程信息表

create table course

(

cid int not null check(cid between 1 and 100) primary key,

cname char(10) not null unique,

ct int not null check(ct between 1 and 200),

tscore int not null default(100),

mark varchar(50)

)

go

--创建学生选课表

create table sc

(

sno char(11) not null,

cid int not null,

score float not null default(0)

)

go

--加约束

--联合主键

alter table sc

add constraint PK_sc primary key(sno,cid)

go

--加外键+级联

alter table sc

add constraint FK_sno foreign key(sno) references stuInfo(sno) on delete cascade on update cascade

go

alter table sc

add constraint FK_cid foreign key(cid) references course(cid)  on delete cascade on update cascade

go

--创建权限表

create table login

(

lid int not null identity(1,1) primary key,

admin char(20) not null unique,

pwd char(20) not null,

jb char(6) not null check(jb in ('管理员','学生'))

)

go

--------------------------------------------------------------------------

--插入

insert into stuInfo values('51360522017','张三','男',default,'T25','中国湖北')

insert into course values(1,'s1-java',100,100,null)

insert into sc values('51360522017',1,90)

insert into login values('wgf','123456','管理员')

insert into login values('张三','123456','学生')

go

--查询

select * from stuInfo

select * from course

select * from sc

select * from login

go

-------------------------------------------------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一个简单的学生选课系统Java代码,实现操作,不需要连接数据库。 首先,我们需要定义一个学生类和一个课程类,如下所示: ``` public class Student { private String name; private int id; private List<Course> courses; public Student(String name, int id) { this.name = name; this.id = id; this.courses = new ArrayList<>(); } public void enroll(Course course) { courses.add(course); } public void unenroll(Course course) { courses.remove(course); } public List<Course> getCourses() { return courses; } } public class Course { private String name; private int id; private int capacity; private List<Student> students; public Course(String name, int id, int capacity) { this.name = name; this.id = id; this.capacity = capacity; this.students = new ArrayList<>(); } public boolean addStudent(Student student) { if (students.size() < capacity) { students.add(student); return true; } else { return false; } } public boolean removeStudent(Student student) { return students.remove(student); } public List<Student> getStudents() { return students; } } ``` 然后,我们可以在主函数中创建学生和课程对象,并进行操作,如下所示: ``` public static void main(String[] args) { // 创建学生和课程对象 Student alice = new Student("Alice", 1); Student bob = new Student("Bob", 2); Course math = new Course("Math", 1, 2); Course english = new Course("English", 2, 1); // 学生选课 math.addStudent(alice); math.addStudent(bob); english.addStudent(alice); // 询课程学生信息 System.out.println(math.getStudents()); System.out.println(english.getStudents()); // 询学生课程信息 System.out.println(alice.getCourses()); System.out.println(bob.getCourses()); // 学生退课 math.removeStudent(alice); // 询课程学生信息 System.out.println(math.getStudents()); // 询学生课程信息 System.out.println(alice.getCourses()); } ``` 以上代码仅为示例,可以根据实际需求进行修和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值