Java数组存取名字,题⽬:⽤java定义⼀个student数组,其中
保存学⽣的姓名、学号。。。
2009-10-06 回答
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.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) {
}
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{
/**
java定义一维数组并赋值* 采⽤控制台动态输⼊数据
*/
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("学⽣学号:");
adLine();
if(s1.length()==0)
break;
System.out.println("学⽣姓名:");
adLine();
if(s2.length()==0)
break;
System.out.println("学⽣性别:");
adLine();
if(s3.length()==0)
break;
System.out.println("学⽣年龄:");
adLine();
if(s4.length()==0)
break;
System.out.println("学⽣所在班级:");
adLine();
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);
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();
}
}
追问:
你编译出来没啊
我怎么编译不出来啊

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。