JAVA中将控制台动态输入的一组学生数据存储到数组student中怎么实现

学生类publicclassStudent{publicintid;publicStringname;publicbooleangender;publicintage;p... 学生类

public class Student {
public int id;
public String name;
public boolean gender;
public int age;
public String classteam;
public Student(int id,String name,boolean gender,int age,String classteam){

this.id = id;
this.name = name;
this.gender = gender;
this.age = age;
this.classteam = classteam;
}

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 boolean isGender() {
return gender;
}
public void setGender(boolean gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getClassteam() {
return classteam;
}
public void setClassteam(String classteam) {
this.classteam = classteam;
}
}
学生管理类实现动态数据的输入并存储至文本文档
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class StudentManager {

private final static int MAX_SIZE = 10;
private int length;

public StudentManager(){
length = 0;
}

public void display() throws IOException{
/**
* 采用控制台动态输入数据
*/
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\学生情况.txt"));

String s1,s2,s3,s4,s5;
while(length < MAX_SIZE)
{
System.out.println("学生学号:");
s1=br.readLine();
if(s1.length()==0)
break;
System.out.println("学生姓名:");
s2=br.readLine();
if(s2.length()==0)
break;
System.out.println("学生性别:");
s3=br.readLine();
if(s3.length()==0)
break;
System.out.println("学生年龄:");
s4=br.readLine();
if(s4.length()==0)
break;
System.out.println("学生所在班级:");
s5=br.readLine();
if(s5.length()==0)
break;

bw.write(s1);
bw.write(" ");
bw.write(s2);
bw.write(" ");
bw.write(s3);
bw.write(" ");
bw.write(s4);
bw.write(" ");
bw.write(s5);

bw.newLine();//产生新行
length++;
}
bw.close();
}

}
如何实现将动态输入的数据存储至一个学生类数组?
各位高手些帮帮忙啊`````
展开
 我来答
从乐然M0
推荐于2016-04-01 · TA获得超过134个赞
知道答主
回答量:258
采纳率:0%
帮助的人:107万
展开全部
public class Student {
public int id;
public String name;
public String gender;
public int age;
public String classteam;
public Student(int id,String name,String gender,int age,String classteam){

this.id = id;
this.name = name;
this.gender = gender;
this.age = age;
this.classteam = classteam;
}

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 isGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getClassteam() {
return classteam;
}
public void setClassteam(String classteam) {
this.classteam = classteam;
}

public String toString()
{
return "id="+id+",name="+name+",sex="+gender+",age="+age+",class="+classteam;
}
}
*************************************
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class StudentManager {

private final static int MAX_SIZE = 10;
private int length;

public StudentManager(){
length = 0;
}

public void display() throws IOException{
/**
* 采用控制台动态输入数据
*/
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\学生情况.txt"));
Student[] stu=new Student[10];
String s1,s2,s3,s4,s5;
while(length < MAX_SIZE)
{
System.out.println("学生学号:");
s1=br.readLine();
if(s1.length()==0)
break;
System.out.println("学生姓名:");
s2=br.readLine();
if(s2.length()==0)
break;
System.out.println("学生性别:");
s3=br.readLine();
if(s3.length()==0)
break;
System.out.println("学生年龄:");
s4=br.readLine();
if(s4.length()==0)
break;
System.out.println("学生所在班级:");
s5=br.readLine();
if(s5.length()==0)
break;

bw.write(s1);
bw.write(" ");
bw.write(s2);
bw.write(" ");
bw.write(s3);
bw.write(" ");
bw.write(s4);
bw.write(" ");
bw.write(s5);
int mid=Integer.parseInt(s1);
int mage=Integer.parseInt(s4);
stu[length]=new Student(mid,s2,s3,mage,s5);

bw.newLine();//产生新行
length++;
}
bw.close();
for(int i=0;i<10;i++)
System.out.println(stu[i]);
}

}
**********************************
class test
{
public static void main(String [] args) throws Exception
{
StudentManager SM=new StudentManager();
SM.display();

}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
loverzhouwei
2009-04-26
知道答主
回答量:41
采纳率:0%
帮助的人:20.3万
展开全部
楼上的代码应该没什么问题。至少思路可以是这样的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友a46867888
2009-04-25
知道答主
回答量:65
采纳率:0%
帮助的人:28.1万
展开全部
上面的代码,你试了吗?
行不行啊?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式