欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java實現(xiàn)簡單學生信息管理系統(tǒng)

 更新時間:2021年09月14日 16:05:37   作者:悠檸  
這篇文章主要為大家詳細介紹了Java實現(xiàn)簡單學生信息管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

最近在學習Java,所以寫了個學生信息管理系統(tǒng),話不多說,上代碼。

Student.java:

package com.mumu;

public class Student {  //定義學生類
    private String name;
    private String age;
    private String id;
    private String room_num;
    private int math;
    private int english;
    private int physic;

    public Student() {//無參構(gòu)造方法
    }

    public Student(String name, String age, String id, String room_num, int math, int english, int physic) {
        this.name = name;
        this.age = age;
        this.id = id;
        this.room_num = room_num;
        this.math = math;
        this.english = english;
        this.physic = physic;
    }

//Alt+ INSERT鍵,可自動生成構(gòu)造方法
    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 getId() {
        return id;
    }

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

    public String getRoom_num() {
        return room_num;
    }

    public void setRoom_num(String room_num) {
        this.room_num = room_num;
    }

    public int getMath() {
        return math;
    }

    public int getEnglish() {
        return english;
    }

    public int getPhysic() {
        return physic;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    public void setPhysic(int physic) {
        this.physic = physic;
    }
}

StudentManager .java:

package com.mumu;

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

public class StudentManager {
    public static void main(String[] args) {

    ArrayList<Student> array=new ArrayList<>();
    menu(array);
    }
    public static void menu(ArrayList<Student> array)//菜單
    {
        while(true)
        {
            System.out.println("^^^^^^^^welcom to my System^^^^^^^^");
            System.out.println("please input your choice");
            System.out.println("1.add students' information");
            System.out.println("2.remove students' information");
            System.out.println("3.revise students' information");
            System.out.println("4.look over students' information");
            System.out.println("5.find  students' information");
            System.out.println("6.quit the system");
            Scanner sc=new Scanner(System.in);
            String choice =sc.nextLine();
            switch(choice)
            {
                case "1":
                    adding(array);
                    break;
                case "2":
                    removing(array);
                    break;
                case "3":
                    revising(array);
                    break;
                case "4":
                    look_over(array);
                    break;
                case "5":
                    serching(array);
                case "6":
                    quiting();
                    break;
                default:
                    System.out.println("error!");
                    System.exit(0);
            }
        }

    }

    public static void adding(ArrayList<Student> array)//添加學生信息
    {//錄入的學生數(shù)據(jù)錄入給成員變量
        System.out.println("please input student's id");
        Scanner sc=new Scanner(System.in);
        String stu_num=sc.nextLine();
        if(is_used(array,stu_num)==false)
        {
            System.out.println("please input student's name");
            String stu_name=sc.nextLine();
            System.out.println("please input student's age");
            String stu_age=sc.nextLine();
            System.out.println("please input student's room number");
            String stu_addr=sc.nextLine();
            System.out.println("do you want to add student's grade?yes/no");
            //創(chuàng)建學生對象
            Student st=new Student();
            st.setAge(stu_age);
            st.setId(stu_num);
            st.setName(stu_name);
            st.setRoom_num(stu_addr);
            //添加學生成績
            String cho=sc.nextLine();
            if(cho=="yes")
            {
                System.out.println("please input student's math grade");
                int stu_math=sc.nextInt();
                System.out.println("please input student's english grade");
                int stu_english= sc.nextInt();
                System.out.println("please input student's physic grade");
                int stu_physic= sc.nextInt();
                st.setMath(stu_math);
                st.setEnglish(stu_english);
                st.setPhysic(stu_physic);
            }
            //將學生對象添加到集合中
            array.add(st);
            System.out.println("add successfully");
        }
        else
        {
            System.out.println("you are already input information of this student");
        }

    }
    public static void removing(ArrayList<Student> array)//刪除學生信息
    {
    Scanner sc=new Scanner(System.in);
        System.out.println("please input student's number");
        String stu_num=sc.nextLine();
        for(int i=0;i<array.size();i++)
        {
            Student st=array.get(i);
            if(st.getId().equals(stu_num))
            {
                array.remove(i);
                break;
            }
            else
            {
                System.out.println("there is no information of that student");
            }
        }
        System.out.println("remove successfully");
    }
    public static void revising(ArrayList<Student> array)//修改學生信息
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("please input stubent's id");
        String stu_num=sc.nextLine();
        System.out.println("please input student's new name");
        String stu_name=sc.nextLine();
        System.out.println("please input student's new  id");
        String stu_id=sc.nextLine();
        System.out.println("please input student's new age");
        String stu_age=sc.nextLine();
        System.out.println("please input student's new room_number");
        String stu_add=sc.nextLine();
        System.out.println("do you want to revise student's grade?yes/no");
        //創(chuàng)建學生對象
        Student st1=new Student();
        st1.setRoom_num(stu_add);
        st1.setName(stu_name);
        st1.setId(stu_id);
        st1.setAge(stu_age);
        String cho= sc.nextLine();
        if(cho=="yes")
        {
            System.out.println("please input student's new math grade");
            int stu_math=sc.nextInt();
            System.out.println("please input student's new english grade");
            int stu_english=sc.nextInt();
            System.out.println("please input student's new physic grade");
            int stu_physic=sc.nextInt();
            st1.setEnglish(stu_english);
            st1.setMath(stu_math);
            st1.setPhysic(stu_physic);
        }
        for(int i=0;i< array.size();i++)
        {
            Student st2=array.get(i);
            if(st2.getId().equals(stu_num))//判斷輸入的學號是否在array里面
            {
                array.set(i,st1);
                break;
            }
            else
            {
                System.out.println("there is no information of that student");
            }
        }
        System.out.println("revise successfully");
    }
    public static void look_over(ArrayList<Student> array)//查看所有學生信息
    {
        if(array.size()==0)//先判斷集合是否為空
        {
            System.out.println("there is no information,please input information firstly");
        }
        else
        {
            System.out.println("number\tname\tage\troom_number\tmath_grade\tenglish_grade\tphysic_grade");
            for(int i=0;i<array.size();i++)
            {
                Student st=array.get(i);
                System.out.println(st.getId()+"\t"+st.getName()+"\t"+st.getAge()+"\t"+st.getRoom_num()+"\t"
                        +st.getMath()+"\t"+st.getEnglish()+"\t"+st.getPhysic());
            }

        }

    }
    public static void quiting() //退出系統(tǒng)
    {
        System.exit(0);
    }

