Small Practice---Class student management system

Source: Internet
Author: User

Requirements:

The following features are implemented:

① add a class;

② add students to the class;

③ query class, students;

④ Delete class, student;

Analysis:

Object:

① class: Class number, class name, student array;

② Students: School number, name, gender, age;

Completed in MyEclipse: new 4 classes

①student

Package Studentmanagement;public class Student {private string Sno;private string sname;private string ssex;private int SA Ge;public Student () {super ();} Public Student (String sno, String sname, string ssex, int sage) {super (); This.sno = Sno;this.sname = Sname;this.ssex = SSE X;this.sage = Sage;} Public String Getsno () {return sno;} public void Setsno (String sno) {This.sno = sno;} Public String Getsname () {return sname;} public void Setsname (String sname) {this.sname = sname;} Public String Getssex () {return ssex;} public void Setssex (String ssex) {this.ssex = Ssex;} public int getsage () {return sage;} public void setsage (int sage) {this.sage = sage;}}

②class

package Studentmanagement;public class Class {private string Cno;private string Cname;private student[] stus;private int size;private int count=0;public Class () {this.size=10;stus=new Student[ This.size];} Public Class (String cno, string cname, int size) {super (); this.cno = Cno;this.cname = Cname;this.size = Size;stus=new Stu Dent[this.size];} Public String Getcno () {return CNO;} public void Setcno (String cno) {this.cno = CNO;} Public String Getcname () {return CNAME;} public void Setcname (String cname) {this.cname = CNAME;} Public student[] Getstus () {return stus;} public void Setstus (student[] stus) {this.stus = Stus;} public int GetSize () {return size;} public void setSize (int size) {this.size = size;} public int GetCount () {return count;} public void SetCount (int count) {This.count = count;} public void Addstudent (Student stu) {if (count<stus.length) {stus[count]=stu;count++; System.out.println ("Add Student success!");} ELSE{SYSTEM.OUT.PRINTLN ("Class size is full!");}} 

③manageservice

Package Studentmanagement;import Java.util.scanner;public class Manageservice {private class[] classes;private int size ;p rivate int count = 0;public Manageservice () {this.size = 10;classes = new Class[this.size];} public manageservice (int size) {this.size = Size;classes = new Class[this.size];} public void Addclazz (Class c) {if (count<classes.length) {Classes[count] = c;count++; SYSTEM.OUT.PRINTLN ("class added success! ");} ELSE{SYSTEM.OUT.PRINTLN ("Class number reaches the limit, cannot add Class!") ");}} public void Printallclass () {System.out.println ("class number \ t class name"); for (int i=0;i<classes.length;i++) {Class C = classes[ I];if (c!=null) {System.out.println (C.getcno () + "\ T" +c.getcname ());}}} Public Class Getclassbyno (String cno) {Class clazz = null;for (int i=0;i<classes.length;i++) {Class C = classes[i];if (c! =null) {if (C.getcno (). Equals (CNO)) {clazz = c;}} Else{break;}} return clazz;} Public student[] Getstusbyclass (String cno) {student[] Stus = null;for (int i=0;i<classes.length;i++) {Class c = classes [I];if (C!=null) {if (C.getcno (). Equals (CNO)) {Stus= C.getstus ();}} Else{break;}} return stus;} Public Student Getstubyno (String Sno) {Student stu = null;for (int i=0;i<classes.length;i++) {Class c = classes[i];if (c! =null) {student[] Stus = C.getstus (); for (int j=0;j<stus.length;j++) {Student s = stus[j];if (s!=null) {if (S.getsno (). Equals (Sno)) {Stu = s;}} Else{break;}}} Else{break;}} return Stu;} public void Deletestubyno (String sno) {for (int i=0;i<classes.length;i++) {Class c = classes[i];if (C!=null) {student[] Stus = C.getstus (); for (int j=0;j<stus.length;j++) {Student s = stus[j];if (s!=null) {if (S.getsno (). Equals (Sno)) {Stus [j] = null;}} Else{break;}}} Else{break;}}} public void Deleteclassbyno (String cno) {for (int i=0;i<classes.length;i++) {Class c = classes[i];if (C!=null) {if ( C.getcno (). Equals (CNO)) {classes[i]=null;}} Else{break;}}} public void Run () {System.out.println ("Welcome to sue College management system!") "); Scanner sc = new Scanner (system.in), while (true) {System.out.println ("1. Adding classes, 2. Adding students, 3. viewing classes, 4. Viewing students, 5. Deleting a student, 6. Deleting a class, 7. Exit "); String comd = Sc.next (), if (Comd.equals ("1")) {System.out.println ("Please enter class Number:"); String CNO = Sc.next (); Class C = Getclassbyno (CNO), if (c==null) {System.out.println ("Please enter class name, number of people:"); String cname = Sc.next (); int size = Sc.nextint (); c = new Class (CNO, CNAME, size); Addclazz (c);} Else{system.out.println ("Class already exists!") ");}} else if (Comd.equals ("2")) {System.out.println ("Please enter class Number:"); String CNO = Sc.next (); Class C = Getclassbyno (CNO); if (c!=null) {System.out.println ("Please enter the number, name, gender, Age:"); String sno = Sc.next (); String sname = Sc.next (); String ssex = Sc.next (); int sage=sc.nextint (); Student stu = new Student (Sno, sname, Ssex, Sage); C.addstudent (Stu);} ELSE{SYSTEM.OUT.PRINTLN ("class does not exist!") ");}} else if (Comd.equals ("3")) {Printallclass ();} else if (Comd.equals ("4")) {System.out.println ("1. According to Class View, 2. View student's personal details"); String type = Sc.next (), if (Type.equals ("1")) {System.out.println ("Please enter class Number:"); String CNO = Sc.next (); student[] Stus = Getstusbyclass (CNO), if (stus!=null) {System.out.println ("the number \ t name \ t gender \ t age"); for (int j=0;j< stus.length;j++) {Student s = stus[j];if (s!=null) {System.out.prinTLN (S.getsno () + "\ T" +s.getsname () + "\ T" +s.getssex () + "\ T" +s.getsage ());} Else{break;}}} ELSE{SYSTEM.OUT.PRINTLN ("Class does not exist, or there is no student in this class!") ");}} else if (Type.equals ("2")) {System.out.println ("Please enter Number:"); String sno = Sc.next (); Student stu = Getstubyno (SNO), if (stu!=null) {System.out.println ("school number \ t name \ t gender \ t age"); System.out.println (Stu.getsno () + "\ T" +stu.getsname () + "\ T" +stu.getsno () + "\ T" +stu.getsage ());} ELSE{SYSTEM.OUT.PRINTLN ("Student" +sno+ "does not exist!") ");}}} else if (Comd.equals ("5")) {System.out.println ("Please enter Number:"); String sno = Sc.next (); Student stu = Getstubyno (SNO), if (stu!=null) {Deletestubyno (SNO); System.out.println ("Delete succeeded! ");} ELSE{SYSTEM.OUT.PRINTLN ("Student" +sno+ "does not exist!") ");}} else if (Comd.equals ("6")) {System.out.println ("Please Lose Class Number:"); String CNO = Sc.next (); Class C = Getclassbyno (CNO), if (c!=null) {deleteclassbyno (CNO); System.out.println ("Delete succeeded! ");} Else{system.out.println ("Class" +cno+ "does not exist!") ");}} else if (Comd.equals ("7")) {System.out.println ("System exits! "); System.exit (0);} ELSE{SYSTEM.OUT.PRINTLN ("The order is illegal! ");}}}}

④app

Package Studentmanagement;public class App {public static void main (string[] args) {manageservice ss=new Manageservice (5) ; Ss.run ();}}

  

Small Practice---Class 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.