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

📄 readingroom.java

📁 图书馆座位管理系统
💻 JAVA
字号:
package fileUtility;

import java.io.RandomAccessFile;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import librarysearchingsystem.ProportionPanel;


public class ReadingRoom {
    public String name;
    public int studentsSerial[];
    public int map[][];
    public int studentNumber;
    public int seatNumber = 0;

    public static final int seatNum = -1, windowNum = -2, doorNum = -3,
            passageNum = -4, bookNum = -5, deskNum = -6, wallNum = -7,
            blankNum = -8;


    public ProportionPanel proportionPanel;

    public ReadingRoom(String fileName) throws FileNotFoundException,
            IOException {

//        RandomAccessFile ffff = new RandomAccessFile(fileName, "r");
        BufferedReader f = new BufferedReader(new FileReader(fileName));
        name = f.readLine(); //名字
        //参数
        int lineNumber, lineLength; // seatNumber;
        String temp;
        temp = f.readLine();
        int tInt[] = LineToInt(2, temp);
        lineNumber = tInt[0];
        lineLength = tInt[1];
//        seatNumber = tInt[2];
        map = new int[lineNumber][lineLength];

        for (int i = 0; i < map.length; i++) {
            temp = f.readLine();
            for (int j = 0; j < temp.length(); j++) {
                map[i][j] = reflection(temp.charAt(j));
                if (map[i][j] == -1) {
                    seatNumber++;
                }
            }
        }
        studentsSerial = new int[seatNumber];
//        while (f.getFilePointer() < f.length()) {
//            temp = f.readLine();
//
//        }
        f.close();
    }

    public static int reflection(char ch) { //变为负值
        switch (ch) {
//        case '0':
//            return 0;
//        case '1':
//            return -1;
//        case '2':
//            return -2;
//        case '3':
//            return -3;
//        case '4':
//            return -4;
//        case '5':
//            return -5;
//        case '6':
//            return -6;
//        case '7':
//            return -7;
//        case '8':
//            return -8;
//        case '9':
//            return -9;
        default:
            return '0' - ch;

        }
//        return 0;

    }


    static int[] LineToInt(int c, String s) {
        int num[] = new int[c];
        char ch;
        String temp = "";
        int index = 0;
        for (int i = 0; i < s.length(); i++) {
            ch = s.charAt(i);
            if (ch != ' ' && ch != '/') {
                temp += ch;
            } else if (!temp.equals("")) {
                num[index++] = Integer.parseInt(temp);
                if(index==c)return num;
                temp = "";
            }
        }
        if (temp != "") {
            num[index] = Integer.parseInt(temp);
        }

        return num;

    }

    public static void main(String[] args) throws FileNotFoundException,
            IOException {
//        ReadingRoom r = new ReadingRoom(filePath.file + "reaingRoom1.txt");
//        r.print();
//        System.out.println("666660000000000000066666".length());


        ReadingRoom rr[] = listReadingRooms(filePath.readingRoomPath);
        for (int i = 0; i < rr.length; i++) {
            rr[i].print();
        }
    }

    public void print() {
        System.out.println(name + "");
        for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < map[0].length; j++) {
                if(map[i][j]>0)System.out.println("");
                System.out.print(map[i][j]);
            }
            System.out.println("");
        }
        System.out.println("seatNumber=" + seatNumber);
        System.out.println("");
    }

    public static ReadingRoom[] listReadingRooms(String directory) {
        File f = new File(directory);
        File roomFile[] = FileOption.listFiles(".read", f);
        if (roomFile == null) {
            return null;
        } else {
            ReadingRoom rooms[] = new ReadingRoom[roomFile.length];
            for (int i = 0; i < rooms.length; i++) {
                try {
                    rooms[i] = new ReadingRoom(roomFile[i].toString());
                } catch (FileNotFoundException ex) {
                    System.out.println("can't find readingrooms");
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
            return rooms;
        }
    }


}

⌨️ 快捷键说明

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