国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

用Java代碼實(shí)現(xiàn)學(xué)生管理系統(tǒng)(可實(shí)現(xiàn)用戶登錄注冊功能)

這篇具有很好參考價(jià)值的文章主要介紹了用Java代碼實(shí)現(xiàn)學(xué)生管理系統(tǒng)(可實(shí)現(xiàn)用戶登錄注冊功能)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

學(xué)生管理系統(tǒng)

簡單實(shí)現(xiàn)學(xué)生系統(tǒng)的登錄和注冊,以及學(xué)生信息添加、刪除,修改、查詢功能。根據(jù)需求,創(chuàng)建一個(gè)學(xué)生類和和用戶類以及學(xué)生系統(tǒng)類,在登錄管理系統(tǒng)之前需要先注冊用戶,只有輸入正確的用戶名和密碼才可以登錄,忘記密碼后可以根據(jù)用戶信息進(jìn)行修改,用容器存儲學(xué)生信息和用戶信息,這里用到ArrayList<E>,這是基礎(chǔ)版的,進(jìn)一步可以將信息存到數(shù)據(jù)庫中。

目錄

學(xué)生管理系統(tǒng)

? ? ? ???1.項(xiàng)目演示

? ? ? ???2.學(xué)生管理系統(tǒng)實(shí)現(xiàn)思路

3.1定義用戶類

3.2定義學(xué)生類

4.1主界面的實(shí)現(xiàn)

4.2添加學(xué)生的代碼編寫

4.3刪除學(xué)生的代碼編寫

4.4修改學(xué)生的代碼編寫

4.5查詢學(xué)生的代碼

5.登錄時(shí)的驗(yàn)證碼功能

6.1項(xiàng)目結(jié)構(gòu)

6.2全部代碼

?總結(jié)

?注:需將用戶類和學(xué)生類和測試類三個(gè)代碼放在同一個(gè)包下才可運(yùn)行


?1.項(xiàng)目演示

用Java代碼實(shí)現(xiàn)學(xué)生管理系統(tǒng)(可實(shí)現(xiàn)用戶登錄注冊功能)

?用Java代碼實(shí)現(xiàn)學(xué)生管理系統(tǒng)(可實(shí)現(xiàn)用戶登錄注冊功能)

?2.學(xué)生管理系統(tǒng)實(shí)現(xiàn)思路

1.定義用戶類

2.實(shí)現(xiàn)登錄界面的代碼編寫

3.實(shí)現(xiàn)注冊、登錄、忘記密碼功能的代碼編寫

4.定義學(xué)生類

5.管理系統(tǒng)主界面的代碼編寫

6.實(shí)現(xiàn)增刪改查功能的代碼編寫

3.1定義用戶類

package com.ithm.student;

public class User {
    private String username;
    private String password;
    private String personID;
    private String phoneNumber;

    public User() {
    }

    public User(String username, String password, String personID, String phoneNumber) {
        this.username = username;
        this.password = password;
        this.personID = personID;
        this.phoneNumber = phoneNumber;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPersonID() {
        return personID;
    }

    public void setPersonID(String personID) {
        this.personID = personID;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }
}

3.2定義學(xué)生類

package com.ithm.student;

public class Student {

    private int id;
    private String name;
    private int age;
    private String address;

    public Student() {
    }

    public Student(int id, String name, int age, String address) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.address = address;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    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 getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}

4.1主界面的實(shí)現(xiàn)

思路:

  1. 用輸出語句完成主界面的編寫
  2. 用Scanner實(shí)現(xiàn)鍵盤錄入數(shù)據(jù)
  3. 用switch語句完成操作的選擇
  4. 用循環(huán)完成再次回到主界面
     public static void menu(){
            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("---           0.退出                  ---");
            System.out.println("----------------------------------------");
        }
        public static void choose(ArrayList<Student> list){
           while (true){
               menu();
               System.out.print("請輸入你的選擇:");
               Scanner sc=new Scanner(System.in);
               int t= sc.nextInt();
               switch (t){
                   case(1):  addStudent(list);    break;
                   case(2):  deleteStudent(list); break;
                   case(3):  updateStudent(list); break;
                   case(4):  queryStudent(list);  break;
                   case(0):  System.exit(0);
                   default:  return;
               }
           }
        }

4.2添加學(xué)生的代碼編寫

