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

歡迎訪問 生活随笔!

生活随笔

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

windows

学生管理系统(Java实现)

發布時間:2023/12/9 windows 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 学生管理系统(Java实现) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、學生信息管理程序 基本要求:
1.要求實現學生信息的使用添加、查找、刪除、修改等幾個功能,每個功能模塊均能實現從模塊中退出,從而完成一個學生管理系統所需功能。

2.要使用結構體來實現對學生信息的存儲。

3.學生信息需至少包括:學號,姓名,年齡。

4.使用文件完成數據的存儲與讀取,要求每次運行某個功能模塊時將數據讀入結構體中,并給用戶提供保存選項,可以將結構體中的數據保存在文件中。

1.1項目演示

1.2學生管理系統實現思路

  • 定義學生類
  • 主界面的代碼編寫
  • 添加學生的代碼編寫
  • 查看學生的代碼編寫
  • 刪除學生的代碼編寫
  • 修改學生的代碼編寫

1.3定義學生類

學生類: Student

成員變量:? ? ? ? ? ? ? 學號:sid

????????????????????????????????姓名:name

????????????????????????????????年齡:age

????????????????????????????????成績: ?score

構造方法:無參構造、帶四個參數的構造

成員方法:每個成員變量給出相應的get/set方法

package StudentManage; public class Student {private String sid;private String name;private String age;private String score;public Student(){}public Student(String sid, String name, String age, String score) {this.sid = sid;this.name = name;this.age = age;this.score = score;}public String getSid() {return sid;}public void setSid(String sid) {this.sid = sid;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}public String getScore() {return score;}public void setScore(String score) {this.score = score;} }

1.4主界面的代碼編寫

