我們需要完成的任務?題目如下圖所示:


需要達到的要求:

第一步:在Customer類里面實現(xiàn)Comparble接口并重寫Compareto方法?實現(xiàn)根據(jù)姓氏名字的首字母來進行升序排序。
public class Customer implements Comparable{
private String firstName;
private String LastName;
private Account account;
private ArrayListarrayList;
public Customer(String firstName, String lastName) {
this.firstName = firstName;
LastName = lastName;
arrayList=new ArrayList<>(10);
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return LastName;
}
public void setAccount(Account account) {
this.account = account;
}
public Account getAccount() {
return account;
}
public void addAccount(Account account)
{
arrayList.add(account);
}
public Account getAccount(int i)
{
return arrayList.get(i);
}
public int getNumOfAccounts()
{
return arrayList.size();
}
//重寫compareto方法 根據(jù)姓氏首字母排序
@Override
public int compareTo(Customer o) {
if (this.LastName.charAt(0) 在Bank類里面實現(xiàn)sort方法
public void sortCustomers()
{
//如果是一次性初始化了一個很大的數(shù)組 那么一定要限制排序的范圍 否則會報空指針錯誤
Arrays.sort(customer,0,numOfCustomers);
}接著實現(xiàn)搜索方法:
我這里是根據(jù)姓氏和名字來查找?然后返回具體信息?不過這個題目后來沒有要求進行測試?可以忽略這個方法。
public void searchCustomers()
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter the firstname");
String first=sc.next();
System.out.println("Please enter the lastname");
String last=sc.next();
for (int i=0;i最后直接運行Testbanking類?結果如下?符合我們的題目要求
運行結果:?

你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
文章題目:java--bank項目6排序和搜索客戶-創(chuàng)新互聯(lián)
本文鏈接:http://www.chinadenli.net/article10/degdgo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設、域名注冊、ChatGPT、微信小程序、網(wǎng)站改版、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容