java父类子类代码
import java.util.Scanner;
import java.util.*;
class PersonF
{
public void print(String ID,String Workcard,String name,char fig,int age,String pro)
{
System.out.printf("%s %s %s %c %d %s ",ID,Workcard,name,fig,age,pro);
}
}
class Student extends PersonF
{
public void print1(int score1,int score2,int score3)
{
System.out.printf("%d %d %d",score1,score2,score3);
}
}
class teacher extends PersonF
{
public void print2(String kk,int time)
{
System.out.printf("%s %d",kk,time);
}
}
public class Main {
public static void main(String[] args)
{
PersonSon p=new Student();
PersonSon p1=new teacher();
Student s=new Student();
teacher t=new teacher();
Scanner AI=new Scanner(System.in);
String ID;String Workcard;String name;char fig;int age;String pro;
int score1;int score2;int score3;
String kk;int time;
int count;
while(AI.hasNext())
{
count=AI.nextInt();
if(count==1)
{
//System.out.print(count);
ID=AI.next();
//System.out.print(ID);
Workcard=AI.next();
//System.out.print(Workcard);
name=AI.next();
//System.out.print(name);
fig=AI.next().charAt(0);
//System.out.print(fig);
age=AI.nextInt();
//System.out.print(age);
pro=AI.next();
//System.out.print(pro);
score1=AI.nextInt();
score2=AI.nextInt();
score3=AI.nextInt();
System.out.printf("Student:");
s.print(ID, Workcard, name, fig, age, pro);
s.print1(score1, score2, score3);
System.out.println();
}
if(count==2)
{
ID=AI.next();
Workcard=AI.next();
name=AI.next();
fig=AI.next().charAt(0);
age=AI.nextInt();
pro=AI.next();
kk=AI.next();
time=AI.nextInt();
System.out.printf("Teacher:");
t.print(ID, Workcard, name, fig, age, pro);
t.print2(kk, time);
System.out.println();
}
}
}
}