思路:

  • 用輸出語句完成主界面的編寫
  • 用Scanner實現鍵盤錄入數據
  • 用switch語句完成操作的選擇
  • 用循環完成再次回到主界面
  • package StudentManage;import java.util.Scanner;public class StudentManager {public static void main(String[] args) {while(true) {System.out.println("--------歡迎來到學生管理系統--------");System.out.println("1.添加學生");System.out.println("2.刪除學生");System.out.println("3.修改學生");System.out.println("4.查看作業學生");System.out.println("5.退出");System.out.println("請輸入你的選擇");Scanner sc = new Scanner(System.in);String line = sc.nextLine();switch (line) {case "1":System.out.println("1.添加學生");break;case "2":System.out.println("2.刪除學生");break;case "3":System.out.println("3.修改學生");break;case "4":System.out.println("4.查看作業學生");break;case "5":System.out.println("謝謝使用");System.exit(0);}}} }

    1.5添加學生的代碼編寫

  • 用鍵盤錄入選擇添加學生
  • 定義一個方法,用于添加學生?
  • 調用方法
    • 2.1顯示提示信息,提示要輸入何種信息
    • 2.2鍵盤錄入學生對象所需要的數據
    • 2.3創建學生對象,把鍵盤錄入的信息賦值給學生對象的成員變量
    • 2.4將學生對象添加到集合中(保存)
    • 2.5給出添加成功提示
    public static void addStudent(ArrayList<Student>array){Scanner sc=new Scanner(System.in);System.out.println("請輸入學生學號");String sid=sc.nextLine();System.out.println("請輸入學生姓名");String name=sc.nextLine();System.out.println("請輸入學生年齡");String age=sc.nextLine();System.out.println("請輸入學生成績");String score=sc.nextLine();Student s = new Student();s.setSid(sid);s.setName(name);s.setAge(age);s.setScore(score);array.add(s);System.out.println("添加學生成功");}

    1.6查看所有學生的代碼編寫

    思路

  • 用鍵盤錄入選擇查看的學生信息
  • 定義一個方法,用于查看學生信息? (1.顯示表頭信息 。2.將集合中數據按照對應的格式顯示學生信息,年齡顯示補充“歲”)
  • 調用函數
  • public static void findStudent(ArrayList<Student> array){if(array.size()==0){System.out.println("無信息,清線添加再查詢");return ;}System.out.println("學號\t\t姓名\t\t年齡\t\t成績");for(int i=0;i<array.size();i++){Student s =array.get(i);System.out.println(s.getSid()+"\t"+s.getName()+"\t\t"+s.getAge()+"歲\t"+s.getScore());}}

    1.7刪除學生的代碼編寫

    思路

  • 用鍵盤錄入選擇刪除的學生信息
  • 定義一個方法,用于刪除學生信息(1.顯示提示信息。2.鍵盤錄入要刪除學生的學號。3.遍歷集合將對應的學生對象從集合中刪除。4.給出刪除成功的提示)
  • 調用方法
  • public static void deleteStudent(ArrayList<Student> array){Scanner sc =new Scanner(System.in);System.out.println("請輸入你要刪除的學生的學號");String sid=sc.nextLine();int index=-1;for(int i=0;i<array.size();i++){Student s=array.get(i);if(s.getSid().equals(sid)){index=i;break;}}if(index==-1){System.out.println("信息不存在");} else{array.remove(index);System.out.println("刪除成功");}}

    1.8修改學生的代碼編寫

  • 用鍵盤錄入選擇修改的學生信息
  • 定義一個方法,用于修改學生信息(1.顯示提示信息。2.鍵盤錄入要修改學生的學號。3.鍵盤錄入要修改學生的信息。4.遍歷集合修改對應的學生信息5.給出修改成功的提示)
  • 調用方法
  • public static void updataStudent(ArrayList<Student> array){Scanner sc =new Scanner(System.in);System.out.println("請輸入要修改學生的學號");String sid=sc.nextLine();System.out.println("請輸入學生的新姓名");String name =sc.nextLine();System.out.println("請輸入學生的新年齡");String age =sc.nextLine();System.out.println("請輸入學生的新成績");String score=sc.nextLine();Student s =new Student();s.setSid(sid);s.setName(name);s.setAge(age);s.setScore(score);for(int i=0;i<array.size();i++){Student student=array.get(i);if(student.getSid().equals(sid)){array.set(i,s);break;}}System.out.println("修改學生信息成功");}

    最終的主函數如下:

    package StudentManage;import java.util.ArrayList; import java.util.Scanner;public class StudentManager {public static void main(String[] args) {ArrayList<Student> array=new ArrayList<Student>();while(true) {System.out.println("--------歡迎來到學生管理系統--------");System.out.println("1.添加學生");System.out.println("2.刪除學生");System.out.println("3.修改學生");System.out.println("4.查看作業學生");System.out.println("5.退出");System.out.println("請輸入你的選擇");Scanner sc = new Scanner(System.in);String line = sc.nextLine();switch (line) {case "1":addStudent(array);break;case "2":deleteStudent(array);break;case "3":updataStudent(array);break;case "4":findStudent(array);break;case "5":System.out.println("謝謝使用");System.exit(0);}}}public static void addStudent(ArrayList<Student>array){Scanner sc=new Scanner(System.in);System.out.println("請輸入學生學號");String sid=sc.nextLine();System.out.println("請輸入學生姓名");String name=sc.nextLine();System.out.println("請輸入學生年齡");String age=sc.nextLine();System.out.println("請輸入學生成績");String score=sc.nextLine();Student s = new Student();s.setSid(sid);s.setName(name);s.setAge(age);s.setScore(score);array.add(s);System.out.println("添加學生成功");}public static void findStudent(ArrayList<Student> array){if(array.size()==0){System.out.println("無信息,清線添加再查詢");return ;}System.out.println("學號\t\t姓名\t\t年齡\t\t成績");for(int i=0;i<array.size();i++){Student s =array.get(i);System.out.println(s.getSid()+"\t"+s.getName()+"\t\t"+s.getAge()+"歲\t"+s.getScore());}}public static void deleteStudent(ArrayList<Student> array){Scanner sc =new Scanner(System.in);System.out.println("請輸入你要刪除的學生的學號");String sid=sc.nextLine();int index=-1;for(int i=0;i<array.size();i++){Student s=array.get(i);if(s.getSid().equals(sid)){index=i;break;}}if(index==-1){System.out.println("信息不存在");} else{array.remove(index);System.out.println("刪除成功");}}public static void updataStudent(ArrayList<Student> array){Scanner sc =new Scanner(System.in);System.out.println("請輸入要修改學生的學號");String sid=sc.nextLine();System.out.println("請輸入學生的新姓名");String name =sc.nextLine();System.out.println("請輸入學生的新年齡");String age =sc.nextLine();System.out.println("請輸入學生的新成績");String score=sc.nextLine();Student s =new Student();s.setSid(sid);s.setName(name);s.setAge(age);s.setScore(score);for(int i=0;i<array.size();i++){Student student=array.get(i);if(student.getSid().equals(sid)){array.set(i,s);break;}}System.out.println("修改學生信息成功");}}

    注:記得建立學生類

    學生類如下

    package StudentManage; public class Student {private String sid;private String name;private String age;private String score;public Student(){}public Student(String sid, String name, String age, String score) {this.sid = sid;this.name = name;this.age = age;this.score = score;}public String getSid() {return sid;}public void setSid(String sid) {this.sid = sid;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}public String getScore() {return score;}public void setScore(String score) {this.score = score;} }

    注:需將以上兩個代碼放在同一個包下才可運行

    ?

    總結

    以上是生活随笔為你收集整理的学生管理系统(Java实现)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。