The Java User Name is used to log on to the student information management system and add, delete, modify, and query the user name.

Source: Internet
Author: User

The Java User Name is used to log on to the student information management system and add, delete, modify, and query the user name.

Package zzzzzzzz; import java. io. *; public class Text {public static void main (String [] args) throws MyException, IOException {Login l = new Login (); l. login () ;}} class Student {private String stunumber; private String name; private String age; private String sex; private String score; public void set_stunumber (String stu) {stunumber = stu;} public String get_stunumber () {return stunumber;} void set_name (String na ){ Name = na;} String get_name () {return name;} void set_age (String agee) {age = agee;} String get_age () {return age ;} void set_sex (String sexx) {sex = sexx;} String get_sex () {return sex;} void set_score (String scoree) {score = scoree;} String get_score () {return score ;}} class StudentManager {int n = 0; Student ss [] = new Student [50]; // traverses the Student information void showStudent () {for (int I = 0; I <= n; I ++) {System. out. println ("student ID:" + ss [I]. get_stunumber () + "Name:" + ss [I]. get_name () + "Age:" + ss [I]. get_age () + "Gender:" + ss [I]. get_sex () + "score:" + ss [I]. get_score () + "\ t \ n") ;}// determines whether the student ID already exists. boolean panduan (String st) {boolean flag = true; for (int I = 0; I <n; I ++) {if (ss [I]. get_stunumber (). equals (st) flag = false; else flag = true;} return flag;} // Add student information void addStudent (String stunumber, String name, String age, String B, string score) {ss [n] = new Student (); ss [n]. set_stunumber (st Unumber); ss [n]. set_name (name); ss [n]. set_age (age); ss [n]. set_sex (B); ss [n]. set_score (score); n ++;} // Delete student information void deleteStudent (String stunumber) throws MyException {for (int I = 0; I <= n; I ++) {if (ss [I]. get_stunumber (). equals (stunumber) {System. out. println ("student ID:" + stunumber + "has been deleted! "); If (n = 1) {System. out. println ("empty array"); ss [0] = new Student ();} else {for (int j = I; j <= n; j ++) {ss [j] = ss [j + 1];} n -- ;}} else {throw new MyException ("this student does not exist! ") ;}}// Modify student information void updateStudent (String stu1, String name, String age, String sex, String score) throws MyException {for (int I = 0; I <= n; I ++) {if (ss [I]. get_stunumber (). equals (stu1) {ss [I] = new Student (); ss [I]. set_stunumber (stu1); ss [I]. set_name (name); ss [I]. set_age (age); ss [I]. set_sex (sex); ss [I]. set_score (score);} else throw new MyException ("This student is not found! ") ;}}// Query student information void selectStudent (String number) throws MyException {for (int I = 0; I <= n; I ++) {if (ss [I]. get_stunumber (). equals (number) {System. out. println ("student ID:" + ss [I]. get_stunumber () + "name:" + ss [I]. get_name () + "Age:" + ss [I]. get_age () + "Gender:" + ss [I]. get_sex () + "score:" + ss [I]. get_score () + "\ t \ n");} else throw new MyException ("This student is not found! ") ;}} // Count the number of failed students void tongji () {int s = 0; for (int I = 0; I <= n; I ++) {int a = Integer. parseInt (ss [I]. get_score (); if (a <= 60) {s = s + 1; System. out. println ("student ID:" + ss [I]. get_stunumber () + "name:" + ss [I]. get_name () + "Age:" + ss [I]. get_age () + "Gender:" + ss [I]. get_sex () + "score:" + ss [I]. get_score () + "\ t \ n") ;}} System. out. println ("failed:" + s + ");} // enter the void showface () {System. out. println ("*****************************"); System. out. println ("Shijiazhuang Iron University student information management System "); System. out. println ("*****************************"); System. out. println ("1. traverse and output the student information "); System. out. println ("2. new student information entry "); System. out. println ("3. delete student information "); System. out. println ("4. modify student information "); System. out. println ("5. querying student information "); System. out. println ("6. student Information Statistics "); System. out. println ("7 quit. ") ;}} class Login {User users = new User (" 001 "," 123456 "); // User name, password // log on to void login () throws MyException, IOException {BufferedRea Der in = new BufferedReader (new InputStreamReader (System. in); DataOutputStream out = new DataOutputStream (new BufferedOutputStream (new FileOutputStream ("Student.txt", true); for (int I = 1; I <= 3; I ++) {System. out. println ("Enter the user id:"); String id = in. readLine (); System. out. println ("enter the password:"); String pass = in. readLine (); if (users. uername. equals (id) & (users. passage. equals (pass) {StudentManager sm = new StudentManager (); While (true) {sm. showface (); System. out. println ("select:"); String choose = in. readLine (); if (choose. startsWith ("1") {sm. showStudent ();} else if (choose. startsWith ("2") {System. out. print ("Enter your student ID:"); String stu = in. readLine (); System. out. print ("Enter name:"); String name = in. readLine (); System. out. print ("Enter age:"); String age = in. readLine (); System. out. println ("Enter gender (true male, false female):"); String sex = in. readLine (); System. out. prin T ("Enter the score:"); String score = in. readLine (); if (sm. panduan (stu) {sm. addStudent (stu, name, age, sex, score); System. out. println ("created successfully! "); Out. writeUTF ("| student ID:" + stu + "| name:" + name + "| age:" + age + "| Gender:" + sex + "| score: "+ score +" | \ t \ n ");} elsethrow new MyException (" this student already exists. Do not add it again ");} else if (choose. startsWith ("3") {System. out. println ("Enter the student ID:"); String stu = in. readLine (); if (! (Sm. panduan (stu) {sm. deleteStudent (stu);} else throw new MyException ("this student ID does not exist! ");} Else if (choose. startsWith ("4") {System. out. println ("Enter the student ID:"); String stu = in. readLine (); System. out. println ("Enter name:"); String name = in. readLine (); System. out. println ("Enter age:"); String age = in. readLine (); System. out. print ("Enter gender (true male, false female):"); String sex = in. readLine (); System. out. print ("Enter the score:"); String score = in. readLine (); if (! (Sm. panduan (stu) {sm. updateStudent (stu, name, age, sex, score); out. writeUTF ("| student ID:" + stu + "| name:" + name + "| age:" + age + "| Gender:" + sex + "| score: "+ score +" | \ t \ n ");} else throw new MyException (" this student ID does not exist! ");} Else if (choose. startsWith ("5") {System. out. println ("Enter the student ID:"); String stu = in. readLine (); if (! (Sm. panduan (stu) {sm. selectStudent (stu);} else throw new MyException ("this student ID does not exist! ");} Else if (choose. startsWith ("6") {sm. tongji ();} else if (choose. startsWith ("7") {in. close (); out. close (); System. exit (0);} else {throw new MyException ("incorrect selection, please reselect") ;}} elseSystem. out. println ("incorrect user ID or password, please enter it again");} throw new MyException ("this card is locked! ") ;}} Class User {String uername; String passage; User (String user, String pass) {this. uername = user; this. passage = pass;} void set_uername (String use) {uername = use;} String get_uername () {return uername;} void set_passage (String pass) {passage = pass ;} string get_passage () {return passage;} class MyException extends Exception {public MyException (String e) {super (e );}}

  

Related Article

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.