Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Student Management system with Java

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how Java implements the student management system. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

I. Preface

We wrote the address book management system before, and now let's write a student management system.

In fact, the backbone code is all the same. I have added and optimized a lot of functions in the student management system.

Such as [login password verification, exception handling, non-empty judgment, prevent repeated addition] and so on.

II. Main functions of student management system

Increase student information

Delete student information

Modify student information

Find student information

View all student information

Withdraw from the student management system

General view of the backbone:

We have divided into many method modules, which are easy to call.

Under the category of students

Are ordinary constructors and get and set methods, as well as an overridden toString method

(Alt+Insert can quickly generate all of the above)

Package student management system; public class Student {private String name; private String age; private String sex; private String number; private String classroom; public Student () {} public Student (String name, String age, String sex, String classroom,String number) {this.name = name; this.age = age; this.sex = sex; this.classroom = classroom; this.number=number } 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 getSex () {return sex;} public void setSex (String sex) {this.sex = sex } public String getClassroom () {return classroom;} public void setClassroom (String classroom) {this.classroom = classroom;} public String getNumber () {return number;} public void setNumber (String number) {this.number = number;}

The toString method is overridden so that we can display it in the way we set it:

@ Override public String toString () {return "name:" + name+ "| gender:" + sex+ "| Age:" + age+ "| Student ID:" + number+ "| Class:" + classroom+ "\ n";} under the student headquarters category:

Main method: public static void main (String [] args) {ArrayList arrayList=new ArrayList (); password (); / / password authentication while (true) {menu (); / / menu Scanner sc=new Scanner (System.in); try {int num=sc.nextInt () Switch (num) {case 1: {addStudent (arrayList); break;} case 2: {deleteStudent (arrayList); break;} case 3: {reviseStudent (arrayList) Break;} case 4: {oneStudent (arrayList); break;} case 5: {checkStudent (arrayList); break } case 6: {System.out.println ("exit successful"); System.exit (0);} default: {System.out.println ("input error, enter a number between 0 and 6") Break;}} catch (Exception e) {e.printStackTrace (); System.out.println ("your input is not a number, please enter a number from 0 to 6") Main login password authentication: public static void password () {System.out.println ("* Welcome to the student management system *"); Scanner sc=new Scanner (System.in); System.out.print ("Please enter administrator password:"); String s = "keystroke"; int sum=3 While (true) {String ss=sc.nextLine (); if (ss.equals (s)) {System.out.println ("Verification successful!") ; break;} else {sum--; System.out.print ("wrong password, you still have a" + sum+ "chance:");} if (sum==0) {System.out.println ("enter the upper limit, goodbye!") ; System.exit (0);} / / password verification print menu: public static void menu () {System.out.println ("- Welcome to the student management system -"); System.out.println ("1. Increase the number of students; System.out.println ("2. Delete students "); System.out.println (" 3. Modify the student "); System.out.println (" 4. Find students "); System.out.println (" 5. View all students "); System.out.println (" 6. System.out.println ("Please select:");} / / print menu page to add student information: public static void addStudent (ArrayList arrayList) {Scanner sc1=new Scanner (System.in); System.out.print ("Please enter name:"); String name=sc1.nextLine (); System.out.print ("Please enter age:"); String age=sc1.nextLine () System.out.print ("Please enter gender:"); String sex=sc1.nextLine (); System.out.print ("Please enter your student number:"); String number=sc1.nextLine (); System.out.print ("Please enter your class:"); String classroom=sc1.nextLine (); Student stu=new Student (); stu.setAge (age); stu.setClassroom (classroom) Stu.setName (name); stu.setSex (sex); stu.setNumber (number); the student ID used by int kong=0;// to define whether it already exists or not: for (int itemo / s.getNumber (). Equals (number)) & & (s.getClassroom (). Equals (classroom)) {System.out.println ("failed to add, the student number you entered already exists in the same class") Add an arrayList.remove (stu);}} if (name.length ()) = = 0 | | age.length () = = 0 | | sex.length () = = 0 | | classroom.length () = = 0 | | number.length () = = 0 | | kongqiang0) {System.out.println ("failed to add an item that is empty or the student number already exists in the same class"); arrayList.remove (stu) / / remove this item} else {arrayList.add (stu); System.out.println ("added successfully");}} / / add information to view student information: public static void checkStudent (ArrayList array) {if (array.isEmpty ()) {System.out.println ("there is no information here, please check it after adding!") ;} else {System.out.println (array);}} / / check the information to delete the student information: public static void deleteStudent (ArrayList array) {if (array.isEmpty ()) {System.out.println ("there is no information here, please add it and do the operation!") ;} else {Scanner sc=new Scanner (System.in); System.out.println ("Please enter the name of the message you want to delete"); String str=sc.nextLine (); int sum=0; for (int iSuppli

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report