  1. 用鍵盤錄入選擇添加學(xué)生
  2. 定義一個(gè)方法,用于添加學(xué)生
    顯示提示信息,提示要輸入何種信息? ? ? ? ?
  3. 錄入id時(shí)定義一個(gè)查詢方法,查看集合中是否已經(jīng)添加過此id,確保id唯一
  4. 鍵盤錄入學(xué)生對象所需要的數(shù)據(jù)創(chuàng)建學(xué)生對象,把鍵盤錄入的數(shù)據(jù)賦值給學(xué)生對象的成員變量
  5. 將學(xué)生對象添加到集合中(保存數(shù)據(jù))
 public static void addStudent(ArrayList<Student> list){
     Student stu=new Student();
     Scanner sc=new Scanner(System.in);
        System.out.print("請輸入學(xué)生的學(xué)號id:");
        while (true){
            int id= sc.nextInt();
            boolean item=comain(list,id);
            if(item){
                System.out.println("此學(xué)生已經(jīng)存在,請重新輸入學(xué)生id");
            }else {
                stu.setId(id);
                break;
            }
        }
        System.out.print("請輸入學(xué)生的名字:");
        String name=sc.next();
        stu.setName(name);
        System.out.print("請輸入學(xué)生的年齡:");
        int age= sc.nextInt();
        stu.setAge(age);
        System.out.print("請輸入學(xué)生的地址:");
        String address=sc.next();
        stu.setAddress(address);
        list.add(stu);
    }

public static boolean comain(ArrayList<Student> list,int id){
        for (int i = 0; i < list.size(); i++) {
            if(id==list.get(i).getId()){
                return true;
            }
        }
        return false;
    }

4.3刪除學(xué)生的代碼編寫

  1. 用鍵盤錄入選擇刪除學(xué)生信息
  2. 定義一個(gè)方法,用于刪除學(xué)生信息
    提示信息
    鍵盤錄入要刪除的學(xué)生學(xué)號
    遍歷集合將對應(yīng)學(xué)生對象從集合里刪除
    給出刪除成功提示
public static void deleteStudent(ArrayList<Student> list){
        System.out.println("請輸入要刪除的學(xué)生學(xué)號:");
       while (true){
           Scanner sc=new Scanner(System.in);
           int id= sc.nextInt();
           for (int i = 0; i < list.size(); i++) {
               if(list.get(i).getId()==id){
                   list.remove(i);
                   System.out.println("刪除成功");
                   return;
               }
           }
           System.out.println("未找到該學(xué)生,請重新輸入id");
       }
    }

4.4修改學(xué)生的代碼編寫

  1. 鍵盤錄入選擇修改學(xué)生
  2. 自定義一個(gè)方法,用于修改學(xué)生信息
    提示信息
    鍵盤錄入要修改的學(xué)生學(xué)號
    根據(jù)提示選擇修改哪一個(gè)信息
  3. 鍵盤錄入要修改的學(xué)生信息
    遍歷集合修改對應(yīng)學(xué)生信息
    給出成功提示
public static void updateStudent(ArrayList<Student> list){
      while (true){
          System.out.print("請輸入學(xué)生id:");
          Scanner sc=new Scanner(System.in);
          int id= sc.nextInt();
          for (int i = 0; i < list.size(); i++) {
              if(list.get(i).getId()==id){
                  System.out.println("已查詢到該學(xué)生,請選擇更改哪一條信息");
                  Student stu=list.get(i);
                  System.out.println("1.更改學(xué)生姓名 2.更改學(xué)生年齡 3.更改學(xué)生家庭地址");
                  int item=sc.nextInt();
                  if(item==1){
                      System.out.println("請輸入更改后的學(xué)生姓名");
                      String name=sc.next();
                      stu.setName(name);
                      System.out.println("更改成功!");  return;
                  }else if(item==2){
                      System.out.println("請輸入更改后的學(xué)生年齡");
                      int age=sc.nextInt();
                      stu.setAge(age);
                      System.out.println("更改成功!"); return;
                  }else if(item==3){
                      System.out.println("請輸入更改后的學(xué)生家庭地址");
                      String address=sc.next();
                      stu.setName(address);
                      System.out.println("更改成功!"); return;
                  }
              }
          }
          System.out.println("未查詢到該學(xué)生");
      }
    }

4.5查詢學(xué)生的代碼

