补充代码,import java.util.Scanner; //接口定义 interface MyListener { public void dispInfo(double dWeidu, double dJingdu); } //抽象类声明 abstract class Location { public double dWeidu; public double dJingdu; public Location(double w, double j) { System.out.println("Father Constructor"); dWeidu=w; dJingdu=j; } abstract public void setLocation(double d, double j);//抽象方法,让子类实现,可以更改成员变量的纬度和经度值 } /* 请在这里填写答案,编写你的类,实现四个方法 */ //===================================== //===================================== public class Main { public static void main(String args[]) { MyLocation obj1=new MyLocation (); obj1.dispInfo(obj1.dWeidu,obj1.dJingdu); obj1.setLocation(33.45678,104.54321); obj1.dispInfo(obj1.dWeidu,obj1.dJingdu); Scanner in = new Scanner(System.in); double a=in.nextDouble(); double b=in.nextDouble(); MyLocation obj2=new MyLocation (a,b); obj2.dispInfo(obj2.dWeidu,obj2.dJingdu); obj2.setLocation(30.12345,104.56789); obj2.dispInfo(obj2.dWeidu,obj2.dJingdu); } }
时间: 2023-06-02 18:05:09 浏览: 105
java代码-import java.util.Scanner;
5星 · 资源好评率100%
//编写自己的Location类,实现四个方法
class MyLocation extends Location implements MyListener {
//构造方法
public MyLocation() {
super(0, 0);
System.out.println("MyLocation Constructor");
}
public MyLocation(double w, double j) {
super(w, j);
System.out.println("MyLocation Constructor with arguments");
}
//实现抽象方法
public void setLocation(double w, double j) {
dWeidu = w;
dJingdu = j;
}
//实现接口方法
public void dispInfo(double w, double j) {
System.out.println("纬度:" + w);
System.out.println("经度:" + j);
}
}
阅读全文