使用递归搜索数组?

yiytaume  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(235)

有人知道如何使用递归来搜索其他数组中的对象数组吗?地毯=文件夹archivos=文件nombre=名称tamaño=尺寸
编辑:为进一步澄清,翻译了几个苏。
本练习的重点是在其他ArrayList中创建ArrayList,模拟计算机中使用的真实文件夹和文件。下面的代码是我到目前为止所做的。救命啊!

public class Carpetas {

private String nombre;
private int tamaño;
ArrayList <Carpetas> Crp;
ArrayList <Archivo> Arc;

public Carpetas(String nombre, int tamaño){
    this.nombre = nombre;
    this.tamaño = tamaño;
    Crp = null;
    Arc = null;
}

public ArrayList<Carpetas> getCrp() {
    return Crp;
}

public void setCrp(Carpetas nueva_carpeta) {
    if(Crp == null){
       Crp = new ArrayList<>(); 
       Crp.add(nueva_carpeta);
    }else{
       Crp.add(nueva_carpeta); 
    }
}

public ArrayList<Archivo> getArc() {
    return Arc;
}

public void setArc(Archivo nuevo_archivo ) {
    if(Arc == null)
    {
        Arc = new ArrayList<>();
        Arc.add(nuevo_archivo);
    }else
    {
        Arc.add(nuevo_archivo);
    }
}

public static void menu(int a){
    Scanner input = new Scanner(System.in);
    System.out.println("1 - Search folder: ");
    System.out.println("2 - Type in/Create Folder: ");
    System.out.println("3 - Type in/Create Files: ");
    System.out.println("Typ in the menu option: ");
    a = input.nextInt();
    switch(a){
        case 1:

            break;
    }
}

public String searchCarpeta(String nombre, int y){
    if(y == Crp.size()){
        return "File not found.";
    }
    if(nombre.equals(Crp.get(y).getNombre())){
        return Crp.get(y).getNombre();
    }
    else{
        return searchCarpeta(nombre, y++);
    }        
}

public void createCarpetas(String nombre, int y){
    if(nombre.equals(Crp.get(y).getNombre())){
        System.out.println("Folder already exists.");
        return;
    }
    else{
       Crp.add(new Carpetas(nombre, 0));
        System.out.println("Folder added successfully!");
    }

}

public void createArchivo(String nombre, String archivo, int y){

}

public String getNombre() {
    return nombre;
}

public int getTamaño() {
    return tamaño;
}

public void setTamaño(int tamaño) {
    this.tamaño = tamaño;
}

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    Carpetas crp = null;

    System.out.println("Type the name of the file: ");
    String nombre = input.next();

    crp.Crp.add(new Carpetas(nombre, 0));

}

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题