Java集合框架,Arraylist处理对象

Java集合框架,Arraylist处理对象,java,arraylist,collections,Java,Arraylist,Collections,下面是开始的分支类: package com.sherzod; import java.util.ArrayList; public class Branch { private String branchName; private ArrayList<Customer> customer; public Branch(String branchName) { this.branchName = branchName; t

下面是开始的分支类:

package com.sherzod;

import java.util.ArrayList;

public class Branch {
    private String branchName;
    private ArrayList<Customer> customer;

    public Branch(String branchName) {
        this.branchName = branchName;
        this.customer = new ArrayList<>();
    }

    public String getBranchName() {
        return branchName;
    }

    public ArrayList<Customer> getCustomer() {
        return customer;
    }

    **public Customer findCustomer(String name){
        for (int i=0; i<this.customer.size(); i++){
            Customer checkedCustomer = this.customer.get(i);
            if(checkedCustomer.equals(name)){
                return checkedCustomer;
            }
        }
        return null;
    }**
}
package com.sherzod;
导入java.util.ArrayList;
公营部门{
私有字符串分支名称;
私人ArrayList客户;
公共分支(字符串分支名称){
this.branchName=branchName;
this.customer=new ArrayList();
}
公共字符串getBranchName(){
返回分支名称;
}
公共阵列列表getCustomer(){
退货客户;
}
**公共客户findCustomer(字符串名称){

对于(int i=0;i对于包中的java类,不需要导入同一包中的其他公共类。 i、 e.
Customer
类不需要在
Branch
类中导入(因为两者都是
com.sherzod
的一部分),而
ArrayList
java.util
包的一部分

用于:


继承是一个不同的主题。关系b/w分支和客户类是因为它们在同一个包中,它们不需要父子关系

问题是我们为什么要创建返回(作为布尔值)类型“客户”的方法对象?-你能重新表述一下你想问什么吗?很难理解你的问题是什么。我的意思是,通常如果我们想返回一些东西,我们会这样做:“public(int,double,String等)methodName(){}”对吗?但在分支类中,我编写了一个类似“public Customer findCustomer()”的方法findCustomer正在返回一个对象?这部分我不明白..然后呢?你的问题是什么?你想让你的方法返回
布尔值
?或者..?请阐述这个问题。你能解释一下我们从哪里得到这个“findCustomer”方法吗?返回数据类型是什么?返回
公共客户findCustomer的类型吗(字符串名称)
Customer
,您显然可以看到这一点。我不知道您是从哪里获得此方法的。
package com.sherzod;

import java.util.ArrayList;

public class Customer {
    private String customerName;
    private ArrayList<Double> transactions;

    public Customer(String customerName) {
        this.customerName = customerName;
        this.transactions = new ArrayList<>();
    }

    public String getCustomerName() {
        return customerName;
    }

    public ArrayList<Double> getTransactions() {
        return transactions;
    }

    public void addTransaction(double amount){
        transactions.add(amount);
    }
}
even if I didn't extend Customer class from Branches still code works, no errors.