日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

用Java实现学生管理系统【简化版】基础

發(fā)布時間:2023/12/9 windows 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用Java实现学生管理系统【简化版】基础 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?🎉博客首頁:痛而不言笑而不語的淺傷

📢歡迎關(guān)注🥳點贊 👍 收藏 ?留言 📝 歡迎討論!

🔮本文由痛而不言笑而不語的淺傷原創(chuàng),CSDN首發(fā)!

🌋系列專欄:《Java每日一練》

🧿首發(fā)時間:2022年6月4日

?:熱愛Java學習,期待一起交流!

🙏🏻作者水平有限,如果發(fā)現(xiàn)錯誤,求告知,多謝!

🥰有問題可以私信交流!!!

目錄

運行展示

界面初始化

查看所有學生

?添加學生

刪除學生

修改學生

退出系統(tǒng)

?完整源代碼?


?

?* 標準的IO版學生管理系統(tǒng)
?*?
?* * 分析:
?* ?? ??? ?1.定義學生類
?* ?? ??? ?2.學生管理系統(tǒng)主界面的代碼編寫
?* ?? ??? ?3.學生管理系統(tǒng)的查看所有學生的代碼編寫
?* ?? ??? ?4.學生管理系統(tǒng)的添加學生的代碼編寫
?* ?? ??? ?5.學生管理系統(tǒng)的刪除學生的代碼編寫
?* ?? ??? ?6.學生管理系統(tǒng)的修改學生的代碼編寫

????????其實挺簡單的,就最基本的Java基礎(chǔ)語法部分。很適合初學者練習。其實主要從Java面向?qū)ο蠛虸O流的一個熟練掌握。最后是轉(zhuǎn)換成jar文件,通過軟件弄成了.exe的文件。執(zhí)行exe文件就是如下運行結(jié)果。數(shù)據(jù)的保存是在同目錄下的TXT文件,需要注意的是TXT文件和可執(zhí)行的exe文件一定要放在同一文件夾內(nèi),不然會報錯。

運行展示

界面初始化

