java Implementation of Simple Student Information Management System Code Example
- 2021-07-24 11:02:44
- OfStack
java Realizes Simple Student Information Management System (No Interface)
Student entity:
package com.edu.imau.wcy;
public class Stu {
private String stuNum;// Student number
private String name;// Name
private String gender;// Gender
private int age;// Age
private int score;// Fraction
public Stu() {
super();
}
public String getStuNum() {
return stuNum;
}
public void setStuNum(String stuNum) {
this.stuNum = stuNum;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Main method:
package com.edu.imau.wcy;
import java.util.*;
public class Main {
static Stu[] Stu=new Stu[100];// Defines an array of students with a capacity of 100
static int number=0;
static Scanner scanner=new Scanner(System.in);
public static void main(String args[]){
int choice;
System.out.println(" This is 1 Student information management system, the maximum capacity is 100 Welcome to use this system ");
while(true){
System.out.println("1. Information addition ");
System.out.println("2. Information viewing ");
System.out.println("3. Information modification ");
System.out.println("4. Message deletion ");
System.out.println("5. Information is sorted according to grades from low to high ");
System.out.println("6. Information query ");
System.out.println("7. Quit ");
System.out.println(" Please enter the action you want to do ");
choice=scanner.nextInt();
if(choice==7)break;
switch(choice){
case 1: add(); break;// Add Student Information
case 2: show();break;// Query student information
case 3: change();break;// Modify student information
case 4: delete();break;// Delete student information
case 5: paixu();break;// Sort student information
case 6: query();break;// Query student information
}
}
System.out.println(" Thank you for your use of this system, and welcome to continue to use it next time ");
}
static void add(){// Add Student Information
while(true){
System.out.println(" Click any key to continue adding student information and stop adding input 0");
if(scanner.nextInt()==0)break;
System.out.println(" Please enter the student's student number, name, gender, age and grade ");
Stu[number]=new Stu();
Stu[number].setStuNum(scanner.next());
Stu[number].setName(scanner.next());
Stu[number].setGender(scanner.next());
Stu[number].setAge(scanner.nextInt());
Stu[number].setScore(scanner.nextInt());
number++;
System.out.println(" Successful addition ");
}
}
static void show(){// Display student information
System.out.println("*******************************************");
System.out.println(" Student number Name Gender Age Achievement ");
for(int i=0;i<number;i++)
System.out.println(Stu[i].getStuNum()+"\t"+Stu[i].getName()+"\t"+"\t"+Stu[i].getGender()+"\t"+Stu[i].getAge()+"\t"+Stu[i].getScore());
System.out.println("*******************************************");
System.out.println();
}
static void paixu(){// Sort student information
int j;
Stu temp=new Stu();
for(int i=0;i<number;i++)
{
for(j=i+1;j<number;j++)
if(Stu[i].getScore()>Stu[j].getScore())
{temp=Stu[i];Stu[i]=Stu[j];Stu[j]=temp;}
}
System.out.println(" After sorting is completed, select "Student Information View" to view ");
}
static void change(){// Change student information
System.out.println(" Please enter the student number of the student to modify the information ");
String Stunumber=scanner.next();
for(int i=0;i<number;i++)
{
if(Stunumber.equals(Stu[i].getStuNum()))
{System.out.println(" Please enter the information of the student you want to modify , Student number, name, sex, age, score ");
Stu[i].setStuNum(scanner.next());
Stu[i].setName(scanner.next());
Stu[i].setGender(scanner.next());
Stu[i].setAge(scanner.nextInt());
Stu[i].setScore(scanner.nextInt());
break;
}
if(number==i)System.out.println(" Sorry, there is no such person ");
}
}
static void query(){// Query
System.out.println(" Please enter the student number to query ");
String Stunumber=scanner.next();
int i;
for(i=0;i<number;i++)
{
if(Stunumber.equals(Stu[i].getStuNum())){
System.out.println("*******************************************");
System.out.println(" Student number Name Gender Age Achievement ");
System.out.println(Stu[i].getStuNum()+"\t"+Stu[i].getName()+"\t"+"\t"+Stu[i].getGender()+"\t"+Stu[i].getAge()+"\t"+Stu[i].getScore());
System.out.println("*******************************************");
}
}
if(number==i)System.out.println(" Sorry, there is no such person ");
}
static void delete(){// Delete student information
System.out.println(" Please enter the student number for which you want to delete the information ");
String Stunumber=scanner.next();
int i;
for( i=0;i<number;i++)
if(Stunumber.equals(Stu[i].getStuNum()))break;
if(number==i)System.out.println(" Sorry, there is no such person ");
for(;i<number-1;i++)
Stu[i]=Stu[i+1];
number--;
System.out.println(" Delete complete ");
}
}