    public static boolean is_used(ArrayList<Student> array,String sid)//判斷學號是否重復
    {
        boolean temp=false;
        for(int i=0;i< array.size();i++)
        {
            Student st=array.get(i);
            if(st.getId().equals(sid))
            {
                temp=true;
                break;
            }
        }
        return temp;
    }
    public static void serching(ArrayList<Student> array)//通過學號查找
  {
      System.out.println("please input id of the student you want to find");
      Scanner sc=new Scanner(System.in);
      String stu_num=sc.nextLine();
      for(int i=0;i< array.size();i++)
      {
          Student st= array.get(i);
          if(st.getId().equals(stu_num))
          {
              System.out.println(st.getId()+"\t"+st.getName()+"\t"+st.getAge()+"\t"+st.getRoom_num()+"\t"
                      +st.getMath()+"\t"+st.getEnglish()+"\t"+st.getPhysic());
          }
          else
          {
              System.out.println("there is no information of that student");
          }
      }
  }
}

代碼是用IDEA寫的,因為是初學者,功能相對簡單,如有問題歡迎指正哦。

更多學習資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。

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

相關(guān)文章

  • 詳細總結(jié)Java堆棧內(nèi)存、堆外內(nèi)存、零拷貝淺析與代碼實現(xiàn)

    詳細總結(jié)Java堆棧內(nèi)存、堆外內(nèi)存、零拷貝淺析與代碼實現(xiàn)

    零拷貝,這是個耳熟能詳?shù)拿~,是開發(fā)崗面試中經(jīng)常提及的問題.最近在回顧Netty的基礎(chǔ)原理,還是把NIO中關(guān)于堆外內(nèi)存的知識點過了一遍,這里就針對堆棧內(nèi)存 堆外內(nèi)存和零拷貝這幾個概念以及相關(guān)知識做一下記錄,需要的朋友可以參考下
    2021-05-05
  • java中@JSONField和@JsonProperty注解的使用說明及對比

    java中@JSONField和@JsonProperty注解的使用說明及對比

    @JSONField與@JsonProperty隸屬兩個不同的包,前者是阿里系的fastjson包,后者是spring?boot官方使用的jackson包,本文主要介紹了java中@JSONField和@JsonProperty注解的使用說明及對比,感興趣的可以了解一下
    2023-11-11
  • Resty極簡restful框架快速接入Spring

    Resty極簡restful框架快速接入Spring

    這篇文章主要為大家介紹了Resty極簡的restful框架快速接入Spring詳細說明,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-03-03
  • 微信公眾平臺(測試接口)準備工作

    微信公眾平臺(測試接口)準備工作

    想要微信開發(fā),首先要有個服務器,但是自己沒有。這時候可以用花生殼,將內(nèi)網(wǎng)映射到公網(wǎng)上,這樣就可以在公網(wǎng)訪問自己的網(wǎng)站了。
    2016-05-05
  • Spring Cloud服務安全連接方式

    Spring Cloud服務安全連接方式

    這篇文章主要介紹了Spring Cloud服務安全連接方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Java中double保留兩位小數(shù)的多種方法

    Java中double保留兩位小數(shù)的多種方法

    這篇文章主要給大家介紹了關(guān)于Java中double保留兩位小數(shù)的多種方法,對于double數(shù)據(jù)類型進行計算發(fā)生的精度丟失的情況,可以按照自己的需求選擇任意方式,需要的朋友可以參考下
    2023-07-07
  • Java實現(xiàn)窗體程序顯示日歷

    Java實現(xiàn)窗體程序顯示日歷

    這篇文章主要為大家詳細介紹了Java實現(xiàn)窗體程序顯示日歷,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • Java Swing JList列表框的實現(xiàn)

    Java Swing JList列表框的實現(xiàn)

    這篇文章主要介紹了Java Swing JList列表框的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-12-12
  • java檢測redis是否可用的方法示例

    java檢測redis是否可用的方法示例

    這篇文章主要給大家介紹了關(guān)于java檢測redis是否可用的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用java具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-08-08
  • Java編程讀寫鎖詳解

    Java編程讀寫鎖詳解

    本篇文章給大家詳細分享了Java編程讀寫鎖的相關(guān)原理以及知識點內(nèi)容,有興趣的朋友們可以參考下。
    2018-08-08

最新評論