public class StudentManagerTest_IO {public static void main(String[] args) throws Exception {File f1 = new File("?G:\\學生管理系統(tǒng)\\Student1.txt");// 創(chuàng)建持久相對路勁String findName = f1.getName();// 學生管理系統(tǒng)主界面的代碼編寫// 死循環(huán)執(zhí)行程序while (true) {System.out.println("----------歡迎使用老馬教育學生管理系統(tǒng)----------");System.out.println("請輸入你要執(zhí)行的操作:");System.out.println("1 查看所有學生");System.out.println("2 添加學生");System.out.println("3 刪除學生");System.out.println("4 修改學生");System.out.println("5 退出系統(tǒng)");

查看所有學生

// 學生管理系統(tǒng)的查看所有學生的代碼編寫public static void findAllStudent(String findName) throws Exception {// 創(chuàng)建集合對象存儲學生數(shù)據(jù)ArrayList<Student> array = new ArrayList<Student>();// 調(diào)用讀數(shù)據(jù)方法readData(findName, array);// 遍歷集合到輸出控制臺// 首先判斷集合中是否有數(shù)據(jù)if (array.size() == 0) {System.out.println("不好意思,目前沒有學生信息可供查詢,請重新你的選擇!");} else {System.out.println("所有學生信息如下:");System.out.println("|-------|-------|-------|-------|");System.out.println("|" + "學號" + "\t" + "|" + "姓名" + "\t" + "|" + "年齡" + "\t" + "|" + "地址" + "\t" + "|");System.out.println("|-------|-------|-------|-------|");for (int i = 0; i < array.size(); i++) {Student s = array.get(i);System.out.println("|" + s.getId() + "\t" + "|" + s.getName() + "\t" + "|" + s.getAges() + "\t" + "|"+ s.getAddress() + "\t" + "|");System.out.println("|-------|-------|-------|-------|");}System.out.println();System.out.println();}}

?

?添加學生

// 學生管理系統(tǒng)的添加學生的代碼編寫public static void addStudent(String findName) throws Exception {// 創(chuàng)建存儲數(shù)據(jù)的集合對象ArrayList<Student> array = new ArrayList<Student>();// 調(diào)用讀數(shù)據(jù)方法readData(findName, array);// 創(chuàng)建鍵盤錄入對象Scanner sc = new Scanner(System.in);String id;// 判斷該學號是否已被占用while (true) {// 定義標記boolean flag = false;// 添加學號System.out.println("請您輸入要添加的學生學號:");id = sc.nextLine();for (int i = 0; i < array.size(); i++) {Student s = array.get(i);if (s.getId().equals(id)) {flag = true;break;}}if (flag) {System.out.println("不好意思,你輸入的學號已被占用,請你重新你的選擇:");break;} else {// 添加姓名System.out.println("請您輸入學生姓名:");String name = sc.nextLine();System.out.println("請您輸入學生年齡:");String ages = sc.nextLine();System.out.println("請您輸入學生居住地址:");String address = sc.nextLine();// 創(chuàng)建學生對象Student s = new Student();s.setId(id);s.setName(name);s.setAges(ages);s.setAddress(address);// 把學生對象作為元素添加到集合中array.add(s);// 調(diào)用寫數(shù)據(jù)方法writerData(findName, array);// 添加成功的提示語System.out.println("添加學生信息成功!");break;}}}

?

刪除學生

// 學生管理系統(tǒng)的刪除學生的代碼編寫public static void deleteStudent(String findName) throws Exception {// 創(chuàng)建學生數(shù)據(jù)存儲的空集合ArrayList<Student> array = new ArrayList<Student>();// 調(diào)用讀數(shù)據(jù)方法readData(findName, array);// 創(chuàng)建鍵盤錄入對象Scanner sc = new Scanner(System.in);// 定義標記int index = -1;// 定義學號變量String id;// 刪除學生信息// 數(shù)據(jù)要刪除學生信息的學生學號System.out.println("請您輸入要刪除學生信息的學生學號:");id = sc.nextLine();for (int i = 0; i < array.size(); i++) {Student s = array.get(i);// 判斷是否有要刪除的這個學號if (s.getId().equalsIgnoreCase(id)) {index = i;break;}}if (index == -1) {System.out.println("您想要刪除的學生信息不存在,請重新您的選擇!");} else {array.remove(index);// 調(diào)用寫文件方法writerData(findName, array);// 提示語System.out.println("刪除學生信息成功!");}}

?

修改學生

// 學生管理系統(tǒng)的修改學生的代碼編寫public static void alterStudent(String findName) throws Exception {// 創(chuàng)建存儲學生數(shù)據(jù)的空集合ArrayList<Student> array = new ArrayList<Student>();// 調(diào)用讀數(shù)據(jù)方法readData(findName, array);// 創(chuàng)建鍵盤錄入對象Scanner sc = new Scanner(System.in);// 定義標記int index = -1;// 定義學生學號變量String id;// 輸入學號判斷while (true) {// 輸入學號System.out.println("請您輸入想要修改學生信息的學號:");id = sc.nextLine();for (int i = 0; i < array.size(); i++) {Student s = array.get(i);if (s.getId().equals(id)) {index = i;}}if (index == -1) {System.out.println("您想要修改的學生信息不存在,請您重新輸入學號:");} else {// 修改姓名System.out.println("請您輸入學生姓名:");String name = sc.nextLine();// 修改年齡System.out.println("請您輸入學生年齡:");String ages = sc.nextLine();// 修改居住地址System.out.println("請您輸入居住地址:");String address = sc.nextLine();// 創(chuàng)建學生對象Student s = new Student();s.setId(id);s.setName(name);s.setAges(ages);s.setAddress(address);// 添加到集合array.set(index, s);// 調(diào)用寫文件方法writerData(findName, array);// 提示語System.out.println("修改學生信息成功!");break;}}} }

退出系統(tǒng)

// 退出系統(tǒng)System.out.println("感謝您的使用,辛苦了!");System.exit(0);break;

?完整源代碼?

package com.laoma_02;import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner;/** 標準的IO版學生管理系統(tǒng)* * * 分析:* 1.定義學生類* 2.學生管理系統(tǒng)主界面的代碼編寫* 3.學生管理系統(tǒng)的查看所有學生的代碼編寫* 4.學生管理系統(tǒng)的添加學生的代碼編寫* 5.學生管理系統(tǒng)的刪除學生的代碼編寫* 6.學生管理系統(tǒng)的修改學生的代碼編寫** */ public class StudentManagerTest_IO {public static void main(String[] args) throws Exception {File f1 = new File("?G:\\學生管理系統(tǒng)\\Student1.txt");// 創(chuàng)建持久相對路勁String findName = f1.getName();// 學生管理系統(tǒng)主界面的代碼編寫// 死循環(huán)執(zhí)行程序while (true) {System.out.println("----------歡迎使用老馬教育學生管理系統(tǒng)----------");System.out.println("請輸入你要執(zhí)行的操作:");System.out.println("1 查看所有學生");System.out.println("2 添加學生");System.out.println("3 刪除學生");System.out.println("4 修改學生");System.out.println("5 退出系統(tǒng)");// 創(chuàng)建鍵盤錄入對象Scanner sc = new Scanner(System.in);// 輸入所匹配的序號并執(zhí)行操作String option = sc.nextLine();switch (option) {case "1":// 查看所有學生信息findAllStudent(findName);break;case "2":// 添加學生信息addStudent(findName);break;case "3":// 刪除學生信息deleteStudent(findName);break;case "4":// 修改學生信息alterStudent(findName);break;case "5":// 退出系統(tǒng)System.out.println("感謝您的使用,辛苦了!");System.exit(0);break;default:System.out.println("您輸入的選擇不存在,請您重新輸入!");break;}}}// 把文件中的數(shù)據(jù)讀到集合中public static void readData(String findName, ArrayList<Student> array) throws Exception {// 創(chuàng)建輸入緩沖流對象BufferedReader br = new BufferedReader(new FileReader(findName));// 創(chuàng)建數(shù)組讀取文本文件數(shù)據(jù)并按照執(zhí)行格式分割,然后把讀取的數(shù)據(jù)作為元素存儲到集合,最后遍歷集合到輸出控制臺// 定義索引String line;while ((line = br.readLine()) != null) {// 讀取文本文件數(shù)據(jù)并按照執(zhí)行格式分割String[] strArray = line.split(",");// 創(chuàng)建學生對象Student s = new Student();s.setId(strArray[0]);s.setName(strArray[1]);s.setAges(strArray[2]);s.setAddress(strArray[3]);// 把讀取的數(shù)據(jù)作為元素存儲到集合array.add(s);}// 釋放資源你br.close();}// 把集合中的數(shù)據(jù)寫入文件中public static void writerData(String findName, ArrayList<Student> array) throws Exception {// 創(chuàng)建輸出緩沖流對象BufferedWriter bw = new BufferedWriter(new FileWriter(findName));for (int i = 0; i < array.size(); i++) {Student s = array.get(i);StringBuilder sb = new StringBuilder();sb.append(s.getId()).append(",").append(s.getName()).append(",").append(s.getAges()).append(",").append(s.getAddress());bw.write(sb.toString());bw.newLine();bw.flush();}// 釋放資源bw.close();}// 學生管理系統(tǒng)的查看所有學生的代碼編寫public static void findAllStudent(String findName) throws Exception {// 創(chuàng)建集合對象存儲學生數(shù)據(jù)ArrayList<Student> array = new ArrayList<Student>();// 調(diào)用讀數(shù)據(jù)方法readData(findName, array);// 遍歷集合到輸出控制臺// 首先判斷集合中是否有數(shù)據(jù)if (array.size() == 0) {System.out.println("不好意思,目前沒有學生信息可供查詢,請重新你的選擇!");} else {System.out.println("所有學生信息如下:");System.out.println("|-------|-------|-------|-------|");System.out.println("|" + "學號" + "\t" + "|" + "姓名" + "\t" + "|" + "年齡" + "\t" + "|" + "地址" + "\t" + "|");System.out.println("|-------|-------|-------|-------|");for (int i = 0; i < array.size(); i++) {Student s = array.get(i);System.out.println("|" + s.getId() + "\t" + "|" + s.getName() + "\t" + "|" + s.getAges() + "\t" + "|"+ s.getAddress() + "\t" + "|");System.out.println("|-------|-------|-------|-------|");}System.out.println();System.out.println();}}// 學生管理系統(tǒng)的添加學生的代碼編寫public static void addStudent(String findName) throws Exception {// 創(chuàng)建存儲數(shù)據(jù)的集合對象ArrayList<Student> array = new ArrayList<Student>();// 調(diào)用讀數(shù)據(jù)方法readData(findName, array);// 創(chuàng)建鍵盤錄入對象Scanner sc = new Scanner(System.in);String id;// 判斷該學號是否已被占用while (true) {// 定義標記boolean flag = false;// 添加學號System.out.println("請您輸入要添加的學生學號:");id = sc.nextLine();for (int i = 0; i < array.size(); i++) {Student s = array.get(i);if (s.getId().equals(id)) {flag = true;break;}}if (flag) {System.out.println("不好意思,你輸入的學號已被占用,請你重新你的選擇:");break;} else {// 添加姓名System.out.println("請您輸入學生姓名:");String name = sc.nextLine();System.out.println("請您輸入學生年齡:");String ages = sc.nextLine();System.out.println("請您輸入學生居住地址:");String address = sc.nextLine();// 創(chuàng)建學生對象Student s = new Student();s.setId(id);s.setName(name);s.setAges(ages);s.setAddress(address);// 把學生對象作為元素添加到集合中array.add(s);// 調(diào)用寫數(shù)據(jù)方法writerData(findName, array);// 添加成功的提示語System.out.println("添加學生信息成功!");break;}}}// 學生管理系統(tǒng)的刪除學生的代碼編寫public static void deleteStudent(String findName) throws Exception {// 創(chuàng)建學生數(shù)據(jù)存儲的空集合ArrayList<Student> array = new ArrayList<Student>();// 調(diào)用讀數(shù)據(jù)方法readData(findName, array);// 創(chuàng)建鍵盤錄入對象Scanner sc = new Scanner(System.in);// 定義標記int index = -1;// 定義學號變量String id;// 刪除學生信息// 數(shù)據(jù)要刪除學生信息的學生學號System.out.println("請您輸入要刪除學生信息的學生學號:");id = sc.nextLine();for (int i = 0; i < array.size(); i++) {Student s = array.get(i);// 判斷是否有要刪除的這個學號if (s.getId().equalsIgnoreCase(id)) {index = i;break;}}if (index == -1) {System.out.println("您想要刪除的學生信息不存在,請重新您的選擇!");} else {array.remove(index);// 調(diào)用寫文件方法writerData(findName, array);// 提示語System.out.println("刪除學生信息成功!");}}// 學生管理系統(tǒng)的修改學生的代碼編寫public static void alterStudent(String findName) throws Exception {// 創(chuàng)建存儲學生數(shù)據(jù)的空集合ArrayList<Student> array = new ArrayList<Student>();// 調(diào)用讀數(shù)據(jù)方法readData(findName, array);// 創(chuàng)建鍵盤錄入對象Scanner sc = new Scanner(System.in);// 定義標記int index = -1;// 定義學生學號變量String id;// 輸入學號判斷while (true) {// 輸入學號System.out.println("請您輸入想要修改學生信息的學號:");id = sc.nextLine();for (int i = 0; i < array.size(); i++) {Student s = array.get(i);if (s.getId().equals(id)) {index = i;}}if (index == -1) {System.out.println("您想要修改的學生信息不存在,請您重新輸入學號:");} else {// 修改姓名System.out.println("請您輸入學生姓名:");String name = sc.nextLine();// 修改年齡System.out.println("請您輸入學生年齡:");String ages = sc.nextLine();// 修改居住地址System.out.println("請您輸入居住地址:");String address = sc.nextLine();// 創(chuàng)建學生對象Student s = new Student();s.setId(id);s.setName(name);s.setAges(ages);s.setAddress(address);// 添加到集合array.set(index, s);// 調(diào)用寫文件方法writerData(findName, array);// 提示語System.out.println("修改學生信息成功!");break;}}} }

最后呢?文章到這里就結(jié)束啦,你們學廢了嗎?

?

好啦!今天的練習就到這里。看吧這么努力的你又學到了很多,新的一天加油鴨!!!


你的點贊是對我最大的鼓勵。

你的收藏是對我文章的認可。

你的關(guān)注是對我創(chuàng)作的動力。

?

?

總結(jié)

以上是生活随笔為你收集整理的用Java实现学生管理系统【简化版】基础的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。