两道JAVA作业题,求解决啊
Person类
public class Person(){
private String name ;
private String address;
private String phone;
private String email;
//get()和set()自己写了吧~
public String toString(){
return “类名:”+Person.class.getName()+”姓名”+name;
}
}
public class Student extends Person(){
//同上。
}
《Java语言程序设计基础篇》机械工程出版社原书第8版 课后习题答案(包括编程题)Liang,Y.D著
这本书在官方网站上提供偶数题的答案
但是奇数题的答案只能通过寄回书后的回执得到,并且需要加盖学校公章和院系主任签字.
编写程序,提示用户输入学生的个数,每个学生的名字及其分数,最后显示最高分的学生和第二高分的学生
public static void main(String[] args) throws Exception {
Scanner in=new Scanner(System.in);
System.out.println(“请输入学生的个数:”);
int num=in.nextInt();
String names[]=new String [num];//学生姓名数组
double scores[]=new double [num];//学生分数数组
double max=0; //记录最大分数
int index=0; //记录最大分数的下标
for (int i = 0; i num; i++) {
System.out.print(“请输入第”+(i+1)+”个学生的姓名:”);
names[i]=in.next();
System.out.print(“请输入第”+(i+1)+”个学生的分数:”);
scores[i]=in.nextDouble();
if(scores[i]max){
max=scores[i];
index=i;
}
}
System.out.println(“最高分的学生是:”+names[index]+”,分数为:”+scores[index]);
}
java第八章回答接口的问题
//定义具体类AirPlane,继承Machine
//飞机的work() 方法调用时,输出“正在飞行,速度为…”
public class AirPlane extends Machine {
@Override
void work() {
// TODO Auto-generated method stub
System.out.println(“正在飞行,速度为…”);
}
}
//定义一个接口canFly,其中,含有speed()方法,
public interface CanFly {
void speed();
}
//并实现canFly接口,每个飞机有型号、飞行速度,编写构造方法,toString()方法,
public class CanFlyImp implements CanFly {
private String xinghao;
private int sudu;
public CanFlyImp() {
super();
// TODO Auto-generated constructor stub
}
public CanFlyImp(String xinghao, int sudu) {
super();
this.xinghao = xinghao;
this.sudu = sudu;
}
public void speed() {
// TODO Auto-generated method stub
}
@Override
public String toString() {
return “CanFlyImp [xinghao=” + xinghao + “, sudu=” + sudu + “]”;
}
//set get…..
}
//定义一个抽象类Machine,其中含work()方法,
public abstract class Machine {
abstract void work();
}
//创建一个飞机对象测试,执行对象work()方法;
public class Test {
public static void main(String[] args) {
AirPlane ap = new AirPlane();
ap.work();
CanFlyImp canFlyImp = new CanFlyImp(“002”,12 );
System.out.println(canFlyImp);
canFlyImp.speed();
}
}