⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentda.java

📁 学生成绩管理系统
💻 JAVA
字号:
package teamwork;

import java.io.*;
/**
 * <p>Title: teamwork</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author yeliang
 * @version 1.0
 */
public class studentDA {

    int num_student;
    int num_course;
    student[] students = new student[1000];
    //course[] courses = new course[40];   //记录课程总数

    public studentDA() {
        num_student = 0;
        num_course = 0;
        for(int i=0;i<1000;i++) students[i] = new student();
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        //for(int i=0;i<40;i++) courses[i] = new course();
    }

    public void readdata(){
        try{
            num_student = 0;
            for(int i=0;i<4;i++)
                students[num_student].inf_tearm[0].num = 0;
            File read = new File("data.data");
            BufferedReader readf = new BufferedReader(new FileReader(read));
            String temp = readf.readLine();
            while(temp != null){
                for(int i=0;i<4;i++){         //截取name;id;classNo三个成员数据
                    int spaceIndex = temp.indexOf(" ");
                    if(i==0)students[num_student].name = temp.substring(0,spaceIndex);
                    if(i==1)students[num_student].classNo = temp.substring(0,spaceIndex);
                    if(i==2)students[num_student].id = temp.substring(0,spaceIndex);
                    if(i==3)students[num_student].sex = temp.substring(0,spaceIndex);
                    temp = temp.substring(spaceIndex+1,temp.length());

                }
                while(!temp.equals(""))
                {
                    if(temp.indexOf(" ")>0){
                        //确定第几学期
                        int spaceIndex = temp.indexOf(" ");
                        String s = temp.substring(0,spaceIndex);
                        int tearm = Integer.parseInt(s) - 1;
                        temp = temp.substring(spaceIndex+1,temp.length());

                        //课程信息
                        spaceIndex = temp.indexOf(" ");
                        s = temp.substring(0,spaceIndex);
                        students[num_student].inf_tearm[tearm].sub[students[num_student].inf_tearm[tearm].num] = s;
                        temp = temp.substring(spaceIndex+1,temp.length());
                        spaceIndex = temp.indexOf(" ");
                        if(!(temp.indexOf(" ")>0)){
                            students[num_student].inf_tearm[tearm].sub_mark[students[num_student].inf_tearm[tearm].num] = Integer.parseInt(temp);
                            temp = "";
                        }
                        else{
                            s = temp.substring(0,spaceIndex);
                            students[num_student].inf_tearm[tearm].sub_mark[students[num_student].inf_tearm[tearm].num] = Integer.parseInt(s);
                            //System.out.print(s+" "+students[num_student].inf_tearm[tearm].num+"\n");
                            temp = temp.substring(spaceIndex+1,temp.length());
                        }
                        students[num_student].inf_tearm[tearm].num ++;
                    }
                }
                //print_inf(students[n]);

                temp = readf.readLine();
                num_student = num_student + 1;
            }

            readf.close();
        }catch(FileNotFoundException e){
            System.out.print(e);
        }catch(IOException e){
            System.out.print(e);
        }

    }

    public void writedata(){
        String str="";
        for(int i=0;i<num_student;i++){
            str += students[i].name+" "+students[i].classNo+" "+students[i].id+" "+students[i].sex;
            for(int j=0;j<4;j++){
                int k = 0;
                while(students[i].inf_tearm[j].sub[k]!=null){
                    str += " "+(j+1)+" "+students[i].inf_tearm[j].sub[k]+" "+students[i].inf_tearm[j].sub_mark[k];
                    k++;
                }
            }
            str += "\n";
        }
        //System.out.print(str);
        try{
            File write = new File("data.data");
            BufferedWriter w = new BufferedWriter(new FileWriter(write));
            w.write(str);
            w.close();
        }catch(FileNotFoundException e){
            System.out.print(e);
        }catch(IOException e){
            System.out.print(e);
        }

    }

    public void delete(int n){
        for(int i=n;i<num_student;i++)
            students[i] = students[i+1];
        num_student--;
    }

    public void add(student new_student){

        students[num_student] = new_student;
        num_student ++;

    }

    public static void main(String[] args) {
        //studentDA studentda = new studentDA();
    }

    private void jbInit() throws Exception {
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -