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();
}
}
如何实现将动态输入的数据存储至一个学生类数组?
各位高手些帮帮忙啊````` 展开
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();
}
}
如何实现将动态输入的数据存储至一个学生类数组?
各位高手些帮帮忙啊````` 展开
3个回答
展开全部
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();
}
}
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();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上的代码应该没什么问题。至少思路可以是这样的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
上面的代码,你试了吗?
行不行啊?
行不行啊?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询