Description
定义一个Student类描述学生,学生信息有:身份证号、学号、姓名、性别、年龄和成绩。再定义一个Teacher类描述教师,教师信息有:身份证号、教师号、姓名、性别、年龄和职务。
(表示字符串用String类的对象表示,如:
String name;
name=reader.next();//不要使用reader.nextLine()
)
Input
首先是一个整数n,表示有n组数据,其后是每一组数据。
每组数据第1个数是一个整型数,1表示学生,2表示教师,其后分别是身份证号、学号/教师号、姓名、性别、年龄和成绩/职位。
Output
学生或教师的信息。
Sample Input
2
2 2301 0401 Wangli 35 f vice-pro
1 1031 1504 Zhangyi 18 m 89.5
Sample Output
Teacher:2301 0401 Wangli 35 f vice-pro
Student3:1031 1504 Zhangyi 18 m 89.5
我的代码
import java.util.*;
public class Main {
private static Scanner reader;
public static void main(String args[]){
reader = new Scanner(System.in);
int old,chengji;
String name;
String sex;
String id;
String xuehao;
String chengji1;
int t=reader.nextInt();
while(t>0)
{ t--;
int n=reader.nextInt();
if(n==1)
{
id=reader.next();
xuehao=reader.next();
name=reader.next();
old=reader.nextInt();
sex=reader.next();
chengji=reader.nextInt();
student s=new student();
s.setall(id,xuehao,name,old,sex,chengji);
System.out.printf("Student:"+s.getid()+" "+s.getxuehao()+" "+name+" "+s.getold()+" "+sex+" "+s.getchengji());
System.out.printf("\n");
}
if(n==2)
{
id=reader.next();
xuehao=reader.next();
name=reader.next();
old=reader.nextInt();
sex=reader.next();
chengji1=reader.next();
teacher ss=new teacher();
ss.setall(id,xuehao,name,old,sex,chengji1);
System.out.printf("Teacher:"+ss.getid()+" "+ss.getxuehao()+" "+name+" "+ss.getold()+" "+sex+" "+ss.getchengji());
System.out.printf("\n");
}
}
}
}
class student
{
int old,chengji;
String name;
String id;
String xuehao;
String sex;
void setall(String i,String x,String n,int o,String s,int c)
{
id=i;
xuehao=x;
old=o;
chengji=c;
name=n;
sex=s;
}
String getid()
{
return id;
}
String getxuehao()
{
return xuehao;
}
int getold()
{
return old;
}
int getchengji()
{
return chengji;
}
String getname()
{
return name;
}
String getsex()
{
return sex;
}
}
class teacher
{
int old;
String name;
String sex;
String chengji;
String id;
String xuehao;
void setall(String i,String x,String n,int o,String s,String c)
{
id=i;
xuehao=x;
old=o;
chengji=c;
name=n;
sex=s;
}
String getid()
{
return id;
}
String getxuehao()
{
return xuehao;
}
int getold()
{
return old;
}
String getchengji()
{
return chengji;
}
String getname()
{
return name;
}
String getsex()
{
return sex;
}
}
676548736484165813
相关分类