用虚线分割的是三个类,写的很清楚,跪求大神帮帮忙!
package javaoopch5.training1;
public class Student {
private int id;
private String name;
private String sex;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Student() {
super();
}
public Student(int id, String name, String sex) {
super();
this.id = id;
this.name = name;
this.sex = sex;
}
}
----------------------------------------------------------------
package javaoopch5.training1;
import java.util.ArrayList;
import java.util.List;
public class StuMar {
private List list=new ArrayList();
public void AddStudent(Student s){
list.add(s);
}
public void showAll(){
System.out.println("学号\t姓名\t性别");
for(int i=0;i<list.size();i++){
Student s=(Student) list.get(i);
System.out.println(s.getId()+"\t"+s.getName()+"\t"+s.getSex());
}
}
}
--------------------------------------------------------------------------------------------
package javaoopch5.training1;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
String choose2;
int id = 0;
String name = null;
String sex = null;
do{
System.out.println("欢迎使用学生管理系统");
System.out.println("请选择:1.添加学生 2.查询学生 3.删除学生\n");
Scanner sc=new Scanner(System.in);
int input =sc.nextInt();
if(input==1)
{
System.out.println("请输入学生的学号\n");
id=sc.nextInt();
System.out.println("请输入学生的姓名\n");
name =sc.next();
System.out.println("请输入学生的性别\n");
sex=sc.next();
}else
{
System.out.println("选择其他");
}
System.out.println("是否继续(y/n)");
choose2=sc.next();
}while(choose2.equals("y"));
Student stu=new Student( id, name,sex);
StuMar stum=new StuMar();
stum.AddStudent(stu);
stum.showAll();
}
}
IT僧
慕瓜9220888
相关分类