每日代码系列(17)
1 interface Achievement { 2 public abstract float average(); 3 } 4 class Person { 5 String name; 6 int age; 7 public Person(String newName,int newAge) { 8 name=newName; 9 age=newAge; 10 } 11 public void introduce() { 12 System.out.println("你好,我是"+name+",今年"+age+"岁"); 13 } 14 } 15 class Student extends Person implements Achievement { 16 int chinese,math,english; 17 public Student(String newName,int newAge) { 18 super(newName,newAge); 19 } 20 public void setScore(int c,int m,int e) { 21 chinese=c; 22 math=m; 23 english=e; 24 } 25 public float average() { 26 return (chinese+math+english)/3; 27 } 28 } 29 class C3_2 { 30 public static void main(String[] args) { 31 Student s1=new Student("张三",16); 32 s1.introduce(); 33 s1.setScore(80,90,80); 34 System.out.println("平均分: "+s1.average()); 35 } 36 }
补上周六欠的。