//利用容器来储存操作学生信息
import java.util.*;
public class Student{
public static void main(String[]args){
LinkedList<StuInf> inf=new LinkedList<StuInf>();
sel(inf);
}
public static void sel(LinkedList<StuInf> list1 ){
System.out.println("请选择操作:");
System.out.println("1.添加:");
System.out.println("2.删除:");
System.out.println("3.更改:");
System.out.println("4.查找");
System.out.println("5.退出");
Scanner in=new Scanner(System.in);
int i= in.nextInt();
switch(i)
{
case 1:// 添加学生
System.out.println("请依次输入学生的姓名,学号,班级,语文成绩,数学成绩,英语成绩");
StuInf s= stuAdd();
list1.add(s);
Iterator<StuInf> it1=list1.iterator();
while(it1.hasNext())
{ StuInf sIt=(StuInf)it1.next();
System.out.println(sIt.getInf());
System.out.println(sIt.getRes());
}
sel(list1);
break;
case 2://删除
System.out.println("请输入要删除学生的姓名");
Del(list1);
Iterator<StuInf> it2=list1.iterator();
while(it2.hasNext())
{ StuInf sIt=(StuInf)it2.next();
System.out.println(sIt.getInf());
System.out.println(sIt.getRes());
}
sel(list1);
break;
case 3://更改
System.out.println("请输入要更改学生的姓名");
Update(list1);
Iterator<StuInf> it3=list1.iterator();
while(it3.hasNext())
{ StuInf sIt=(StuInf)it3.next();
System.out.println(sIt.getInf());
System.out.println(sIt.getRes());
}
sel(list1);
break;
case 4:
System.out.println("请输入要查询学生的学号");
Search(list1);
case 5:
break;
default:
System.out.println("选择失败,请重新选择");
break;
}
}
public static void Del(LinkedList<StuInf> list2){//先查找角标,依据角标进行删除操作
Scanner del=new Scanner(System.in);
String Dname= del.nextLine();
try{
int index1=-1;
Iterator<StuInf> it=list2.iterator();
while(it.hasNext())
{ StuInf sIt=it.next();
if(sIt.getName().equals(Dname)){
index1=list2.indexOf(sIt);
}
}
list2.remove(index1);
}catch(IndexOutOfBoundsException e){
System.out.println("删除错误");
}
}
public static void Update(LinkedList<StuInf> list3){
Scanner up=new Scanner(System.in);
String Uname= up.nextLine();
try{
int index2=-1;
Iterator<StuInf> it=list3.iterator();
while(it.hasNext())
{ StuInf sIt=it.next();
if(sIt.getName().equals(Uname)){
index2=list3.indexOf(sIt);
}
}
StuInf StuTest=list3.get(index2);
System.out.println("该学生的原信息为");
System.out.println(StuTest.getInf());
System.out.println(StuTest.getRes());
StuTest.updateInf();
}catch(IndexOutOfBoundsException e){
System.out.println("未找到相关学生信息");
}
}
public static void Search(LinkedList<StuInf> list4){
Scanner sear=new Scanner(System.in);
String Sid= sear.nextLine();
try{
int index3=-1;
Iterator<StuInf> it=list4.iterator();
while(it.hasNext())
{ StuInf sIt=it.next();
if(sIt.getId().equals(Sid)){
index3=list4.indexOf(sIt);
}
}
StuInf StuTest=list4.get(index3);
System.out.println("所查找的学生的信息为");
System.out.println(StuTest.getInf());
System.out.println(StuTest.getRes());
}catch(IndexOutOfBoundsException e){
System.out.println("未找到相关学生信息");
}
}
public static StuInf stuAdd(){
Scanner in1=new Scanner(System.in);
String _name=in1.nextLine();
Scanner in2=new Scanner(System.in);
String _id= in2.nextLine();
Scanner in3=new Scanner(System.in);
String _classes=in3.nextLine();
Scanner in4=new Scanner(System.in);
String _chinese=in4.nextLine();
Scanner in5=new Scanner(System.in);
String _maths=in5.nextLine();
Scanner in6=new Scanner(System.in);
String _english=in6.nextLine();
StuInf stu=new StuInf(_name,_id,_classes,_chinese,_maths,_english);
return stu;
}
}
class StuInf{
private String name;
private String id;
private String classes;
private String chinese;
private String maths;
private String english;
StuInf(String name,String id,String classes, String chinese,String maths,String english)
{
this.name=name;
this.id=id;
this.classes=classes;
this.chinese=chinese;
this.maths=maths;
this.english=english;
}
public String getInf(){
return "|---学生姓名为"+name+",学生学号为"+id+",学生班级为"+classes;
}
public String getRes(){
return "|---语文成绩为"+chinese+",数学成绩为"+maths+",英语成绩为"+english;
}
public String getName(){
return name;
}
public String getId(){
return id;
}
public void updateInf(){
System.out.println("重新输入语文成绩");
Scanner in7=new Scanner(System.in);
chinese=in7.nextLine();
System.out.println("重新输入数学成绩");
import java.util.*;
public class Student{
public static void main(String[]args){
LinkedList<StuInf> inf=new LinkedList<StuInf>();
sel(inf);
}
public static void sel(LinkedList<StuInf> list1 ){
System.out.println("请选择操作:");
System.out.println("1.添加:");
System.out.println("2.删除:");
System.out.println("3.更改:");
System.out.println("4.查找");
System.out.println("5.退出");
Scanner in=new Scanner(System.in);
int i= in.nextInt();
switch(i)
{
case 1:// 添加学生
System.out.println("请依次输入学生的姓名,学号,班级,语文成绩,数学成绩,英语成绩");
StuInf s= stuAdd();
list1.add(s);
Iterator<StuInf> it1=list1.iterator();
while(it1.hasNext())
{ StuInf sIt=(StuInf)it1.next();
System.out.println(sIt.getInf());
System.out.println(sIt.getRes());
}
sel(list1);
break;
case 2://删除
System.out.println("请输入要删除学生的姓名");
Del(list1);
Iterator<StuInf> it2=list1.iterator();
while(it2.hasNext())
{ StuInf sIt=(StuInf)it2.next();
System.out.println(sIt.getInf());
System.out.println(sIt.getRes());
}
sel(list1);
break;
case 3://更改
System.out.println("请输入要更改学生的姓名");
Update(list1);
Iterator<StuInf> it3=list1.iterator();
while(it3.hasNext())
{ StuInf sIt=(StuInf)it3.next();
System.out.println(sIt.getInf());
System.out.println(sIt.getRes());
}
sel(list1);
break;
case 4:
System.out.println("请输入要查询学生的学号");
Search(list1);
case 5:
break;
default:
System.out.println("选择失败,请重新选择");
break;
}
}
public static void Del(LinkedList<StuInf> list2){//先查找角标,依据角标进行删除操作
Scanner del=new Scanner(System.in);
String Dname= del.nextLine();
try{
int index1=-1;
Iterator<StuInf> it=list2.iterator();
while(it.hasNext())
{ StuInf sIt=it.next();
if(sIt.getName().equals(Dname)){
index1=list2.indexOf(sIt);
}
}
list2.remove(index1);
}catch(IndexOutOfBoundsException e){
System.out.println("删除错误");
}
}
public static void Update(LinkedList<StuInf> list3){
Scanner up=new Scanner(System.in);
String Uname= up.nextLine();
try{
int index2=-1;
Iterator<StuInf> it=list3.iterator();
while(it.hasNext())
{ StuInf sIt=it.next();
if(sIt.getName().equals(Uname)){
index2=list3.indexOf(sIt);
}
}
StuInf StuTest=list3.get(index2);
System.out.println("该学生的原信息为");
System.out.println(StuTest.getInf());
System.out.println(StuTest.getRes());
StuTest.updateInf();
}catch(IndexOutOfBoundsException e){
System.out.println("未找到相关学生信息");
}
}
public static void Search(LinkedList<StuInf> list4){
Scanner sear=new Scanner(System.in);
String Sid= sear.nextLine();
try{
int index3=-1;
Iterator<StuInf> it=list4.iterator();
while(it.hasNext())
{ StuInf sIt=it.next();
if(sIt.getId().equals(Sid)){
index3=list4.indexOf(sIt);
}
}
StuInf StuTest=list4.get(index3);
System.out.println("所查找的学生的信息为");
System.out.println(StuTest.getInf());
System.out.println(StuTest.getRes());
}catch(IndexOutOfBoundsException e){
System.out.println("未找到相关学生信息");
}
}
public static StuInf stuAdd(){
Scanner in1=new Scanner(System.in);
String _name=in1.nextLine();
Scanner in2=new Scanner(System.in);
String _id= in2.nextLine();
Scanner in3=new Scanner(System.in);
String _classes=in3.nextLine();
Scanner in4=new Scanner(System.in);
String _chinese=in4.nextLine();
Scanner in5=new Scanner(System.in);
String _maths=in5.nextLine();
Scanner in6=new Scanner(System.in);
String _english=in6.nextLine();
StuInf stu=new StuInf(_name,_id,_classes,_chinese,_maths,_english);
return stu;
}
}
class StuInf{
private String name;
private String id;
private String classes;
private String chinese;
private String maths;
private String english;
StuInf(String name,String id,String classes, String chinese,String maths,String english)
{
this.name=name;
this.id=id;
this.classes=classes;
this.chinese=chinese;
this.maths=maths;
this.english=english;
}
public String getInf(){
return "|---学生姓名为"+name+",学生学号为"+id+",学生班级为"+classes;
}
public String getRes(){
return "|---语文成绩为"+chinese+",数学成绩为"+maths+",英语成绩为"+english;
}
public String getName(){
return name;
}
public String getId(){
return id;
}
public void updateInf(){
System.out.println("重新输入语文成绩");
Scanner in7=new Scanner(System.in);
chinese=in7.nextLine();
System.out.println("重新输入数学成绩");