  1. 首先判斷集合里是否存在學(xué)生對象,如果沒有直接返回
  2. 根據(jù)提示,按照id查詢或查詢?nèi)繉W(xué)生
  3. 將集合中數(shù)據(jù)取出按照對應(yīng)格式顯示學(xué)生信息
 public static void queryStudent(ArrayList<Student> list){
        if(list.size()==0){
            System.out.println("請先添加學(xué)生,暫無學(xué)生信息!");
            return;
        }
        System.out.println("1.根據(jù)學(xué)生id查詢  2.查詢?nèi)繉W(xué)生");
        Scanner sc=new Scanner(System.in);
        int t= sc.nextInt();
       if(t==1){
           System.out.println("請輸入要查詢的學(xué)生id");
           while (true){
              int id= sc.nextInt();
              for (int i = 0; i < list.size(); i++) {
                  if(list.get(i).getId()==id){
                      System.out.println("id\t\t姓名\t\t年齡\t家庭地址");
                      Student stu=list.get(i);
                      System.out.println(stu.getId()+"\t"+stu.getName()+"\t"+stu.getAge()+"\t"+stu.getAddress());
                      return;
                  }
              }
              System.out.println("沒有該學(xué)生信息,請重新輸入id");
          }
       }else if(t==2) {
           for (int i = 0; i < list.size(); i++) {
                   System.out.println("id\t\t姓名\t\t年齡\t家庭地址");
                   Student stu=list.get(i);
                   System.out.println(stu.getId()+"\t"+stu.getName()+"\t"+stu.getAge()+"\t"+stu.getAddress());
           }
       }
    }

實(shí)現(xiàn)用戶類與學(xué)生類的思路相同,都是先定義一個(gè)用戶對象,根據(jù)提示將數(shù)據(jù)添加到對象中,再將對象添加到集合中,實(shí)現(xiàn)用戶類時(shí)對用戶的各種信息的長度和格式都有要求,只有滿足格式輸入正確才可以成功輸入,具體代碼就不展示了,只展示一下驗(yàn)證碼功能

5.登錄時(shí)的驗(yàn)證碼功能

  1. 定義一個(gè)集合存放所有的大小寫字母
  2. 通過隨機(jī)數(shù)獲取集合的下標(biāo)
  3. 遍歷得到4個(gè)不同的大小寫字母,將字母都添加到StringBuider,最后隨機(jī)一個(gè)數(shù)字并添加
  4. 將StringBuider變成字符串再變成字符數(shù)字,隨機(jī)得到該數(shù)組的任意下標(biāo),將最后一位數(shù)字與下標(biāo)交換,實(shí)現(xiàn)了隨機(jī)數(shù)字和字母的驗(yàn)證碼
private static String getCode(){
        //驗(yàn)證碼要求有數(shù)字和大小寫字母,且數(shù)字出現(xiàn)在任意位置
        ArrayList<Character> list=new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            list.add((char)('a'+i));
            list.add((char)('A'+i));
        }
        Random random=new Random();
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < 4; i++) {
           int index=random.nextInt(list.size());
           char c=list.get(index);
           sb.append(c);
        }
        int number=random.nextInt(10);
        sb.append(number);
        char []arr=sb.toString().toCharArray();
        int flag=random.nextInt(arr.length);
        char temp=arr[flag];
        arr[flag]=arr[arr.length-1];
        arr[arr.length-1]=temp;
        return new String(arr);
    }

6.1項(xiàng)目結(jié)構(gòu)

用Java代碼實(shí)現(xiàn)學(xué)生管理系統(tǒng)(可實(shí)現(xiàn)用戶登錄注冊功能)

6.2全部代碼

