亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Java實(shí)現(xiàn)簡單學(xué)生管理系統(tǒng)

 更新時(shí)間:2022年07月25日 09:49:21   作者:車臣丿  
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)簡單學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Java實(shí)現(xiàn)簡單學(xué)生管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

名為StudentManageTest的Java測試類

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("-------------------歡迎來到學(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("請輸入您的選擇:");
? ? ? ? int num = sc.nextInt();
? ? ? ? if(num==1){
? ? ? ? ? ? stu.show();
? ? ? ? }
? ? ? ? if(num==2) {
? ? ? ? ? ? System.out.println("姓名:");
? ? ? ? ? ? String name = sc.next();
? ? ? ? ? ? System.out.println("學(xué)號:");
? ? ? ? ? ? int id = sc.nextInt();
? ? ? ? ? ? System.out.println("成績:");
? ? ? ? ? ? int score = sc.nextInt();
? ? ? ? ? ? Student s = new Student(name, id, score);
? ? ? ? ? ? stu.add(s);
? ? ? ? ? ? System.out.println("添加學(xué)生成功?。?);
? ? ? ? }
? ? ? ? if(num==3){
? ? ? ? ? ? System.out.println("請輸入需要刪除第幾個(gè)學(xué)生信息:");
? ? ? ? ? ? int id = sc.nextInt();
? ? ? ? ? ? stu.delete(id);
? ? ? ? ? ? System.out.println("刪除成功??!");
? ? ? ? }
? ? ? ? if(num==4){
? ? ? ? ? ? System.out.println("請輸入需要修改第幾個(gè)學(xué)生信息:");
? ? ? ? ? ? int n = sc.nextInt();
? ? ? ? ? ? System.out.println("姓名:");
? ? ? ? ? ? String name = sc.next();
? ? ? ? ? ? System.out.println("學(xué)號:");
? ? ? ? ? ? int id = sc.nextInt();
? ? ? ? ? ? System.out.println("成績:");
? ? ? ? ? ? int score = sc.nextInt();
? ? ? ? ? ? Student ch = new Student(name, id, score);
? ? ? ? ? ? stu.change(n,ch);
? ? ? ? ? ? System.out.println("修改成功??!");
? ? ? ? }
? ? ? ? if(num==5){
? ? ? ? ? ? System.out.println("請輸入你需要查詢第幾個(gè)學(xué)生信息:");
? ? ? ? ? ? int n = sc.nextInt();
? ? ? ? ? ? stu.check(n);
? ? ? ? }
? ? ? ? if(num==6){
? ? ? ? ? ? System.out.println("下次再來!!");
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? }
? ? }
}

名為Student的成員方法定義類

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的方法類

public class StudentManage{
? ? //初始三個(gè)學(xué)生對象,定義到一個(gè)叫ss的數(shù)組對象中
? ? Student[] ss = new Student[]{new Student("張三",1,70),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? new Student("李四",2,80),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? new Student("王五",3,85)};
? ? //添加操作
? ? public void add(Student s){ ?//傳入一個(gè)自定義的對象數(shù)據(jù)
? ? ? ? Student[] newss = new Student[ss.length+1];
? ? ? ? /*添加操作數(shù)組 ?因?yàn)閿?shù)組一旦定義就無法改變長度
? ? ? ? * 所以需要新定義比ss對象數(shù)組多一個(gè)長度的數(shù)組對象
? ? ? ? * */
? ? ? ? for (int i = 0; i <ss.length ; i++) { ?//該處循環(huán)的目的是把ss數(shù)組對象的數(shù)據(jù)復(fù)制一份到newss對象數(shù)組中
? ? ? ? ? ? newss[i] = ss[i];
? ? ? ? }
? ? ? ? newss[newss.length-1] = s; ?//該處是因?yàn)樾露x的數(shù)組長度多1,目的是把新傳入的對象數(shù)據(jù)賦值到新數(shù)組對象的最后一個(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é)號:\t\t成績:");
? ? ? ? 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)閷ο髷?shù)組不能改變長度,所以得重新創(chuàng)建個(gè)比ss對象數(shù)組少一個(gè)長度的對象數(shù)組
? ? ? ? Student[] deletess = new Student[ss.length-1];
? ? ? ? // 因?yàn)閯h除一個(gè)數(shù)據(jù),所以該數(shù)據(jù)前面數(shù)據(jù)索引和新數(shù)組對象數(shù)據(jù)的索引一樣,因此循環(huán)遍歷到n-1
? ? ? ? for (int i = 0; i <n-1 ; i++) {
? ? ? ? ? ? //所以新數(shù)組對象n-1前面的數(shù)據(jù)一樣
? ? ? ? ? ? deletess[i] = ss[i];
? ? ? ? }
? ? ? ? //刪除了第n個(gè)元素,對應(yīng)數(shù)組的第n-1個(gè)數(shù)據(jù),所以數(shù)組元素從(n-1)+1開始遍歷,即從n開始遍歷
? ? ? ? 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é)號:\t\t成績:");
? ? ? ? System.out.println(ss[n-1].show());//輸出數(shù)組對象ss的第n-1個(gè)數(shù)據(jù)的show方法
? ? }
}

測試功能:

學(xué)生管理系統(tǒng)初始化界面

顯示學(xué)生信息

新增學(xué)生信息

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

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

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

退出

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論