设计个Person类,包含几个字段:姓名,年龄,身份证号。 一个学生Student类,继承Person类。Student类还包含新的字段(学号,语文成绩,数学成绩,英语成绩)和获取平均成绩和总成绩两个方法。
裁判测试程序样例:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 读入一些信息
String name = sc.next();
String ID = sc.next();
int age = sc.nextInt();
// 测试Person类
Person p = new Person(name, ID, age);
p.show();
System.out.println("============================");
// 继续读入一些信息
String stuID = sc.next();
int chinese = sc.nextInt();
int math = sc.nextInt();
int english = sc.nextInt();
sc.close();
// 测试Student类
Student stu = new Student(p, stuID, chinese, math, english);
stu.show();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 读入一些信息
String name = sc.next();
String ID = sc.next();
int age = sc.nextInt();
// 测试Person类
Person p = new Person(name, ID, age);
p.show();
System.out.println("============================");
// 继续读入一些信息
String stuID = sc.next();
int chinese = sc.nextInt();
int math = sc.nextInt();
int english = sc.nextInt();
sc.close();
// 测试Student类
Student stu = new Student(p, stuID, chinese, math, english);
stu.show();
}
}
输入样例:
在这里给出一组输入。例如:
张三 422456202009094356 19 20201001 98 97 94
输出样例:
在这里给出相应的输出。例如:
姓名:张三
ID:422456202009094356
年龄:19
============================
姓名:张三
ID:422456202009094356
年龄:19
学号:20201001
总成绩:289
语文成绩:98
数学成绩: 97
英语成绩:94
平均成绩:96
class Person {
String name;
String ID;
int age;
public Person(String name,String ID,int age) {
this.age=age;
this.ID=ID;
this.name=name;
}
public Person() {//
}
public void show() {
System.out.println("姓名:"+name+"nID:"+ID+"n年龄:"+age);
}
}
class Student extends Person {
String name;
String ID;
int age;
String stuID;
int chinese;
int math;
int english;
public Student(Person p, String stuID,int chinese,int math,int english) {
this.name=p.name;
this.age=p.age;
this.ID=p.ID;
this.stuID=stuID;
this.chinese=chinese;
this.math=math;
this.english=english;
}
public void show() {
System.out.println("姓名:"+name+"nID:"+ID+"n年龄:"+age);
System.out.println("学号:"+stuID);
sum();
System.out.println("语文成绩:"+chinese+ "n数学成绩: "+math+ "n英语成绩:"+english);
avg();
}
void sum() {
int sum11;
sum11=(chinese+math+english);
System.out.println("总成绩:"+sum11);
}
void avg() {
int avg1;
avg1=(chinese+math+english)/3;
System.out.println("平均成绩:"+avg1);
}
}
有没有别的方法??求解



