Java using arrays to implement a simple student management system

Source: Internet
Author: User

Storing the object in an array, and then iterating through the array, plus the operation of some arrays, is simple, purely recorded

Import Java.util.Scanner;


public class Studentmanagertwice {
public static void Main (string[] args) {
Student1 stu = new Student1 ("AAA", 12,1201);
Student1 STU2 = new Student1 ("BBB", 34,1202);
Student1 stu3 = new Student1 ("CCC", 14,1203);
Student1 stu4 = new Student1 ("ddd", 16,1204);
Student1 stu5 = new Student1 ("Eee", 11,1204);

student1[] Stus = new STUDENT1[5];

Stus[0] = stu;
STUS[1] = STU2;
STUS[2] = STU3;
STUS[3] = Stu4;
STUS[4] = Stu5;

String answer = "";
Scanner input = new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("-----welcomecome to the Students manager System-----");
do {

System.out.println ("1.look all 2.query stunum");
System.out.println ("3.exit 4.without");
int choice = Input.nextint ();
Switch (choice) {
Case 1:
for (int i = 0; i < stus.length; i++) {
System.out.println (Stus[i]);
}
Break
Case 2:
SYSTEM.OUT.PRINTLN ("Please input a stunum:");
int num = Input.nextint ();
for (int i = 0; i < stus.length; i++) {
Student1 s = stus[i];
if (num = = S.getstunum ()) {
System.out.println (s);
Break It ended the cycle early with a break and improved efficiency, but
}
}
Break
Case 3:
System.exit (0);
Break
Default
Break
}
System.out.println ("Continue? <y/n> ");
Answer = Input.next ();
} while (Answer.equals ("Y"));


}

}



Class student1{
private String name;
private int age;
private int stunum;
Public Student1 () {
Super ();
TODO auto-generated Constructor stub
}
Public Student1 (String name, int age, int stunum) {
Super ();
THIS.name = name;
This.age = age;
This.stunum = Stunum;
}
@Override
Public String toString () {
Return "Studetn [name=" + name + ", age=" + Age + ", stunum=" + stunum
+ "]";
}
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
public int getage () {
return age;
}
public void Setage (int.) {
This.age = age;
}
public int Getstunum () {
return stunum;
}
public void Setstunum (int stunum) {
This.stunum = Stunum;
}


}

Java using arrays to implement a simple student management system

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.