学校要进行年终总结,需要对教师和学生的评分结果进行统计。学生的统计数据有三个,教师的统计数据有四个。请你实现一个统计系统,对输入的数据进行整理。
请你实现一个Person类表示人员,并实现一些必要的方法,再实现Teacher类和Student类,通过类的继承机制完成这个任务。
输入格式:
首先输入一个数字N,表示输入统计的人数。
接下来是N行,每行是用空格隔开的一系列数字。
输出格式:
N行,每行是一个标识符加一个平均得分(向下取整的整数),用空格隔开。
学生的标识符是Student,教师的标识符是Teacher。
输入样例:
2
2 3 4
2 3 4 5
输出样例:
Student 3
Teacher 3
import java.util.Scanner;
class Person
{
double x,y,z;
Person(double x,double y,double z)
{
this.x=x;
this.y=y;
this.z=z;
}
}
class Triangle extends Person
{
double e;
Triangle(double x, double y,double z,double z2) {
super(x, y,z);
this.e=z2;
}
int show()
{
return ((int)(x+y+z+e)/4);
}
}
class Rectangle extends Person
{
Rectangle(double x, double y,double z) {
super(x, y, z);
}
int show()
{
return (int)((x+y+z)/3);
}
}
public class Main
{
public static void main(String[] args)
{
double n,x,y,z,e;
Scanner cin=new Scanner(System.in);
n=cin.nextInt();
int []na=new int[(int)n];
for(int i=1;i<=n;i++)
{
if(i%2!=0)
{
x=cin.nextInt();
y=cin.nextInt();
z=cin.nextInt();
Rectangle re=new Rectangle(x, y, z);
na[i-1]=re.show();
}
else
{
x=cin.nextInt();
y=cin.nextInt();
z=cin.nextInt();
e=cin.nextInt();
Triangle th=new Triangle(x, y, z, e);
na[i-1]=th.show();
}
}
for(int i=0;i<n;i++)
{
if(i%2==0)
System.out.println("Student "+na[i]);
else
System.out.println("Teacher "+na[i]);
}
}
}
```![图片说明](https://img-ask.csdn.net/upload/201704/22/1492828409_748852.png)