JAVA初学:实现设备的增删改查
创建设备类
在这次的类中 设置了四个信息:名称 类型 版本 制造商
```java
package TestOne;
import java.util.Objects;
public class DeviceInfo {
String id;
String deviceType;
String version;
String manufacturer;
public DeviceInfo() {
}
public DeviceInfo(String id, String deviceType, String version, String manufacturer) {
this.id = id;
this.deviceType = deviceType;
this.version = version;
this.manufacturer = manufacturer;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
@Override
public String toString() {
return "【 设备的名字:"+id+"\t"+"设备的类型:"+deviceType+"\t"+"设备的版本:"+version+"\t"+"设备的制造商:"+manufacturer+" 】\t";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DeviceInfo that = (DeviceInfo) o;
return Objects.equals(id, that.id) && Objects.equals(deviceType, that.deviceType) && Objects.equals(version, that.version) && Objects.equals(manufacturer, that.manufacturer);
}
@Override
public int hashCode() {
return Objects.hash(id, deviceType, version, manufacturer);
}
}
编写主程序
package TestOne;
import java.util.ArrayList;
import java.util.Scanner;
public class DeviceManage {
public static void main(String[] args) {
ArrayList<DeviceInfo> deviceManage=new ArrayList<>();
while(true){
System.out.println("欢迎您的访问");
System.out.println("---------------------");
System.out.println(