Java fundamentals: Student Management systems

Source: Internet
Author: User
Tags chr

Package com.lovo.manager;

Import java.util.Scanner;

/**
* Student Management
*
* @author Longing for Life
*
*/
public class Studentmanager {

public static void main (string[] Args) {
string[] user = new string[10];
int[] Password = new int[10];
While (true) {
Menu
System.out.println ("A registration");
System.out.println ("B login");
System.out.println ("C exit");

System.out.println ("please Select menu:");

        Scanner scan = new Scanner (system.in);
        String operator = Scan.nextline ();
        operator = Operator.touppercase ();/////"sfcds" to a One's ' s ', ' F ', ' C ', ' D ', ' s '
        char[] chr = Operator.tochararray ();//convert string to char array

        switch (chr[0]) {
        case ' A ':
        & nbsp    register (user, password);
             break;
        case ' B ':
             login (user, password);
             break;
        case ' C ':
             SYSTEM.OUT.PRINTLN ("exit the system! ");
             system.exit (-1);
             break;
        default:
             SYSTEM.OUT.PRINTLN ("operation error, Please enter the new! ");
             break;
         }
     }
}

/**
* Login
*/
public static void login (string[] user, int[] password) {

System.out.println ("enter User name:");
Scanner input = new Scanner (system.in);
String userName = Input.nextline ();

System.out.println ("enter password:");
int pwd = Input.nextint ();

int index =-1;
for (int i = 0; i < user.length; i++) {
If (username.equals (user[i]) && pwd = = password[i]) {//if username and password match
System.out.println ("login successful!");
Studentmenu (userName);
index = i;
Break
}
}
If (index = =-1) {//if no subscript is found, the login fails
System.out.println ("login failed! ");
Return
}
}

/**
* Registration
*/
public static void Register (string[] user, int[] password) {

System.out.println ("please Enter User name");
Scanner scan = new Scanner (system.in);
String userName = Scan.nextline ();

System.out.println ("please Enter password");
int pwd = Scan.nextint ();
The default data in the string is null, the loop is checked, and once NULL is encountered,
Enter the user name and password to assign the Value.
for (int i = 0; i < user.length; i++) {
if (user[i] = = Null) {
user[i] = userName;
password[i] = pwd;
Break
}
}
}

/**
* Student Menu
*/
public static void Studentmenu (String User) {
Student name and score
string[] studentname = new string[2];
int[] score = new int[2];
Boolean flag = false;
While (true) {

System.out.println ("* * * welcome" + user + "* * *");

System.out.println ("A New Student score");
System.out.println ("B to revise student performance");
System.out.println ("C Delete Student results");
System.out.println ("D to check student results");
System.out.println ("E-return to Parent menu");

System.out.println ("please Select menu:");
Scanner input = new Scanner (system.in);
String operator = Input.nextline ();

operator = Operator.touppercase ();
Char op = Operator.tochararray () [0];

Switch (OP) {
Case ' A ':
Addinfo (studentname, score);
Break
Case ' B ':
UpdateInfo (studentname, score);
Break
Case ' C ':
Deleteinfo (studentname, score);
Break
Case ' D ':
QueryInfo (studentname, score);
Break
Case ' E ':
Flag = true;
Break;//exit This switch, if you do not add more than one break in the while, the loop will continue and will not return to the top level menu
Default
System.out.println ("operation error, Please new input! ");
Break
}
If (flag) {
Break;//exits This while, it returns to the login menu
}
}
}

/**
* New Student Information
*
* @param studentname
* @param score
*/
public static void Addinfo (string[] studentname, int[] score) {

for (int i = 0; i < studentname.length; i++) {
System.out.println ("please Enter Student's name:");
Scanner scan = new Scanner (system.in);
String stname = Scan.nextline ();
studentname[i] = stname;

System.out.println ("please Enter student score:");
int scr = Scan.nextint ();

score[i] = scr;
}
}

/**
* Change Student's Name
*/
public static void UpdateInfo (string[] studentname, int[] score) {
System.out.println ("please Enter Student's name:");
Scanner scan = new Scanner (system.in);
String stname = Scan.nextline ();
Modify fractions by name
int index =-1;
for (int i = 0; i < score.length; i++) {//through traversal, the number of inputs compared to the data elements in the array
If (stname.equals (studentname[i])) {//if the Student's name is found, record the subscript
index = i;
}
}
Enter a score
System.out.println ("please Enter student score:");
int scr = Scan.nextint ();

score[index] = scr;//assigns The result of the input, the index record to find the subscript
}

/**
* Delete employee data
*/
public static void Deleteinfo (string[] studentname, int[] score) {
      & Nbsp;//delete a Person's name, delete a score
      System.out.println ("please enter Student's name:");
      Scanner scan = new Scanner (system.in);
      String stname = Scan.nextline ();
      Boolean flag = false;
      for (int i = 0; i < studentname.length; i++) {

      if (studentname.length-1 = = I) {//current subscript is last, exit loop
          STUD entname[i] = null;
          score[i] = 0;
          break;
     }
      if (stname.equals (studentname[i]) | | Flag) {//if This name is found, move forward with the next element of the current array element to replace the current element
          flag = true;
          studentname[i] = studentname[i + 1];
          score[i] = score[i + 1];
     }
     }
      for (int i = 0; i < studentname.length; i++) {
            Sy STEM.OUT.PRINTLN ("student name =" + studentname[i] + ", score =" + score[i]);
     }
}

/**
* Check Student Information
*/
public static void QueryInfo (string[] studentname, int[] score) {
Boolean flag = false;
While (true) {

System.out.println ("a query for individual student information");
System.out.println ("B query all student information");
System.out.println ("C return to parent menu");

System.out.println ("please Select menu:");
Scanner scan = new Scanner (system.in);
String operator = Scan.nextline ();
operator = Operator.touppercase ();//case to case

char chr = Operator.tochararray () [0];
Switch (chr) {
Case ' A ':
Querysinglstudentinfo (studentname, score);
Break
Case ' B ':
Queryallstudentinfo (studentname, score);
Break
Case ' C ':
Flag = true;
Break
Default
System.out.println ("operation error, Please new input! ");
Break
}
If (flag) {
Break
}
}

}

/**
* Query individual student Information
*/
public static void Querysinglstudentinfo (string[] studentname, int[] score) {
System.out.println ("please Enter Student's name:");
Scanner scan = new Scanner (system.in);
String stname = Scan.nextline ();

for (int i = 0; i < studentname.length; i++) {
If (stname.equals (studentname[i])) {
System.out.println ("student:" + studentname[i] + ", score:" + score[i]);
Break
}
}
}

/**
* Check all student information
*/
public static void Queryallstudentinfo (string[] studentname, int[] score) {
for (int i = 0; i < studentname.length; i++) {
System.out.println ("student:" + studentname[i] + ", score:" + score[i]);
}
}
}

Java fundamentals: Student Management systems

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.