Student Status Management System (Java Primary Edition)

Source: Internet
Author: User

import java.util.scanner;/** *  Student Management System  *  @author  Tanker *  @version  4.6.0 */ public class XueJiSystem {    //Java  Access Public  static void main (String[] args)  {    Scanner sc=new  Scanner (system.in);  //console input System.out.println ("Welcome to the Student management system!"); for (;;) {System.out.println ("Please enter  1.) Add student Information   2. Query   3. Modify name   4. Delete   5. exit"); int  num=sc.nextint ();  //receives user input if (num==1) {student s=new student ();//Instantiate a Student object// Assign values to students ' attributes System.out.println ("Please enter student number:"); S.setsid (Sc.nextint ()); System.out.println ("Please enter student's name:"); S.setname (Sc.next ()); System.out.println ("Please enter Student Age:"); S.setage (Sc.nextint ()); System.out.println ("Please enter student address:"); S.setadd (Sc.next ());//Call Add method, and put the student object inside, return whether to add a successful flag boolean flag= Studentoperator.addstudent (s);//Depending on the mark, determine whether to add success if (flag) {System.out.println ("Add success! ");} Else{system.out.println ("Add failed! ");}} else if (num==2) {System.out.println ("Please enter student number:"), Int sid=sc.nextint ();//Check student information according to input number student s= Studentoperator.selectstudent (sid+ ""); if (s==null) {System.out.println ("The student information does not exist!") ");} Else{system.out.println (S.tostring ());////tostring  is a default method}}else if (num==3) {System.out.println (" Please enter the student number to change the name: "); Int sid=sc.nextint ();//based on the student ID entered. Query Student Information student s=studentoperator.selectstudent (sid+ "");//If Student information exists if (s!=null) {System.out.println ("Please set a new name:" ); String newname=sc.next ();//The method is called, and the number, student name, modified name into the inside, return to add a successful mark boolean flag= Studentoperator.updatestudent (Sid,s.getname (), newName);//Determine if the modification succeeds if (flag) {SYSTEM.OUT.PRINTLN ("modified successfully! ");} Else{system.out.println ("Modify failed! ");} If the student information does not exist}ELSE{SYSTEM.OUT.PRINTLN ("The student information does not exist!") please add ");}} Else if (num==4) {System.out.println ("Please enter student number to delete:"); Int sid=sc.nextint ();//based on the student ID entered. Query Student Information student s=studentoperator.selectstudent (sid+ ""); if (s!=null) {//Find student information then pass the number into the Delete method and return whether to delete the successful flag Boolean  flag=studentoperator.deletestudent (SID);//Determine if success is removed if (flag) {System.out.println ("Delete succeeded! ");} Else{system.out.println ("Delete failed! ");}} Else{system.out.println ("The student information does not exist!") ");}} Else if (num==5) {System.out.println ("The system has exited! "); break;} ELSE{SYSTEM.OUT.PRINTLN ("Wrong input! Please re-lose ");}}         }}//Student Class Public class student {private int  sid;//  number private string name;//  name private int age;//  age private  string add;//  Home Address Public int getsid ()  {return sid;} Public void setsid (Int sid)  {this.sid = sid;} 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 getadd ()  {return add;} Public void setadd (String add)  {this.add = add;} Show query results   Each class has ToStringMethod @overridepublic string tostring ()  {return  "student [sid="  + sid +   ",  name="  + name +  ",  age="  + age +  ",  add="  + add +  "]";}} Control class, around the array expansion and deletion to search four methods public class studentoperator {static student stu[]=new  student[10];//used to store student objects//Query method Public static student selectstudent (string sid) {Student s =null;//defines a student class variable s  defined as NULL//traversal array for (int i=0;i<stu.length;i++) {//If the array element is not empty if (stu[i]!=null) {// Determines whether the SID of this element is equal to the external incoming SID if (Stu[i].getsid () ==integer.parseint (SID)) {s=stu[i];//assigns the element to s}}}return s;//if it is equal Return Student Class s}//add student Information public static boolean addstudent (student s) {//define an int type variable index with a value of-1, Used to tag array subscript int index=-1;//to iterate through an array, to find a vacancy for the student to be added for (int i=1;i<stu.length;i++) {if (stu[i]==null) {index=i;// Assign the subscript to index and stop the loop break if there is a vacancy;}} Add if (index==-1) {return false; //location filled with add failure by judging the value of the index subscript}else{stu[index]=s; //object students into array return true;  //add successful}}//delete public static boolean deletestudent (INT&NBSP;SID) {//Defines a Boolean type of variable flag  initialized to falseboolean flag=false;//traversal array for (int i=0;i<stu.length;i++) {// if (stu[i]!=null) {//If the array is not empty (Stu[i].getsid () ==sid) {/////If the array element is empty (assigned value is empty) {stu[i]=null;//exists) ;//flag changed to True while terminating loop break;}}} return flag; //returns a Boolean value flag}//modify information public static boolean updatestudent (INT&NBSP;SID, String field,string newvalue) {//defines a Boolean type of variable flag  initialized to falseboolean flag=false;//traversal array for (int  i=0;i<stu.length;i++) {//When the array is not empty if (stu[i]!=null) {//////Based on an externally passed-in SID to determine if there is an if (Stu[i].getsid () ==sid) {Stu[i] in the array. SetName (newvalue);//exists if the name of the array element is set to the new value Flag=true;//flag changed to True, and the loop break is terminated;}} return flag;//returns a Boolean value of flag}}


Student Status Management System (Java Primary Edition)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.