package hwk4;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
import
public class Owner implements Serializable {
/**
13
* 序列化ID
14
*/
private static final long serialVersionUID = -5809782578272943999L;
protected String ownerName;// 车主
protected int tele;// 联系方式
protected String ID;// 身份证号
protected String license;// 行驶证号
protected boolean policyOfInsurance;// 是否有保险单
protected boolean invoice;// 是否有发票
protected String sellExplain;// 卖车说明
public Owner() {
}// 构造空函数
public Owner(String ownerName, int tele, String iD, String license,
boolean policyOfInsurance, boolean invoice, String sellExplain) {
super();
this.ownerName = ownerName;
this.tele = tele;
ID = iD;
this.license = license;
this.policyOfInsurance = policyOfInsurance;
this.invoice = invoice;
this.sellExplain = sellExplain;
}
@Override
public String toString() {
return "Owner [ownerName=" + ownerName + ", tele=" + tele + ", ID="
+ ID + ", license=" + license + ", policyOfInsurance="
+ policyOfInsurance + ", invoice=" + invoice + ", sellExplain="
+ sellExplain + "]"+"\n";
}
Scanner sca = new Scanner(System.in);
// 查询车主信息
public ArrayList<Owner> SearchOwner(ArrayList<Owner> ownerList) {
Iterator<Owner> it = ownerList.iterator();// 创建一个ownerList集合对应的迭代器
ArrayList<Owner> downer = new ArrayList<Owner>();
System.out.println("请输入车主姓名::");
String str = sca.next();
while (it.hasNext()) {
Owner sowner = (Owner) it.next();
if (sowner.ownerName.endsWith(str)) {
downer.add(sowner);// 把符合条件的车辆放入一个dcar 集合中
}
}
return downer;
}
// 删除车主信息
public ArrayList<Owner> DeleteOwner(ArrayList<Owner> ownerList) {
Iterator<Owner> it = ownerList.iterator();// 创建一个 ownerList集合对应的迭代器
ArrayList<Owner> downer = new ArrayList<Owner>();
System.out.println("请输入您需要删除的车主姓名:");
String str = sca.next();
while (it.hasNext()) {
Owner mowner = (Owner) it.next();
if (mowner.ownerName.endsWith(str)) {
downer.add(mowner);// 把符合删除条件的车辆放入一个mowner 集合中
}
}
return downer;
}
// 修改车主信息
public Owner ModifyOwner(ArrayList<Owner> ownerList) {
Owner owner = new Owner();
System.out.println("您需要修改第几条信息:");
int mn = sca.nextInt();
for (int i = 0; i < ownerList.size(); i++) {
if (i + 1 == mn) {
ownerList.remove(i);
}
}
System.out.println("请按以下顺序输入您需要修改的信息:");
System.out
.println("--车主姓名--联系方式--身份证号--行驶证号--是否有保险单true OR false--是否有发票true OR false--买车说明--");
String s = sca.next();
owner.ownerName = s;
int i1 = sca.nextInt();
owner.tele = i1;
String s1 = sca.next();
owner.ID = s1;
String s2 = sca.next();
owner.license = s2;
boolean b1 = sca.hasNext();
owner.policyOfInsurance = b1;
boolean b2 = sca.hasNext();
owner.invoice = b2;
String s4 = sca.next();
owner.sellExplain = s4;
return owner;
}
// 增加车主信息
public ArrayList<Owner> AddOwner(ArrayList<Owner> ownerList) {
Owner owner = new Owner();
System.out.println("请输入您需要增加的个数:");
int dn = sca.nextInt();
System.out.println("请按以下顺序输入您需要添加的信息:");
System.out
.println("--车主姓名--联系方式--身份证号--行驶证号--是否有保险单true OR false--是否有发票true OR false--买车说明--");
for (int i = 0; i < dn; i++) {
String s = sca.next();
owner.ownerName = s;
int i1 = sca.nextInt();
owner.tele = i1;
String s1 = sca.next();
owner.ID = s1;
String s2 = sca.next();
owner.license = s2;
boolean b1 = sca.hasNext();
owner.policyOfInsurance = b1;
boolean b2 = sca.hasNext();
owner.invoice = b2;
String s4 = sca.next();
owner.sellExplain = s4;
ownerList.add(owner);
}
return ownerList;
}
//添加get和set方法
public String getOwnerName() {
return ownerName;
}
public int getTele() {
return tele;
}
public String getID() {
return ID;
}
public String getLicense() {
return license;
}
public boolean isPolicyOfInsurance() {
return policyOfInsurance;
}
public boolean isInvoice() {
return invoice;
}
public String getSellExplain() {
return sellExplain;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
public void setTele(int tele) {
this.tele = tele;
}
public void setID(String iD) {
ID = iD;
}
public void setLicense(String license) {
this.license = license;
}
public void setPolicyOfInsurance(boolean policyOfInsurance) {
this.policyOfInsurance = policyOfInsurance;
}
public void setInvoice(boolean invoice) {
this.invoice = invoice;
}
public void setSellExplain(String sellExplain) {
this.sellExplain = sellExplain;
}
}