配列とオブジェクトを使用したJava学生情報管理システム



Java Student Information Management System Using Arrays



package array job public class Student { String stuName,stuSex int stuAge,stuSno } package array job public class opreate { Student[] students = new Student[100]//Create an array of student objects Student stu = new Student() int index=0 //main menu public void menu() { System.out.println('Simple Student Management System') System.out.println('1. Add student information') System.out.println('2. Modify student information according to student number') System.out.println('3. View all student information') System.out.println('4. View information about a student based on student ID') System.out.println('5. View all students of the same gender according to gender') System.out.println('6. Delete a student based on student ID') System.out.println('7. Sort in ascending order by student number') System.out.println('8. Sort in descending order according to age') System.out.println('9. Exit') System.out.println('Please enter your choice:') } //Add students public boolean addstu(Student stu) { // for(int i = 0i package array job import java.util.Scanner public class test { public static void main(String[] args) { // TODO Auto-generated method stub opreate stuOp = new opreate() Scanner input = new Scanner(System.in) while(true) { stuOp.menu() int answer = input.nextInt() switch(answer){ case 1 : for(int i=0i<2i++) { System.out.println('Please enter name') String name = input.next() System.out.println('Please enter the age') int age = input.nextInt() System.out.println('Please enter gender') String sex = input.next() System.out.println('Please enter the student number') int sno = input.nextInt() //Save the input variables into the Student object Student stu = new Student() //Assign values ​​to the properties of objects stu.stuName= name stu.stuAge = age stu.stuSex = sex stu.stuSno = sno //Call the add method to add the student object to the array boolean boo = stuOp.addstu(stu) if(boo) { System.out.println('Successfully added') } } stuOp.menu() break case 2 : System.out.println('Please enter the student number') int no = input.nextInt() //Find the student object to be modified according to the student number Student stu= stuOp.queryStudentById(no) if(stu!=null) { System.out.print('Please enter a new name:') String name = input.next() System.out.print('Please enter a new age:') int age = input.nextInt() System.out.print('Please enter a new gender:') String sex = input.next() //Reset the value of the stu object stu.stuName=name stu.stuAge=age stu.stuSex=sex //Call the modification method to modify boolean booo = stuOp.updateStudentById(stu) if(booo) { System.out.println('Successfully modified') System.out.println(stu.stuAge+' '+stu.stuName+' '+stu.stuSex+' '+stu.stuSex) }else { System.out.println('Modify failed') } } stuOp.menu() break case 3: stuOp.show() stuOp.menu() break case 4: System.out.println('Please enter the student number') int newsno = input.nextInt() Student stu1 = stuOp.queryStudentById(newsno) if(stu1!=null) { System.out.println(stu1.stuAge+stu1.stuName+stu1.stuSex+stu1.stuSno) }else { System.out.println('The student does not exist') } stuOp.menu() break case 5: System.out.print('Please enter gender:') String sex = input.next() stuOp.queryStudentBySex(sex) stuOp.show() stuOp.menu() break case 6: System.out.println('Please enter the student number') int nsno = input.nextInt() boolean boo = stuOp.deletStudentById(nsno) if(boo) { System.out.println('Successfully deleted') stuOp.show() }else { System.out.println('Deletion failed') } stuOp.menu() break case 7: System.out.println('Arranged in descending order by student number') stuOp.studentByIdDesc() stuOp.show() stuOp.menu() break case 8: System.out.println('Arranged in descending order of age') stuOp.studentByAgeDesc() stuOp.show() stuOp.menu() break case 9 : System.out.println('Thank you for using') stuOp.menu() break default: System.out.println('The code you entered is incorrect, please re-enter') stuOp.menu() break } } } }