package com.ithm.student;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class StudentSystem {
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();
        ArrayList<User> userlist=new ArrayList<>();
        loginPage(userlist,list);
    }
    public static void loginPage(ArrayList<User> userlist,ArrayList<Student> list){
       while (true){
           System.out.println("\t歡迎來到學(xué)生管理系統(tǒng)");
           System.out.println("請選擇操作:1登錄  2注冊  3忘記密碼");
           Scanner sc=new Scanner(System.in);
           int item=sc.nextInt();
           switch (item){
               case (1): loginUser(userlist,list); break;
               case (2): reggisterUser(userlist); break;
               case (3): forgetPassword(userlist); break;
               default:  return;
           }
       }
    }
    public static void loginUser(ArrayList<User> userlist,ArrayList<Student> list){
        Scanner sc=new Scanner(System.in);
        while (true){
            System.out.print("請輸入用戶名:");
            String username=sc.next();
            boolean t=containsUsername(userlist,username);
            if(!t){
                System.out.println(username+"不存在,請先注冊");
                return;
            }
            System.out.print("請輸入密碼:");
            String password=sc.next();
            while (true){
                String rightcode=getCode();
                System.out.println("當(dāng)前正確的驗(yàn)證碼是:"+rightcode);
                System.out.print("請輸入驗(yàn)證碼:");
                String Code=sc.next();
                if(rightcode.equalsIgnoreCase(Code)){
                    System.out.println("驗(yàn)證碼正確");
                    break;
                }else{
                    System.out.println("驗(yàn)證碼錯誤,請重新輸入");
                }
            }
            User useInfo=new User(username,password,null,null);
            boolean flag=checklogin(useInfo,userlist);
            int count=0;
            if(flag){
                System.out.println("登錄成功!");
                break;
            } else{
                count++;
                System.out.println("賬戶或者密碼錯誤,您還有"+(3-count)+"次機(jī)會嘗試登錄");
                if(count==3){
                    System.out.println("您已連續(xù)三次登錄失敗,當(dāng)前用戶"+username+"已經(jīng)被鎖定");
                }
            }
        }
        choose(list);
    }

    public static void reggisterUser(ArrayList<User> userlist){
        Scanner sc=new Scanner(System.in);
        String username,password1,personID, number;
        while (true){
            System.out.print("請輸入用戶名(4-16位字母加數(shù)字):");
            username= sc.next();
            boolean flag1=checkUsername(username);
            if(flag1){
                boolean flag2=containsUsername(userlist,username);
                if(flag2){
                    System.out.println("已經(jīng)存在該用戶,請重新輸入");
                }else{
                    System.out.println("用戶名:"+username+"可以使用");
                    break;
                }
            }else{
                System.out.println("用戶名的格式不滿足條件,請重新輸入");
            }
        }
        while (true){
            System.out.print("請輸入密碼:");
            password1= sc.next();
            System.out.print("請?jiān)俅屋斎朊艽a:");
            String password2= sc.next();
            if(password1.equals(password2)){
                System.out.println("兩次密碼一致");
                break;
            }else{
                System.out.println("兩次密碼不一致,請重新輸入");
            }
        }
        while (true){
            System.out.print("請輸入身份證號碼:");
           personID=sc.next();
            boolean flag=checkPersonID(personID);
            if(flag){
                System.out.println("身份證號碼滿足要求");
                break;
            }else {
                System.out.println("身份證格式錯誤,請重新輸入");
            }
        }
        while (true){
            System.out.print("請輸入電話號碼:");
           number=sc.next();
            boolean flag=checkPhoneNumber(number);
            if(flag){
                System.out.println("電話號碼滿足格式要求");
                break;
            }else {
                System.out.println("電話號碼格式錯誤,請重新輸入");
            }
        }
        User user=new User(username,password1,personID,number);
        userlist.add(user);
        System.out.println("注冊成功");
    }
    public static void forgetPassword(ArrayList<User> userlist){
        Scanner sc=new Scanner(System.in);
        System.out.print("請輸入用戶名:");
        String username=sc.next();
        boolean flag=containsUsername(userlist,username);
        int index=findIndex(userlist,username);
        User user=userlist.get(index);
        if(!flag){
            System.out.println(username+"不存在,請先注冊");
            return;
        }
        System.out.print("請輸入身份證號碼:");
        String personID=sc.next();
        System.out.print("請輸入手機(jī)號碼:");
        String number= sc.next();
        if(!(user.getPersonID().equals(personID)&&user.getPhoneNumber().equals(number))){
            System.out.println("用戶信息輸入有誤,無法修改密碼");
            return;
        }
        String passwor1;
        while (true){
            System.out.print("請輸入新密碼:");
            passwor1= sc.next();
            System.out.print("請?jiān)俅屋斎胄旅艽a:");
            String passwor2= sc.next();
            if(passwor1.equals(passwor2)){
                System.out.println("兩次密碼輸入一致");
                break;
            }else{
                System.out.println("兩次密碼不一致,請重新輸入");
            }
        }
        user.setPassword(passwor1);
        System.out.println("密碼修改成功!");
    }

    public static boolean checkUsername(String username){
        //檢查用戶名長度合法,長度在4到16位
        if(username.length()<4 ||username.length()>16){
            return false;
        }
        //用戶名只能是字母加數(shù)字,但不能是純數(shù)字
        int count=0;
        for (int i = 0; i < username.length(); i++) {
            char c=username.charAt(i);
            if(!((c>='0'&&c<='9') ||(c>='a'&&c<='z') ||(c>='A'&&c<='Z'))){
               return false;
            }
            if((c>='a'&&c<='z') ||(c>='A'&&c<='Z')){
                count++;
                break;
            }
        }
       return count>0;
    }
    public static boolean containsUsername(ArrayList<User> userlist,String username){
        for (int i = 0; i < userlist.size(); i++) {
            if(userlist.get(i).getUsername().equals(username)){
                return true;
            }
        }
        return false;
    }
    private static boolean checkPersonID(String personID) {
        //身份證號碼必須是18位,首位不能為0,前17位是數(shù)字,第18位是數(shù)字或字母x
      if(personID.length()!=18)     return false;
      if(personID.startsWith("0"))  return false;
        for (int i = 0; i < personID.length()-1; i++) {
            char c=personID.charAt(i);
            if(!(c>='0'&&c<='9')){
             return false;
            }
        }
        char end=personID.charAt(personID.length()-1);
        if(!(end=='x'|| end=='X'|| (end>='0'&&end<='9'))) return false;
        return true;
    }
    private static boolean checkPhoneNumber(String number) {
        //電話號碼為11位純數(shù)字,首位不能為0
        if(number.length()!=11)  return false;
        if(number.startsWith("0"))  return false;
        for (int i = 0; i < number.length(); i++) {
            char c=number.charAt(i);
            if(!(c>='0'&&c<='9')) return false;
        }
        return true;
    }
    private static boolean checklogin(User useInfo,ArrayList<User> userlist) {
        for (int i = 0; i < userlist.size(); i++) {
            User u=userlist.get(i);
            if(u.getUsername().equals(useInfo.getUsername()) &&u.getPassword().equals(useInfo.getPassword())){
                return true;
            }
        }
        return false;
    }

    private static String getCode(){
        //驗(yàn)證碼要求有數(shù)字和大小寫字母,且數(shù)字出現(xiàn)在任意位置
        ArrayList<Character> list=new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            list.add((char)('a'+i));
            list.add((char)('A'+i));
        }
        Random random=new Random();
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < 4; i++) {
           int index=random.nextInt(list.size());
           char c=list.get(index);
           sb.append(c);
        }
        int number=random.nextInt(10);
        sb.append(number);
        char []arr=sb.toString().toCharArray();
        int flag=random.nextInt(arr.length);
        char temp=arr[flag];
        arr[flag]=arr[arr.length-1];
        arr[arr.length-1]=temp;
        return new String(arr);
    }
    private static int findIndex(ArrayList<User> userlist, String username) {
        for (int i = 0; i < userlist.size(); i++) {
            if(userlist.get(i).getUsername().equals(username)){
                return i;
            }
        }
        return -1;
    }

    public static void menu(){
        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("---           0.退出                  ---");
        System.out.println("----------------------------------------");
    }
    public static void choose(ArrayList<Student> list){
       while (true){
           menu();
           System.out.print("請輸入你的選擇:");
           Scanner sc=new Scanner(System.in);
           int t= sc.nextInt();
           switch (t){
               case(1):  addStudent(list);    break;
               case(2):  deleteStudent(list); break;
               case(3):  updateStudent(list); break;
               case(4):  queryStudent(list);  break;
               case(0):  System.exit(0);
               default:  return;
           }
       }
    }
    public static void addStudent(ArrayList<Student> list){
     Student stu=new Student();
     Scanner sc=new Scanner(System.in);
        System.out.print("請輸入學(xué)生的學(xué)號id:");
        while (true){
            int id= sc.nextInt();
            boolean item=comain(list,id);
            if(item){
                System.out.println("此學(xué)生已經(jīng)存在,請重新輸入學(xué)生id");
            }else {
                stu.setId(id);
                break;
            }
        }
        System.out.print("請輸入學(xué)生的名字:");
        String name=sc.next();
        stu.setName(name);
        System.out.print("請輸入學(xué)生的年齡:");
        int age= sc.nextInt();
        stu.setAge(age);
        System.out.print("請輸入學(xué)生的地址:");
        String address=sc.next();
        stu.setAddress(address);
        list.add(stu);
    }
    public static void deleteStudent(ArrayList<Student> list){
        System.out.println("請輸入要刪除的學(xué)生學(xué)號:");
       while (true){
           Scanner sc=new Scanner(System.in);
           int id= sc.nextInt();
           for (int i = 0; i < list.size(); i++) {
               if(list.get(i).getId()==id){
                   list.remove(i);
                   System.out.println("刪除成功");
                   return;
               }
           }
           System.out.println("未找到該學(xué)生,請重新輸入id");
       }
    }
    public static void updateStudent(ArrayList<Student> list){
      while (true){
          System.out.print("請輸入學(xué)生id:");
          Scanner sc=new Scanner(System.in);
          int id= sc.nextInt();
          for (int i = 0; i < list.size(); i++) {
              if(list.get(i).getId()==id){
                  System.out.println("已查詢到該學(xué)生,請選擇更改哪一條信息");
                  Student stu=list.get(i);
                  System.out.println("1.更改學(xué)生姓名 2.更改學(xué)生年齡 3.更改學(xué)生家庭地址");
                  int item=sc.nextInt();
                  if(item==1){
                      System.out.println("請輸入更改后的學(xué)生姓名");
                      String name=sc.next();
                      stu.setName(name);
                      System.out.println("更改成功!");  return;
                  }else if(item==2){
                      System.out.println("請輸入更改后的學(xué)生年齡");
                      int age=sc.nextInt();
                      stu.setAge(age);
                      System.out.println("更改成功!"); return;
                  }else if(item==3){
                      System.out.println("請輸入更改后的學(xué)生家庭地址");
                      String address=sc.next();
                      stu.setName(address);
                      System.out.println("更改成功!"); return;
                  }
              }
          }
          System.out.println("未查詢到該學(xué)生");
      }

    }
    public static void queryStudent(ArrayList<Student> list){
        if(list.size()==0){
            System.out.println("請先添加學(xué)生,暫無學(xué)生信息!");
            return;
        }
        System.out.println("1.根據(jù)學(xué)生id查詢  2.查詢?nèi)繉W(xué)生");
        Scanner sc=new Scanner(System.in);
        int t= sc.nextInt();
       if(t==1){
           System.out.println("請輸入要查詢的學(xué)生id");
           while (true){
              int id= sc.nextInt();
              for (int i = 0; i < list.size(); i++) {
                  if(list.get(i).getId()==id){
                      System.out.println("id\t\t姓名\t\t年齡\t家庭地址");
                      Student stu=list.get(i);
                      System.out.println(stu.getId()+"\t"+stu.getName()+"\t"+stu.getAge()+"\t"+stu.getAddress());
                      return;
                  }
              }
              System.out.println("沒有該學(xué)生信息,請重新輸入id");
          }
       }else if(t==2) {
           for (int i = 0; i < list.size(); i++) {
                   System.out.println("id\t\t姓名\t\t年齡\t家庭地址");
                   Student stu=list.get(i);
                   System.out.println(stu.getId()+"\t"+stu.getName()+"\t"+stu.getAge()+"\t"+stu.getAddress());
           }
       }
    }
    public static boolean comain(ArrayList<Student> list,int id){
        for (int i = 0; i < list.size(); i++) {
            if(id==list.get(i).getId()){
                return true;
            }
        }
        return false;
    }
}

