添磚Java之路(其六)——通過集合制作的學生信息管理系統

目錄

前言:

源碼:


前言:

我對于集合的理解,感覺就類似于順序表這樣的數據結構,然后他存儲的數據不能是基本類型,如果要用也只能用對應基本數據的包裝類。

對于集合有很多方法,我的建議就是去api里面文檔查看就行,沒必要可以去背。

源碼:

哈哈哈,這個系統太經典了,拿來練習語法再合適不過了~

實體類:

public class StudentInfor {private String id;private String name;private int age;private String sex;private int MathScore;private int ChineseSocre;private  int EnglishScore;private   int arrSocre;public String getId() {return id;}public void setId(String id) {this.id = id;}public StudentInfor() {}public StudentInfor(String id, String name, int age, String sex, int mathScore, int chineseSocre, int englishScore) {this.id = id;this.name = name;this.age = age;this.sex = sex;MathScore = mathScore;ChineseSocre = chineseSocre;EnglishScore = englishScore;arrSocre=mathScore+chineseSocre+englishScore;}public int getArrSocre() {return arrSocre;}public void setArrSocre() {arrSocre=MathScore+EnglishScore+ChineseSocre;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public int getMathScore() {return MathScore;}public void setMathScore(int mathScore) {MathScore = mathScore;}public int getChineseSocre() {return ChineseSocre;}public void setChineseSocre(int chineseSocre) {ChineseSocre = chineseSocre;}public int getEnglishScore() {return EnglishScore;}public void setEnglishScore(int englishScore) {EnglishScore = englishScore;}
}

方法類:
?


import java.util.ArrayList;
import java.util.Scanner;public class System_Z {private static void SetInfor(ArrayList<StudentInfor> list){StudentInfor student  = new StudentInfor();Scanner sc=new Scanner(System.in);System.out.println("請輸入姓名->");student.setName(sc.next());System.out.println("請輸入學號->");String id=sc.next();for (int i = 0; i < list.size(); i++) {while (id.equals(list.get(i).getId())) {System.out.println("已存在該學號!");System.out.println("請重新輸入");id = sc.next();}}student.setId(id);System.out.println("請輸入年齡->");student.setAge(sc.nextInt());System.out.println("請輸入性別->");student.setSex(sc.next());System.out.println("請輸入語文成績");student.setChineseSocre(sc.nextInt());System.out.println("請輸入數學成績");student.setMathScore(sc.nextInt());System.out.println("請輸入英語成績");student.setEnglishScore(sc.nextInt());student.setArrSocre();list.add(student);}private  static  void PrintAllStudent(ArrayList<StudentInfor>list){System.out.println("姓名   id           年齡   性別   語文   數學   英語   總分");for (int i = 0; i < list.size(); i++) {
/*            System.out.println(list.get(i).getName()+"   "+list.get(i).getId()+"   "+list.get(i).getAge()+"   "+list.get(i).getSex()+"    "+list.get(i).getChineseSocre()+"\t"+list.get(i).getMathScore()+"   "+list.get(i).getEnglishScore()+"  "+list.get(i).getArrSocre());*/System.out.printf("%-5s%-13s%-6d%-6s%-6d%-6d%-6d%-6d\n",list.get(i).getName(),list.get(i).getId(),list.get(i).getAge(),list.get(i).getSex(),list.get(i).getChineseSocre(),list.get(i).getMathScore(),list.get(i).getEnglishScore(),list.get(i).getArrSocre());}}private  static void  Print(){System.out.println("1.錄入學生信息");System.out.println("2.輸入id查看學生信息");System.out.println("3.輸入學生姓名查看學生信息");System.out.println("4.輸入學號修改學生信息");System.out.println("5.打印全部學生信息");System.out.println("6.輸入學號刪除學生信息");System.out.println("0.退出");}private static void  FindByName(ArrayList<StudentInfor> list ){System.out.println("請輸入要查的學生姓名");Scanner sc=new Scanner(System.in);String name=sc.next();int n=0;for (int i = 0; i < list.size(); i++) {if(name.equals(list.get(i).getName())){n=1;System.out.println("學生姓名:"+list.get(i).getName());System.out.println("學生id:"+list.get(i).getId());System.out.println("學生年齡:"+list.get(i).getAge());System.out.println("學生性別:"+list.get(i).getSex());System.out.println("語文成績:"+list.get(i).getChineseSocre());System.out.println("數學成績:"+list.get(i).getMathScore());System.out.println("英語成績:"+list.get(i).getEnglishScore());System.out.println("總成績:"+list.get(i).getArrSocre());System.out.println();}}if(n==0){System.out.println("沒找到喵");System.out.println();}}private static void  FindByID(ArrayList<StudentInfor> list ){System.out.println("請輸入要查的學號");Scanner sc=new Scanner(System.in);String id=sc.next();for (int i = 0; i < list.size(); i++) {if(id.equals(list.get(i).getId())){System.out.println("學生姓名:"+list.get(i).getName());System.out.println("學生id:"+list.get(i).getId());System.out.println("學生年齡:"+list.get(i).getAge());System.out.println("學生性別:"+list.get(i).getSex());System.out.println("語文成績:"+list.get(i).getChineseSocre());System.out.println("數學成績:"+list.get(i).getMathScore());System.out.println("英語成績:"+list.get(i).getEnglishScore());System.out.println("總成績:"+list.get(i).getArrSocre());System.out.println();return ;}}System.out.println("沒找到喵");System.out.println();}private static  void RemakeByname(ArrayList<StudentInfor>list ){System.out.println("請輸入要修改學生的學號");Scanner sc=new Scanner(System.in);String id=sc.next();for (int i = 0; i < list.size(); i++) {if(id.equals(list.get(i).getId())){System.out.println("請輸入姓名->");list.get(i).setName(sc.next());System.out.println("請輸入學號->");list.get(i).setName(sc.next());System.out.println("請輸入年齡->");list.get(i).setAge(sc.nextInt());System.out.println("請輸入性別->");list.get(i).setSex(sc.next());System.out.println("請輸入語文成績");list.get(i).setChineseSocre(sc.nextInt());System.out.println("請輸入數學成績");list.get(i).setMathScore(sc.nextInt());System.out.println("請輸入英語成績");list.get(i).setEnglishScore(sc.nextInt());list.get(i).setArrSocre();return ;}}}private  static void DeleteByid(ArrayList<StudentInfor>list){System.out.println("請輸入要查的學號");Scanner sc=new Scanner(System.in);String id=sc.next();for (int i = 0; i < list.size(); i++) {if(id.equals(list.get(i).getId())){list.remove(i);System.out.println("刪除成功!");return ;}}System.out.println("沒有查找到該學生信息喵~");}private static void main(String[] args) {ArrayList<StudentInfor> list=new ArrayList<>();StudentInfor s1=new StudentInfor("2023211661","牢大",24,"男",59,89,100);StudentInfor s2=new StudentInfor("2023211662","蔡徐坤",25,"男",88,81,66);list.add(s1);list.add(s2);System.out.println("-------歡迎使用學生信息管理系統------");Scanner sc=new Scanner(System.in);int choice=100;while(choice!=0){Print();choice = sc.nextInt();switch(choice){case 1:SetInfor(list);break;case 2:FindByID(list);break;case 3:FindByName(list);break;case 4:RemakeByname(list);break;case 5:PrintAllStudent(list);System.out.println();break;case 6:DeleteByid(list);break;case 0:System.out.println("歡迎下次使用喵~");break;default:System.out.println("選擇錯誤請重新選擇");System.out.println();break;}}}}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/12385.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/12385.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/12385.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【運維】nvidia-smi錯誤信息:Failed to initialize NVML: Driver/library version mismatch

【運維】錯誤信息&#xff1a;Failed to initialize NVML: Driver/library version mismatch 是因為Nvidia的驅動沖突的原因 本地部署&#xff1a;本地Docker容器部署&#xff0c;本地驗證后打包鏡像 遠程部署&#xff1a;鏡像部署阿里云PAI EAS 因為在容器中安裝了驅動版本&a…

短視頻最后的慢動作怎么做:成都鼎茂宏升文化傳媒公司

短視頻最后的慢動作怎么做&#xff1a;技巧與創意實踐指南 在短視頻創作的浩瀚宇宙中&#xff0c;慢動作特效如同一顆璀璨的星辰&#xff0c;為作品增添無限魅力與情感深度。它不僅能夠放大細節之美&#xff0c;還能延長關鍵瞬間&#xff0c;引發觀眾強烈的情感共鳴。短視頻最…

SpringBoot項目的項目部署全過程

一、前端 安裝nginx 1.將提前準備好的nginx的安裝包上傳到Linux中/opt目錄下(我用的是Xftp) 2.解壓 2.1:在xshell中解壓該文件: tar -zxvf nginx-1.20.1.tar.gz 2.2:進入解壓后的目錄 cd nginx-1.20.1/ 2.3:安裝需要的依賴 yum -y install zlib zlib-devel openssl openssl-de…

html特殊字符的html,js,css寫法匯總

? 箭頭類 符號UNICODE符號UNICODEHTMLJSCSSHTMLJSCSS?&#8672\u21E0\21E0?&#8674\u21E2\21E2?&#8673\u21E1\21E1?&#8675\u21E3\21E3?&#8606\u219E\219E?&#8608\u21A0\21A0?&#8607\u219F\219F?&#8609\u21A1\21A1←&#8592\u2190\2…

FreeRTOS【4】線程掛起和恢復

1.開發背景 基于上一篇指引&#xff0c;成功創建并啟動線程后&#xff0c;線程已經開始運行了&#xff0c;但是有時我們需要線程暫停運行&#xff0c;例如某個線程是控制 LED 閃燈的&#xff0c;如果現在需要讓 LED 停止工作&#xff0c;單純的關閉 LED 是沒用的&#xff0c;因…

Python中json數據的常用操作函數:dump load dumps和loads

文章目錄 dump函數load函數dumps函數loads函數 dump函數 功能&#xff1a;將Python對象序列化為JSON格式的字符串&#xff0c;并寫入到文件中。這個方法用于將數據保存到文件中。語法&#xff1a;json.dump(需要進行json序列化的Python對象, 寫入的文件路徑) load函數 功能&…

文科生在三本院校,讀計算機專業

6歲&#xff0c;進入村小&#xff0c;一年級&#xff0c;老師問我的夢想是什么&#xff0c;我說我長大了我要成為科學家。 9歲&#xff0c;三年級&#xff0c;知道科學家不現實&#xff0c;開始學習英語。又因為科學家英語不好發音&#xff0c;于是我的夢想變了&#xff0c;長…

ZCC5503 18V 1A 6uA低靜態功耗 同步降壓控制器

1. 概要 ZCC5503R 是一款基準電壓源、振蕩電路、 比較器 PWM/PFM 控制器構成的 CMOS 降壓電路調整器&#xff0c;利用 PWM/PFM 自動切換控制電路達到可調占空比&#xff0c;具有全輸入電壓范圍&#xff08;3~18V &#xff09;內的低紋波、高效率及大電流輸出等特點. 2. 產品特性…

【智能優化算法】雁群優化算法(Wild Geese Algorithm,WGA)

雁群優化算法(Wild Geese Algorithm,WGA)是期刊“Array”的2021年智能優化算法 01.引言 雁群優化算法(Wild Geese Algorithm,WGA)用于大規模全局優化&#xff0c;并利用IEEE CEC 2008和CEC 2010高維D100、500、1000特別會議的大規模測試函數驗證了該算法的效率和性能。WGA的靈…

OceanBase v4.3特性解析:新功能“租戶克隆”的場景與應用指南

熟悉或曾用過OceanBase的朋友&#xff0c;對于“多租戶”這一理念定不陌生。OceanBase的租戶概念&#xff0c;與我們熟知的傳統數據庫實例頗為相似。舉例來說&#xff0c;OceanBase的租戶支持MySQL兼容模式&#xff0c;對于用戶而言&#xff0c;選用一個MySQL兼容模式的租戶&am…

IT行業的現狀與未來發展趨勢:探索無限可能

隨著技術的不斷進步&#xff0c;IT行業已成為推動全球經濟和社會發展的關鍵力量。從云計算、大數據、人工智能到物聯網、5G通信和區塊鏈&#xff0c;這些技術正在重塑我們的生活和工作方式。在本篇博客中&#xff0c;我們將探討IT行業的現狀以及未來發展趨勢&#xff0c;展望這…

DOM操作---刪除元素,刪除指定的元素,循環刪除元素

刪除DOM元素 remove()方法可以刪除自身節點&#xff0c;要注意一個元素被刪除時&#xff0c;它的子元素也會跟著全部刪除 let bt document.getElementById("bt"); bt.remove(); removeChild ()方法可以刪除指定的子元素 let bt document.getElementById("…

Git 倉庫的常用命令 遠程倉庫 本地倉庫

初始化倉庫&#xff1a; git init克隆&#xff08;Clone&#xff09;一個遠程倉庫到本地&#xff1a; git clone <遠程倉庫地址>添加&#xff08;Add&#xff09;文件到暫存區&#xff1a; git add <文件名>提交&#xff08;Commit&#xff09;文件到本地倉庫&a…

589.N叉樹的前序遍歷

刷算法題&#xff1a; 第一遍&#xff1a;1.看5分鐘&#xff0c;沒思路看題解 2.通過題解改進自己的解法&#xff0c;并且要寫每行的注釋以及自己的思路。 3.思考自己做到了題解的哪一步&#xff0c;下次怎么才能做對(總結方法) 4.整理到自己的自媒體平臺。 5.再刷重復的類…

【C++風云錄】提升設計效率:建筑工程與結構優化

優化你的工程設計&#xff1a;全面解析六大軟件庫 前言 本文將對六種廣泛使用于建筑工程設計的軟件工具進行深入探討&#xff0c;這些工具各自都有獨特的特性和應用場景。我們將詳細介紹并比較這些工具的設計流程&#xff0c;還將通過實例分析來進一步解釋它們在現實世界中的…

C++類與對象的兩個案例

1.立方體 #include <iostream> using namespace std;//立方體類設計 //1.創建立方體類 //2.設計屬性 //3.設計行為 獲取立方體面積和體積 //4.分別利用全局函數和成員函數 判斷兩個立方體是否相等class Cube { public:int getL(){return m_L;}void setL(int L){m_L L;}…

2024OD機試卷-找朋友 (java\python\c++)

題目:找朋友 題目描述 在學校中,N個小朋友站成一隊, 第i個小朋友的身高為height[i], 第i個小朋友可以看到的第一個比自己身高更高的小朋友j,那么j是i的好朋友(要求j > i)。 請重新生成一個列表,對應位置的輸出是每個小朋友的好朋友位置,如果沒有看到好朋友,請在該…

達夢sql中參數個數太多導致出現SOH等特殊字符報錯無效的序列號是不是達夢的bug

mybatis的Mapper.xml中如下&#xff1a; in中的參數大概有1萬6千多個&#xff0c;分成每1000個一組拼接成sql&#xff0c;然而在達夢中執行時報如下: Caused by: dm.jdbc.driver.DMException: Invalid sequence noat dm.jdbc.driver.DBError.throwException(DBError.java:710)…

【風變】Python爬蟲精進復習-20240430

參考筆記 下面給出一個巨佬學習風變pyhton基礎語法和爬蟲精進的筆記&#xff08;鏈接&#xff09; 風變編程筆記(一)-Python基礎語法 風變編程筆記(二)-Python爬蟲精進 技術總結 request BeautifulSoup selenium BeautifulSoup 練習0-1&#xff1a;文章下載 import requ…

舜山木業有限公司現已加入2024長三角快遞物流供應鏈與技術裝備展覽會

參展企業介紹 紹興舜山木業有限公司是中華人民共和國出境木質包裝定點企業、浙江省林業重點龍頭企業。2011年起全面導入和開發應用符合木包裝企業生產特點的ERP管理系統&#xff0c;順利通過國家三級安全生產標準化驗收&#xff0c;取得歐標托盤在中國大陸區的生產商執照資格。…