(求助)JAVA编写类与类的测试程序2

来源:百度知道 编辑:UC知道 时间:2024/05/15 15:31:23
编写一个设备类Device,该类拥有:
成员变量:
protected String dName //设备的名称
protected String address //出厂厂家
protected double price //价格
构造器方法:
Device(String dName,String address) //用于初始化设备名称与出厂厂家
Device(String dName,String address,double price) //用于初始化设备名称,出厂厂家和价格
成员方法:
public String toString() //用于返回设备的设备名称,出厂厂家和各家各户信息

public class Device {
protected String dName; //设备的名称
protected String address; //出厂厂家
protected double price; //价格
public Device(String _dName,String _address){//用于初始化设备名称与出厂厂家
this.dName = _dName;
this.address = _address;
}
public Device(String _dName,String _address,double _price){//用于初始化设备名称,出厂厂家和价格
this.dName = _dName;
this.address = _address;
this.price = _price;
}
public String toString(){
return dName+address+price;
}

public static void main(String[] args) {
Device d1 = new Device("设备1","北京");
System.out.println(d1.toString());
Device d2 = new Device("设备2","南京",100D);
System.out.println(d2.toString());
}

}

public class Device
{
protected String dName //设备的名称
protected String address //出厂厂家
protected double price //价格
Device(Strin