private String memberName
private int memberNo
public Customer(String memberName,int memberNo){
this.memberName = memberName
this.memberNo = memberNo
}
public String getMemberName() {
return memberName
}
public void setMemberName(String memberName) {
this.memberName = memberName
}
public int getMemberNo() {
return memberNo
}
public void setMemberNo(int memberNo) {
this.memberNo = memberNo
}
}
----------------------------------分界线---------------------------------------------------
import java.util.ArrayList
public class CustManager {
private static ArrayList<Customer>list = new ArrayList<Customer>()
public void addCust(String memberName,int memberNo){
list.add(new Customer(memberName, memberNo))
}
public int searchMemberByName(String memberName){
if(memberName == null || memberName.equals("")){
return 1
}
for(Customer c : list){
if(memberName.equals(c.getMemberName())){
return c.getMemberNo()
}
}
return 0
}
}
----------------------------------分界线姿野---------------------------------------------------
public class Test {
public static void main(String[] args) {
CustManager custManager = new CustManager()
custManager.addCust("张三", 1)
custManager.addCust("李迹散喊四", 2)
custManager.addCust("王五", 3)
custManager.addCust("马六", 4)
System.out.println(custManager.searchMemberByName("马六掘搏"))
}
}
1:D2:A
3:B
4:A
5:B
6:A
7:B
8:D
9:C
10:D
11:B
12:D
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)