📄 bussinessservices.java
字号:
package edu.sist200.services;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javax.swing.JOptionPane;
import edu.sist200.model.Course;
import edu.sist200.model.SC;
import edu.sist200.model.Student;
import edu.test.demo.FileManage;
import gui.YXKC;
public class BussinessServices {
Scanner scan=new Scanner(System.in);
public List addStu(Student stu)
{
List l=new ArrayList();
File file = new File("students.txt");
if(file.exists()){
try {
l=(List)FileManage.findObject("students.txt");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
l.add(stu);
try {
for (int i=0; i < l.size(); i++){
Student s=(Student)l.get(i);
System.out.println(s.getSno());
}
FileManage.addObject(l, "students.txt");
System.out.println(l.size());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return l;
}
public boolean stulogin(Student s)
{
boolean f=false;
int i = 0;
List l=new ArrayList();
try {
l=(List)FileManage.findObject("students.txt");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Student stu = null;
String sno=s.getSno();
String pwd=s.getPassword();
for (; i < l.size(); i++)
{
stu = (Student) l.get(i);
if(stu.getSno().equals(sno)&&stu.getPassword().equals(pwd)){
f=true;
break;
}
}
return f;
}
public boolean chooseCou(Student stu,Course c){
File fileC = new File("courses.txt");
boolean flag=false;
if(fileC.exists()){
List scl=new ArrayList();
File file = new File("scs.txt");
if(file.exists()){
try {
scl=(List)FileManage.findObject("scs.txt");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
boolean f=true;
List cl=null;
try {
cl = (List)FileManage.findObject("courses.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
queryCou();
SC sc=new SC();
String cno=c.getCno();
int i = 0;
String ct=c.getCteacher();
for (; i < cl.size(); i++) {
Course course = (Course) cl.get(i);
if(cno.equals(course.getCno())&&ct.equals(course.getCteacher())){
sc.setCourse(course);
sc.setStudent(stu);
scl.add(sc);
System.out.println("选课成功!!!!");
flag=true;
break;
}
}
if(i==cl.size()){
System.out.println("该课程不存在!!!");
}
try {
FileManage.addObject(scl, "scs.txt");
return flag;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
System.out.println("目前没有课程可以选择!");
}
return flag;
}
public List addCourse(Course course)
{
List cl=new ArrayList();
File file = new File("courses.txt");
if(file.exists()){
try {
cl=(List)FileManage.findObject("courses.txt");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
cl.add(course);
try {
FileManage.addObject(cl, "courses.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null,"添加失败!");
}
return cl;
}
public List queryCou(){
List cl=null;
File file = new File("courses.txt");
if(file.exists()){
try {
cl = (List)FileManage.findObject("courses.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return cl;
}else
{
return cl;
}
}
public List queryStuCou(Student stu){
List scl=null;
List rs=new ArrayList();;
int j=0;
File file = new File("scs.txt");
if(file.exists()){
try {
scl = (List)FileManage.findObject("scs.txt");
int t=1;
for (int i = 0; i < scl.size(); i++) {
SC sc=(SC)scl.get(i);
Student s=sc.getStudent();
if(stu.getSno().equals(s.getSno())){
Course course=sc.getCourse();
rs.add(course);
System.out.println(course.getCno());
j=1;
}
}
if(j==0){
JOptionPane.showMessageDialog(null, "该学生没有选课!!请选您要选的课程:");
}
return rs;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
JOptionPane.showMessageDialog(null, "该学生没有选课!!请选您要选的课程:");
}
return rs;
}
public void student(){
boolean flag=true;
while(flag){
System.out.println("学生注册请输入1: ");
System.out.println("学生选课请输入2: ");
System.out.println("退出请输入3: ");
switch(scan.nextInt()){
case 1:
//addStu();break;
case 2:
//stulogin();
break;
case 3:
flag=false;
System.out.println("欢迎使用");break;
default:
System.out.println("操作不存在!!!");
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
BussinessServices s=new BussinessServices();
//s.addStu();
//s.addCourse();
//s.stulogin();
//s.adminlogin();
//s.queryCou();
//s.addStu();
//s.stulogin();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -