Blink of an eye, the school six weeks later, I also study Java so long. During this National day idle come to nothing, do a small system to play.
-------------Student-----------Package Studentsystem;public class Student extends User{private int stuid;private String Stuname;private string Stubirthday;public int getstuid () {return stuid;} public void Setstuid (int stuid) {this.stuid = Stuid;} Public String Getstuname () {return stuname;} public void Setstuname (String stuname) {this.stuname = Stuname;} Public String Getstubirthday () {return stubirthday;} public void Setstubirthday (String stubirthday) {this.stubirthday = Stubirthday;} @Overridepublic String toString () {return "student [stuid=" + Stuid + ", stuname=" + stuname+ ", stubirthday=" + STUBIRTHD ay + "]";} Public student () {super ();} public student (int stuid,string stuname,string stubirthday) {This.stuid=stuid;this.stuname=stuname;this.stubirthday =stubirthday;}} -------------------Istudentdao Interface--------------------------Package Studentsystem;public interface Istudentdao {/* * New Add Student * */public abstract Boolean Insert (student students);/* * Delete student * */public abstract Boolean Delete (intSTUID) */* * UPDATE Student * */public Abstract boolean update (student students);/* * Find student * */public abstract student Search (int STUID);p ublic abstract Void Show (); ------------------Istudentdao Interface Implementation------------------------------Package Studentsystem;public class Studentdaodemo Implements Studentdao {private student student1[] = new student[100];p ublic void Start () {for (int i=0;i<10;i++) {Stude NT student = new Student (1000+i, "Student" +i, "1995-10-" +i); student1[i] = student;}} @Overridepublic the Boolean insert (student students) {/* to iterate through the array, locate the first empty position */for (int i=0; i<student1.length;i++) {if ( Student1[i] = = null) {System.out.println ("Insert" + (i+1) + "x"); student1[i]=students;break;}} return true;} @Overridepublic boolean Delete (int stuid) {if (search (stuid) = = null) return false; for (int i=0;i<student1.length;i++) {if (Student1[i].getstuid () ==stuid) {int j=i; while (Student1[j+1]!=null) {student1[j]=student1[j+1]; j + +; } student1[j]=null; Empty the last empty element to break; }} return true; @Overridepublic Boolean update (student students) {/* by study number, update data */system.out.println ("Test uodate stuid" +students.gets Tuid ()); if (Search (Students.getstuid ()) = = null) return false;else{for (int i=0;i<student1.length;i++) {if (student1 [I].getstuid () = = Students.getstuid ()) {student1[i] = students; Break;}} return true;}} @SuppressWarnings ("unused") public student Search (int stuid) {student student = null; for (int i=0;i<student1.length; i++) {if (student1[i].getstuid () = = stuid) {student = Student1[i]; Break } return null; }return student;} /* * Output all student information * */public void Show () {int j=0;for (int i=0;i<student1.length;i++) {if (student1[i]!=null) j + +;} System.out.println ("+j+" Student information in the system!) "); for (int i=0;i<j;i++) {String result = student1[i].tostring (); SYSTEM.OUT.PRINTLN (result);}}} ------------------Studentmune-------------------------------package Studentsystem;import Java.util.Scanner; public class Studentmune {privateStudentdaodemo studao;private Scanner input=null;public Studentmune () {super (); This.input = new Scanner (system.in); This.studao = new Studentdaodemo ();} public void Mainmune () {//studao.start (); System.out.println ("= = You are welcome to the student system"); System.out.println ("1, View student Information"); System.out.println ("2, add a student information"); System.out.println ("3, delete a student information"); System.out.println ("4, update a student information"); System.out.println ("5, find a student information"); System.out.println ("6, Exit student System"); System.out.println ("====================="); System.out.println ("Please enter the corresponding number to operate:"); String i = input.next (); switch (i) {case "1": Show (); Break;case "2": Insert (); Break;case "3": Delete (); Break;case "4": UPDA Te (); Break;case "5": Search (), break;case "6": System.exit (0) break;default:system.out.println ("Your input is wrong, please re-enter!") ");} Returnmain ();} /* * Find student information * */public void Search () {System.out.println ("= = Search by study number ==>>"); SYSTEM.OUT.PRINTLN ("Please lose the number to find:"), Student students = Studao.search (Input.nextint ()), if (students!=null) { System.out.println ("Find success! "+students.tosTring ());} else {System.out.println ("Lookup failed! ");} Returnmain ();} /* * Insert a student * */public void Insert () {System.out.println ("Please enter Name:"); String name = Input.next (); System.out.println ("Please enter Stuid:"); int Id = Input.nextint (); System.out.println ("Please enter Stubir:"); String bir = Input.next (); Student students = new Student (Id,name,bir); if (Studao.insert (students)) System.out.println ("Insert succeeded! "); else System.out.println ("Insert failed! "); }/* * Delete a student information * */public void Delete () {System.out.println ("= = = = = Delete=====>>"); SYSTEM.OUT.PRINTLN ("Please lose the study number of the Delete:"), if (Studao.delete (Input.nextint ())) System.out.println ("Delete succeeded! "); ElseSystem.out.println (" Delete failed! "); Returnmain ();} /** * Update a student's information * */public void Update () {System.out.println ("Please enter new information directly update!") "); System.out.println ("Please enter new name:"); String name = Input.next (); System.out.println ("Please enter Stuid:"); int Id = Input.nextint (); System.out.println ("Please enter new Stubir:"); String bir = Input.next (); Student students = new Student (Id,name,bir); if (STUDAO.UPDATE (students)) System.out.println ("Update succeeded! "); else System.out.println ("Update failed! ");} public void Show () {studao.show ();} /* * Press 0 to return to the main menu * */public void Returnmain () {System.out.println ("=================>>"); System.out.println ("Enter 0 to return to main Menu"), int i = Input.nextint (), while (i!=0) {System.out.println ("Enter 0 to return to main Menu"); i = Input.nextint (); if (i==0) Mainmune ();} Mainmune ();}} -------------------System test Function----------------------Package Studentsystem;public class Systemtest {static student Students = new Student ();p ublic static void Main (string[] args) {Studentmune mune = new Studentmune (); Mune.mainmune ();}} System will continue to improve, now only realized the increase, delete, change, check the basic operation!
Java Learning Diary---------Simple Student Information Management system