Import? Java . io . *;
Class? StuMgr{
Public? Static electricity Class? Students {
Public? int? id;
Public? String? Name;
Public? int? Age;
Public? Student (int? id? , string? Name, int? Age) (
This. id? =? id;
This name? =? Name;
This. Age? =? Age;
}
@ Overlay
Public? String? toString(){
Return? id? +? ","? +? Name? +? ","? +? Age;
}
}
Public? List & lt students & gt? stuList? =? New? LinkedList & lt& gt();
Public? Invalid? add(){
Scanner? sc? =? New? Scanner (system. in); ?
System.out.println ("Please enter your student number:");
String? id? =? sc . nextline();
int? intId? =? 0;
Try {
intId? =? integer . parse int(id);
}catch(NumberFormatException? For example) {
System.out.println ("The student number is entered incorrectly, please enter a number!" );
Return;
}
What if? (find(intId)? ! =? null){
System.out.println ("This student number already exists!" );
Return? ;
}
System.out.println ("Please enter student name:");
String? Name? =? sc . nextline();
System.out.println ("Please enter student age:");
String? Age? =? sc . nextline();
int? intAge? =? 0;
Try {
intAge? =? Integer.parseInt (age);
}catch(NumberFormatException? For example) {
System.out.println ("Age input is wrong, please enter a number!" );
Return;
}
Student? Stu? =? New? Student (intId, name, intage);
stu list . add(stu);
store();
system . out . println("-");
System.out.println ("student information has been increased");
system . out . println(stu);
system . out . println("-");
}
Public? Invalid? del(){
Scanner? sc? =? New? Scanner (system. in); ?
System.out.println ("Please enter your student number:");
String? id? =? sc . nextline();
int? intId? =? 0;
Try {
intId? =? integer . parse int(id);
}catch(NumberFormatException? For example) {
System.out.println ("The student number is entered incorrectly, please enter a number!" );
Return;
}
Student? Stu? =? find(intId);
What if? (? Stu? ==? null){
System.out.println ("This student number does not exist!" );
Return? ;
}
stu list . remove(stu);
store();
system . out . println("-");
System.out.println ("student information has been deleted");
system . out . println(stu);
system . out . println("-");
}
Public? Invalid? find(){
Scanner? sc? =? New? Scanner (system. in); ?
System.out.println ("Please enter your student number:");
String? id? =? sc . nextline();
int? intId? =? 0;
Try {
intId? =? integer . parse int(id);
}catch(NumberFormatException? For example) {
System.out.println ("The student number is entered incorrectly, please enter a number!" );
Return;
}
Student? Stu? =? find(intId);
What if? (? Stu? ==? null){
System.out.println ("This student number does not exist!" );
Return? ;
}
system . out . println("-");
System.out.println ("Find student information as follows");
system . out . println(stu);
system . out . println("-");
}
Public? Student? find(int? id){
For (students? Stu? :? stuList){
If (stu.id? ==? id){
Return? Stu;
}
}
Return? null
}
Public? Invalid? modify(){
store();
}
Public? Invalid? foreach(){
system . out . println("-");
For (students? Stu? :? stuList){
system . out . println(stu);
}
system . out . println("-");
}
Public? Invalid? store(){
Iterator? Iterator? =? stu list . iterator();
Documents? Documents? =? New? file(" stu list . txt ");
FileWriter? fw? =? null
BufferedWriter? A writer? =? null
Try it? {
fw? =? New? FileWriter (file)
A writer? =? New? buffered writer(fw);
while(iterator.hasNext()){
writer.write(iterator.next()。 toString());
writer . newline(); //newline
}
writer . flush();
}? Catch? (FileNotFoundException? e)? {
e . printstacktrace();
} catch? (IOException? e)? {
e . printstacktrace();
} Finally {
Try it? {
writer . close();
fw . close();
}? Catch? (IOException? e)? {
e . printstacktrace();
}
}
}
Public? Static electricity Invalid? main(String[]? args){
StuMgr? Manager? =? New? stu mgr();
while(true){
System.out.println ("Please select the operation to be performed:");
System.out.println(" 1: add student information ");
System.out.println("2: delete student information ");
System.out.println("3: find student information ");
System.out.println("4: modify student information ");
System.out.println("5: traverse student information ");
system . out . println(" 6:exit ");
system . out . println("-");
Scanner? sc? =? New? Scanner (system. in); ?
String? op? =? sc . nextline();
if("6 "。 Equal to (op)){) (
Return;
}
if(" 1 "。 Equal to (op)){) (
mgr . add();
}
if("2 "。 Equal to (op)){) (
mgr . del();
}
if("3 "。 Equal to (op)){) (
mgr . find();
}
if("4 "。 Equal to (op)){) (
mgr . modify();
}
if("5 "。 Equal to (op)){) (
mgr . foreach();
}
}
}
Time is pressing, and there is still a modify method that has not been implemented, leaving it to everyone to practice.