?總結(jié)

1.注冊時(shí)所有的信息都有數(shù)據(jù)上的判斷和要求,都是基礎(chǔ)的String方法,沒有使用正則表達(dá)式。

2.使用ArrayList集合來實(shí)現(xiàn)簡單的學(xué)生管理系統(tǒng),測試類和用數(shù)組實(shí)現(xiàn)的方法一樣。

2.添加學(xué)生時(shí)候先對list數(shù)組內(nèi)學(xué)生進(jìn)行判斷,確保學(xué)生id唯一,修改學(xué)生信息可以根據(jù)需求修改每一項(xiàng)數(shù)據(jù),查詢學(xué)生可以根據(jù)id查詢或者查詢?nèi)俊?span toymoban-style="hidden">文章來源地址http://www.zghlxwxcb.cn/news/detail-448053.html

注:需將用戶類和學(xué)生類和測試類三個(gè)代碼放在同一個(gè)包下才可運(yùn)行

到了這里,關(guān)于用Java代碼實(shí)現(xiàn)學(xué)生管理系統(tǒng)(可實(shí)現(xiàn)用戶登錄注冊功能)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

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

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

    學(xué)生管理系統(tǒng)效果圖 使用Java提供的Javax庫來實(shí)現(xiàn)圖形化界面,在使用這個(gè)庫的時(shí)候,我發(fā)現(xiàn)它和Qt十分相似,但和Qt相比感覺更方便使用。 效果圖: 1.主頁面 2.添加學(xué)生頁面 3.查找學(xué)生頁面 4.總結(jié) 該圖形化界面核心代碼其實(shí)和第一個(gè)在控制臺操作的管理系統(tǒng)基本一樣,只是進(jìn)

    2024年02月09日
    瀏覽(15)
  • java實(shí)現(xiàn)管理學(xué)生選課系統(tǒng)

    java實(shí)現(xiàn)管理學(xué)生選課系統(tǒng)

    項(xiàng)目簡介 基于Java?Swing+MySQL的學(xué)生選課管理系統(tǒng),支持對課程的發(fā)布,查詢,添加,刪除操作,同時(shí)支持對學(xué)生及教師信息的管理。 ? ? ? 2.項(xiàng)目采用技術(shù) 該項(xiàng)目主要使用Java Swing+SQLServer ? ? ? ?3.功能需求分析 學(xué)生選課管理系統(tǒng)中要實(shí)現(xiàn)管理者對于學(xué)生和教師信息的管理以

    2024年02月07日
    瀏覽(22)
  • 使用C++實(shí)現(xiàn)的學(xué)生成績管理系統(tǒng)(附完整代碼)

    學(xué)生成績管理系統(tǒng)可以錄入、查詢、修改學(xué)生的成績,它包括:信息條目序號、學(xué)生姓名、課程名稱、課程學(xué)分?jǐn)?shù)、學(xué)生該課程的成績(百分制成績, 等級制成績,績點(diǎn))。學(xué)生成績管理系統(tǒng)能夠提供以下功能: 1)錄入學(xué)生的成績信息:從鍵盤輸入數(shù)據(jù),依次輸入:學(xué)生姓

    2024年02月06日
    瀏覽(21)
  • 用JAVA實(shí)現(xiàn)一個(gè)學(xué)生管理系統(tǒng)和登錄系統(tǒng)

    用JAVA實(shí)現(xiàn)一個(gè)學(xué)生管理系統(tǒng)和登錄系統(tǒng)

    目錄 一、學(xué)生管理系統(tǒng): 1.創(chuàng)建學(xué)生對象Student的javabean類: 2.創(chuàng)建出學(xué)生管理系統(tǒng)?StudentSystem類: 1.addStudent方法:添加學(xué)生 2.ifOne方法,用來判斷我們輸入的學(xué)生id是否唯一(如果存在學(xué)生就不用再添加此學(xué)生): 3.queryStudent方法,把我們表中的所有學(xué)生顯示出來 4.getIndex()如果

    2024年02月11日
    瀏覽(18)
  • 【超詳細(xì)】Java實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)

    【超詳細(xì)】Java實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)

    ?項(xiàng)目介紹:用java實(shí)現(xiàn)學(xué)生信息的管理,其中錄入的數(shù)據(jù)包括:學(xué)號、姓名、年齡、居住地等,并且能夠?qū)崿F(xiàn)對學(xué)生信息的添加、修改、刪除、查看功能。 一、創(chuàng)建項(xiàng)目 1、項(xiàng)目名稱:myStudentManager 二、創(chuàng)建包 1、包名稱:study 2、名字也可以自己進(jìn)行命名 三、創(chuàng)建兩個(gè)類 1、

    2024年02月04日
    瀏覽(20)
  • 用Java實(shí)現(xiàn)學(xué)生管理系統(tǒng)【簡化版】基礎(chǔ)

    用Java實(shí)現(xiàn)學(xué)生管理系統(tǒng)【簡化版】基礎(chǔ)

    ???博客首頁:痛而不言笑而不語的淺傷 ??歡迎關(guān)注??點(diǎn)贊 ?? 收藏 ?留言 ?? 歡迎討論! ??本文由痛而不言笑而不語的淺傷原創(chuàng),CSDN首發(fā)! ??系列專欄:《Java每日一練》 ??首發(fā)時(shí)間:2022年6月4日 ?:熱愛Java學(xué)習(xí),期待一起交流! ????作者水平有限,如果發(fā)現(xiàn)錯

    2024年01月16日
    瀏覽(18)
  • Java基礎(chǔ)——學(xué)生成績信息管理系統(tǒng)(簡單實(shí)現(xiàn))

    1、 定義一個(gè)學(xué)生類 Student,包含姓名、成績信息; 2、使用 ArrayList集合存儲學(xué)生對象; 3、 對集合中的元素進(jìn)行增刪查改的操作。 學(xué)生類可以包含姓名、成績、學(xué)號、年齡等等,這里只包含了前兩項(xiàng)學(xué)生類屬性。 在該類中定義了簡單的增、刪、查、改的方法。 其中,遍歷集

    2024年02月11日
    瀏覽(21)
  • JAVA學(xué)生信息管理系統(tǒng)(數(shù)據(jù)庫實(shí)現(xiàn))

    JAVA學(xué)生信息管理系統(tǒng)(數(shù)據(jù)庫實(shí)現(xiàn))

    這次的項(xiàng)目是用數(shù)據(jù)庫實(shí)現(xiàn)學(xué)生的信息管理系統(tǒng),有三步組成,寫項(xiàng)目鏈接數(shù)據(jù)庫實(shí)現(xiàn)相關(guān)的操作 開發(fā)工具: eclipse、MySQL、navicat、mysql-connector-java-8.0.27 ? ? (1)主頁面 ? (2)添加界面 ? (3)刪除界面 ? ?(4)修改界面 ?(5)查找界面 (6)數(shù)據(jù)庫鏈接 ? 添加Java驅(qū)動包

    2024年02月11日
    瀏覽(32)
  • 用Java實(shí)現(xiàn)一個(gè)學(xué)生管理系統(tǒng)(附源碼)

    用Java實(shí)現(xiàn)一個(gè)學(xué)生管理系統(tǒng)(附源碼)

    目錄 一、題目要求 ?二、設(shè)計(jì)思路 (2)代表課程的類——Course類 (3)具體功能實(shí)現(xiàn)類——Function類 (4)測試類——Test類 三、代碼實(shí)現(xiàn) (1)Student.java文件 (2)Course.java文件 (3)Function.java文件 (4)Test.java文件 ????????編寫一個(gè)學(xué)生成績管理系統(tǒng)。學(xué)生的屬性包括學(xué)

    2024年02月08日
    瀏覽(20)
  • Java+Swing+MySQL實(shí)現(xiàn)學(xué)生選課管理系統(tǒng)

    Java+Swing+MySQL實(shí)現(xiàn)學(xué)生選課管理系統(tǒng)

    目錄 一、系統(tǒng)介紹 1.運(yùn)行環(huán)境 2.技術(shù)說明 3.系統(tǒng)功能 4.數(shù)據(jù)庫實(shí)體E-R圖設(shè)計(jì) 5.數(shù)據(jù)庫表的設(shè)計(jì) 二、系統(tǒng)實(shí)現(xiàn)? 1.用戶登錄 2.主界面? ?3.數(shù)據(jù)庫連接 4.數(shù)據(jù)查詢 5.查詢課程信息 6.添加學(xué)生信息 7.修改學(xué)生信息 三、部分代碼? 1.ChangePwd.java 2.Login.java 3.Main.java 5.備注 開發(fā)工具:

    2024年02月08日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包