學生管理系統(I O版)

2021-10-16 12:48:25 字數 3774 閱讀 3822

1.新增學生功能:

鍵盤錄入學生資訊(姓名,語文成績,數學成績,英語成績),儲存到student.txt檔案中,格式

001,張三,85,

90,100002

,李四,99,

85,70.

..2.刪除學生功能:

根據錄入的學號從student.txt檔案中刪除一行

3.修改學生功能:

根據錄入要刪除的學生學號找到學生,再錄入新的學生姓名以及成績,

並修改student.txt檔案中的學生資訊

4.查詢學生功能: 查詢所有的學生資訊,並列印輸出

public

class

student

1.先編寫讀取檔案到集合,以及寫入集合到檔案的方法

2.然後學生管理系統的增、刪、改、查功能。直接對集合進行操作就可以了

新增學生:

1)讀取檔案到集合

2)往集合中新增學生資訊

3)再把集合寫到檔案中,覆蓋原來的檔案

查詢學生:

1)讀取檔案到集合

2)列印集合中的元素

修改學生:

1)讀取檔案到集合

2)鍵盤錄入學號,判斷學號在集合中有沒有

3)重新錄入學生資訊,修改集合中的學生資訊

4)把集合再寫入到檔案中,覆蓋原來的檔案

刪除學生:

1)讀取檔案到集合

2)錄入要刪除的學生學號,判斷學號在集合中有沒有

3)從集合中刪除學生

4)把集合再寫入到檔案中,覆蓋原來的檔案

[外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳(img-dqfcdzyb-1610973946093)(assets/image-20210118110024757.png)]

public

static

void

main

(string[

] args)

}}

public

static arraylist

readfiletolist()

throws ioexception

br.close()

;return list;

}

//把集合中的資料寫回檔案中

public

static

void

writelisttofile

(arraylist

list)

throws ioexception

bw.close()

;}

//獲取指定id在集合中的索引位置

public

static

intgetindex

(arraylist

list, string id)

}return index;

}

//新增學生

private

static

void

addstudent()

throws ioexception

else

} system.out.

println

("輸入學生的姓名:");

string name = sc.

next()

; system.out.

println

("輸入學生的語文成績:");

int chinese = sc.

nextint()

; system.out.

println

("輸入學生的數學成績:");

int math = sc.

nextint()

; system.out.

println

("輸入學生的英語成績:");

int english = sc.

nextint()

;//把學生資訊封裝為student物件

student stu =

newstudent

(id, name, chinese, math, english)

; list.

add(stu)

; system.out.

println

("新增成功");

//3)再把集合寫到檔案中,覆蓋原來的檔案

writelisttofile

(list)

;}

//查詢學生

public

static

void

findallstudent()

throws ioexception

//遍歷集合,列印學生資訊

for(

int i =

0; i < list.

size()

; i++

)}

//修改學生資訊

public

static

void

updatestudent()

throws ioexception

else

}//4.錄入新的學生資訊

system.out.

println

("錄入新的學生學號:");

string id = sc.

next()

; system.out.

println

("錄入新的學生姓名:");

string name = sc.

next()

; system.out.

println

("錄入新的學生語文成績:");

int chinese = sc.

nextint()

; system.out.

println

("錄入新的學生數學成績:");

int math = sc.

nextint()

; system.out.

println

("錄入新的學生英語成績:");

int english = sc.

nextint()

;//把新的學生資訊封裝為student物件

student stu=

newstudent

(id,name,chinese,math,english)

; list.

set(index,stu)

; system.out.

println

("修改學生成功");

//把集合中的資料寫回檔案中

writelisttofile

(list)

;}

public

static

void

deletestudent()

throws ioexception

else

}//從集合中刪除學生

list.

remove

(index)

;//把集合重新寫入檔案,並覆蓋

writelisttofile

(list)

;}

學生管理系統集合版 學生管理系統IO版(2)

從檔案中讀資料到集合中 public static void readdata string filename,arraylistarraylist throws ioexception bufferedreader.close 關閉資源 從集合中的資料寫入檔案public static void ...

學生管理系統 函式版

import time import os 定乙個列表,用來儲存所有的學生資訊 每個學生是乙個字典 info list def print menu print print 學生管理系統 v1.0 print 1 新增學生 print 2 刪除學生 print 3 修改學生 print 4 查詢學生...

go 學生管理系統(函式版)

最近在學習 go,通過go 編寫了乙個簡單的學生資訊管理系統,附上 如下 package main import fmt os math 函式版學生管理系統 1.檢視,新曾,刪除 建立存放所有學生元素的 map var allstud map int64 student type student s...