Java實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)
本文實(shí)例為大家分享了Java實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
名為StudentManageTest的Java測(cè)試類(lèi)
import java.util.Scanner;
?
public class StudentManageTest {
? ? public static void main(String[] args) {
? ? ? ? StudentManage stu = new StudentManage();
? ? ? ? Scanner sc = new Scanner(System.in);
?
? ? ? ? while (true){
? ? ? ? System.out.println("-------------------歡迎來(lái)到學(xué)生管理系統(tǒng)------------------------");
? ? ? ? System.out.println("------ ? ? ? ? ? ? ?1. 查看所有學(xué)生 ? ? ? ? ? ? ? ? ? ? ?-----");
? ? ? ? System.out.println("------ ? ? ? ? ? ? ?2. 添加學(xué)生 ? ? ? ? ? ? ? ? ? ? ? ? ?-----");
? ? ? ? System.out.println("------ ? ? ? ? ? ? ?3. 刪除學(xué)生 ? ? ? ? ? ? ? ? ? ? ? ? ?-----");
? ? ? ? System.out.println("------ ? ? ? ? ? ? ?4. 修改學(xué)生 ? ? ? ? ? ? ? ? ? ? ? ? ?-----");
? ? ? ? System.out.println("------ ? ? ? ? ? ? ?5. 查詢學(xué)生 ? ? ? ? ? ? ? ? ? ? ? ? ?-----");
? ? ? ? System.out.println("------ ? ? ? ? ? ? ?6. 退出 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-----");
? ? ? ? System.out.println("--------------------------------------------------------------");
? ? ? ? System.out.print("請(qǐng)輸入您的選擇:");
? ? ? ? int num = sc.nextInt();
? ? ? ? if(num==1){
? ? ? ? ? ? stu.show();
? ? ? ? }
? ? ? ? if(num==2) {
? ? ? ? ? ? System.out.println("姓名:");
? ? ? ? ? ? String name = sc.next();
? ? ? ? ? ? System.out.println("學(xué)號(hào):");
? ? ? ? ? ? int id = sc.nextInt();
? ? ? ? ? ? System.out.println("成績(jī):");
? ? ? ? ? ? int score = sc.nextInt();
? ? ? ? ? ? Student s = new Student(name, id, score);
? ? ? ? ? ? stu.add(s);
? ? ? ? ? ? System.out.println("添加學(xué)生成功!!");
? ? ? ? }
? ? ? ? if(num==3){
? ? ? ? ? ? System.out.println("請(qǐng)輸入需要?jiǎng)h除第幾個(gè)學(xué)生信息:");
? ? ? ? ? ? int id = sc.nextInt();
? ? ? ? ? ? stu.delete(id);
? ? ? ? ? ? System.out.println("刪除成功!!");
? ? ? ? }
? ? ? ? if(num==4){
? ? ? ? ? ? System.out.println("請(qǐng)輸入需要修改第幾個(gè)學(xué)生信息:");
? ? ? ? ? ? int n = sc.nextInt();
? ? ? ? ? ? System.out.println("姓名:");
? ? ? ? ? ? String name = sc.next();
? ? ? ? ? ? System.out.println("學(xué)號(hào):");
? ? ? ? ? ? int id = sc.nextInt();
? ? ? ? ? ? System.out.println("成績(jī):");
? ? ? ? ? ? int score = sc.nextInt();
? ? ? ? ? ? Student ch = new Student(name, id, score);
? ? ? ? ? ? stu.change(n,ch);
? ? ? ? ? ? System.out.println("修改成功??!");
? ? ? ? }
? ? ? ? if(num==5){
? ? ? ? ? ? System.out.println("請(qǐng)輸入你需要查詢第幾個(gè)學(xué)生信息:");
? ? ? ? ? ? int n = sc.nextInt();
? ? ? ? ? ? stu.check(n);
? ? ? ? }
? ? ? ? if(num==6){
? ? ? ? ? ? System.out.println("下次再來(lái)??!");
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? }
? ? }
}名為Student的成員方法定義類(lèi)
public class Student {
? ? private String name;
? ? private int id;
? ? private int score;
?
? ? public Student() {
? ? }
?
? ? public Student(String name, int id, int score) {
? ? ? ? this.name = name;
? ? ? ? this.id = id;
? ? ? ? this.score = score;
? ? }
?
? ? public String show() {
? ? ? ? return name +"\t\t" + id + "\t\t\t" + score;
? ? }
}名為StudentManage的方法類(lèi)
public class StudentManage{
? ? //初始三個(gè)學(xué)生對(duì)象,定義到一個(gè)叫ss的數(shù)組對(duì)象中
? ? Student[] ss = new Student[]{new Student("張三",1,70),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? new Student("李四",2,80),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? new Student("王五",3,85)};
? ? //添加操作
? ? public void add(Student s){ ?//傳入一個(gè)自定義的對(duì)象數(shù)據(jù)
? ? ? ? Student[] newss = new Student[ss.length+1];
? ? ? ? /*添加操作數(shù)組 ?因?yàn)閿?shù)組一旦定義就無(wú)法改變長(zhǎng)度
? ? ? ? * 所以需要新定義比ss對(duì)象數(shù)組多一個(gè)長(zhǎng)度的數(shù)組對(duì)象
? ? ? ? * */
? ? ? ? for (int i = 0; i <ss.length ; i++) { ?//該處循環(huán)的目的是把ss數(shù)組對(duì)象的數(shù)據(jù)復(fù)制一份到newss對(duì)象數(shù)組中
? ? ? ? ? ? newss[i] = ss[i];
? ? ? ? }
? ? ? ? newss[newss.length-1] = s; ?//該處是因?yàn)樾露x的數(shù)組長(zhǎng)度多1,目的是把新傳入的對(duì)象數(shù)據(jù)賦值到新數(shù)組對(duì)象的最后一個(gè)
? ? ? ? ss=newss; ?//將newss堆中的數(shù)據(jù)地址賦給ss,即ss指向堆中存有新數(shù)據(jù)的內(nèi)存地址
? ? ? ? //當(dāng)執(zhí)行show方法時(shí),遍歷輸出的是堆中新的地址的新的數(shù)據(jù)
? ? }
? ? public void show(){ ?//循環(huán)遍歷輸出ss中的數(shù)據(jù)
? ? ? ? System.out.println("姓名:\t\t學(xué)號(hào):\t\t成績(jī):");
? ? ? ? for (int i = 0; i <ss.length ; i++) {
? ? ? ? ? ? System.out.println(ss[i].show());
? ? ? ? }
? ? }
? ? public void delete(int n){ ?//刪除操作 ?刪除第n個(gè)數(shù)據(jù)
? ? ? ? //因?yàn)閷?duì)象數(shù)組不能改變長(zhǎng)度,所以得重新創(chuàng)建個(gè)比ss對(duì)象數(shù)組少一個(gè)長(zhǎng)度的對(duì)象數(shù)組
? ? ? ? Student[] deletess = new Student[ss.length-1];
? ? ? ? // 因?yàn)閯h除一個(gè)數(shù)據(jù),所以該數(shù)據(jù)前面數(shù)據(jù)索引和新數(shù)組對(duì)象數(shù)據(jù)的索引一樣,因此循環(huán)遍歷到n-1
? ? ? ? for (int i = 0; i <n-1 ; i++) {
? ? ? ? ? ? //所以新數(shù)組對(duì)象n-1前面的數(shù)據(jù)一樣
? ? ? ? ? ? deletess[i] = ss[i];
? ? ? ? }
? ? ? ? //刪除了第n個(gè)元素,對(duì)應(yīng)數(shù)組的第n-1個(gè)數(shù)據(jù),所以數(shù)組元素從(n-1)+1開(kāi)始遍歷,即從n開(kāi)始遍歷
? ? ? ? for (int i = n; i <ss.length ; i++) {
? ? ? ? ? ? //所以ss的第n個(gè)元素就等于deletess的第n-1個(gè)元素
? ? ? ? ? ? deletess[i-1] = ss[i];
? ? ? ? }
? ? ? ? //將deletess堆中的數(shù)據(jù)地址賦給ss,即ss指向堆中存有新數(shù)據(jù)的內(nèi)存地址
? ? ? ? ss=deletess;
? ? }
? ? //修改操作,傳入?yún)?shù)含義:修改第幾個(gè)數(shù)據(jù),把它修改成什么
? ? public void change(int n,Student ch){
? ? ? ? ss[n-1] = ch; ?//直接將ss的第n-1個(gè)元素修改成ch
? ? }
? ? //查詢學(xué)生數(shù)據(jù),查詢第n個(gè)數(shù)據(jù)
? ? public void check(int n){
? ? ? ? System.out.println("姓名:\t\t學(xué)號(hào):\t\t成績(jī):");
? ? ? ? System.out.println(ss[n-1].show());//輸出數(shù)組對(duì)象ss的第n-1個(gè)數(shù)據(jù)的show方法
? ? }
}測(cè)試功能:
學(xué)生管理系統(tǒng)初始化界面

顯示學(xué)生信息

新增學(xué)生信息


刪除某個(gè)學(xué)生信息

修改某個(gè)學(xué)生信息

查詢某個(gè)學(xué)生信息

退出

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java+Mysql學(xué)生管理系統(tǒng)源碼
- java學(xué)生管理系統(tǒng)界面簡(jiǎn)單實(shí)現(xiàn)(全)
- Java基于MySQL實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- 簡(jiǎn)單實(shí)現(xiàn)Java版學(xué)生管理系統(tǒng)
- Java實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- java實(shí)現(xiàn)學(xué)生管理系統(tǒng)(面向?qū)ο?
- java設(shè)計(jì)簡(jiǎn)單學(xué)生管理系統(tǒng)
- Java實(shí)現(xiàn)學(xué)生管理系統(tǒng)詳解
- java實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)項(xiàng)目
- java基于jdbc實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)
相關(guān)文章
Java實(shí)現(xiàn)“年-月-日 上午/下午時(shí):分:秒”的簡(jiǎn)單代碼
當(dāng)前的日期輸出的方法有很多,本文為大家介紹下在java中是如何實(shí)現(xiàn)“年-月-日 上午/下午時(shí):分:秒”,感興趣的朋友不妨參考下2015-08-08
Springboot基于websocket實(shí)現(xiàn)簡(jiǎn)單在線聊天功能
這篇文章主要介紹了Springboot基于websocket實(shí)現(xiàn)簡(jiǎn)單在線聊天功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06
Java concurrency集合之CopyOnWriteArraySet_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
CopyOnWriteArraySet基于CopyOnWriteArrayList實(shí)現(xiàn),其唯一的不同是在add時(shí)調(diào)用的是CopyOnWriteArrayList的addIfAbsent(若沒(méi)有則增加)方法2017-06-06
springboot時(shí)間格式化的五種方法總結(jié)(解決后端傳給前端的時(shí)間顯示不一致)
這篇文章主要給大家介紹了關(guān)于springboot時(shí)間格式化的五種方法,文中介紹的方法解決了后端傳給前端的時(shí)間顯示不一致,文中通過(guò)圖文以及代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-01-01
Java在制作jar包時(shí)引用第三方j(luò)ar包的方法
這篇文章主要介紹了Java在制作jar包時(shí)引用第三方j(luò)ar包的方法的相關(guān)資料,需要的朋友可以參考下2016-01-01
spring boot 實(shí)現(xiàn)配置多個(gè)DispatcherServlet最簡(jiǎn)單方式
這篇文章主要介紹了spring boot 實(shí)現(xiàn)配置多個(gè)DispatcherServlet最簡(jiǎn)單方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01

