Locadora em Java (usando modo texto)

====================================================
//Cliente
====================================================
public class Cliente{
    private int cod;
    private String nome;

    public void setCod(int c){
        cod = c;
    }

    public int getCod(){
        return cod;
    }

    public void setNome(String n){
        nome = n;
    }

    public String getNome(){
        return nome;
    }
}
====================================================
//Atendente
====================================================
public class Atendente{
    private int cod;
    private String nome;

    public void setCod(int c){
        cod = c;
    }

    public int getCod(){
        return cod;
    }

    public void setNome(String n){
        nome = n;
    }

    public String getNome(){
        return nome;
    }
}

====================================================
//Filme
====================================================

====================================================
//Locadora
====================================================

import java.util.*;
public class Locadora{
    public static Cliente clientes[] = new Cliente[20];
    public static Atendente atendentes[] = new Atendente[5];
    public static Filme filmes[] = new Filme[10];
//-----------------------------------------------------------------------BuscaIndiceNull
    public static int BuscaIndiceClienteNull(){
        boolean achou = false;
        int i = 0;
        while (achou==false && i<20){
            if (clientes[i] == null){
                achou = true;
            }else{
                i++;
            }        
        }
        if (achou == true){
            return i;
        }else{
            return -1;
        }    
    }
    public static int BuscaIndiceAtendenteNull(){
        boolean achou = false;
        int i = 0;
        while (achou==false && i<5){
            if (atendentes[i] == null){
                achou = true;
            }else{
                i++;
            }        
        }
        if (achou == true){
            return i;
        }else{
            return -1;
        }    
    }
    public static int BuscaIndiceFilmeNull(){
        boolean achou = false;
        int i = 0;
while (achou==false && i<10){
            if (filmes[i] == null){
                achou = true;
            }else{
                i++;
            }        
        }
        if (achou == true){
            return i;
        }else{
            return -1;
        }    
    }
//-----------------------------------------------------------------------BuscaIndiceNull
//-----------------------------------------------------------------------GerarCod
    public static int GerarCodCliente(){
        int maior = 0;
        int i = 0;
        for (i=0; i<20; i++){
            if(clientes[i] != null){
                if(clientes[i].getCod() > maior){
                    maior = clientes[i].getCod();
                }
            }
        }
        return maior+1;    
    }
    public static int GerarCodAtendente(){
        int maior = 0;
        int i = 0;
        for (i=0; i<5; i++){
            if(atendentes[i] != null){
                if(atendentes[i].getCod() > maior){
                    maior = atendentes[i].getCod();
                }
            }
        }
        return maior+1;    
    }
    public static int GerarCodFilme(){
        int maior = 0;
        int i = 0;
        for (i=0; i<10; i++){
            if(filmes[i] != null){
                if(filmes[i].getCod() > maior){
                    maior = filmes[i].getCod();
                }
            }
        }
        return maior+1;    
    }
//-----------------------------------------------------------------------GerarCod
//-----------------------------------------------------------------------BuscaNome
    public static int BuscaNomeCliente(String nome){
        int i = 0;
        boolean achou = false;
        while (achou == false && i<20){
            if (clientes[i]!=null){
                if(clientes[i].getNome().equals(nome)){
                    achou = true;
                }else{
                    i++;        
                }
            }else{
                i++;    
            }    
        }
        if (achou){
            return i;
        }else{
            return -1;
        }
    }
    public static int BuscaNomeAtendente(String nome){
        int i = 0;
        boolean achou = false;
        while (achou == false && i<20){
            if (atendentes[i]!=null){
                if(atendentes[i].getNome().equals(nome)){
                    achou = true;
                }else{
                    i++;        
                }
            }else{
                i++;    
            }    
        }
        if (achou){
            return i;
        }else{
            return -1;
        }
    }
    public static int BuscaNomeFilme(String nome){
        int i = 0;
        boolean achou = false;
        while (achou == false && i<20){
            if (filmes[i]!=null){
                if(filmes[i].getNome().equals(nome)){
                    achou = true;
                }else{
                    i++;        
                }
            }else{
                i++;    
            }    
        }
        if (achou){
            return i;
        }else{
            return -1;
        }
    }
//-----------------------------------------------------------------------BuscaNome
//-----------------------------------------------------------------------BuscaPorCodigo
    public static int BuscaClientePorCodigo(int cod){
        boolean achou = false;
        int i = 0;
        while(achou == false && i<20){
            if (clientes[i]!= null){
                if (clientes[i].getCod() == cod){
                    achou = true;        
                }else{
                    i++;
                }
            }else{
                i++;
            }
        }    
        if(achou){
            return i;
        }else{
            return -1;
        }    
    }
    public static int BuscaAtendentePorCodigo(int cod){
        boolean achou = false;
        int i = 0;
        while(achou == false && i<20){
            if (atendentes[i]!= null){
                if (atendentes[i].getCod() == cod){
                    achou = true;        
                }else{
                    i++;
                }
            }else{
                i++;
            }
        }    
        if(achou){
            return i;
        }else{
            return -1;
        }    
    }
    public static int BuscaFilmePorCodigo(int cod){
        boolean achou = false;
        int i = 0;
        while(achou == false && i<20){
            if (filmes[i]!= null){
                if (filmes[i].getCod() == cod){
                    achou = true;        
                }else{
                    i++;
                }
            }else{
                i++;
            }
        }    
        if(achou){
            return i;
        }else{
            return -1;
        }    
    }
//-----------------------------------------------------------------------BuscaPorCodigo
//-----------------------------------------------------------------------Imprimir
    public static void ImprimirCliente(Cliente c){
        System.out.println("Código: " + c.getCod());
        System.out.println("Nome: " +  c.getNome());
    }
    public static void ImprimirAtendente(Atendente a){
        System.out.println("Código: " + a.getCod());
        System.out.println("Nome: " +  a.getNome());
    }
    public static void ImprimirFilme(Filme f){
        System.out.println("Código: " + f.getCod());
        System.out.println("Nome: " +  f.getNome());
    }
//-----------------------------------------------------------------------Imprimir
//-----------------------------------------------------------------------CADASTRAR
    public static void CadastrarCliente(){
        int i = BuscaIndiceClienteNull();
        if (i != -1){
            Cliente c = new Cliente();
            System.out.println("Informe o nome do cliente:");
            Scanner scan = new Scanner(System.in);
            c.setNome(scan.nextLine());
            // geração de cod automaticamente
            c.setCod(GerarCodCliente());
            clientes[i] = c;
            System.out.println("Cliente cadastrado com    sucesso!!!");
            ImprimirCliente(clientes[i]);
        }else{
            System.out.println("Não há espaço para novos    clientes!!!");
        }
    }
    public static void CadastrarAtendente(){
        int i = BuscaIndiceAtendenteNull();
        if (i != -1){
            Atendente a = new Atendente();
            System.out.println("Informe o nome do atendente:");
            Scanner scan = new Scanner(System.in);
            a.setNome(scan.nextLine());
            // geração de cod automaticamente
            a.setCod(GerarCodAtendente());
            atendentes[i] = a;
            System.out.println("Atendente cadastrado com    sucesso!!!");
            ImprimirAtendente(atendentes[i]);
        }else{
            System.out.println("Não há espaço para novos    atendentes!!!");
        }
    }
    public static void CadastrarFilme(){
        int i = BuscaIndiceFilmeNull();
        if (i != -1){
            Filme f = new Filme();
            System.out.println("Informe o nome do filme:");
            Scanner scan = new Scanner(System.in);
            f.setNome(scan.nextLine());
            // geração de cod automaticamente
            f.setCod(GerarCodFilme());
            filmes[i] = f;
            System.out.println("Filme cadastrado com    sucesso!!!");
            ImprimirFilme(filmes[i]);
        }else{
            System.out.println("Não há espaço para novos    filmes!!!");
        }
    }
//-----------------------------------------------------------------------CADASTRAR
//-----------------------------------------------------------------------EXCLUIR
    public static void ExcluirCliente(){
        Scanner scan = new Scanner(System.in);
        int cod = 0;
        System.out.println("Informe o código do cliente a ser excluído: ");
        cod = scan.nextInt();    
        // fazer a busca do cliente no vetor
        int i = BuscaClientePorCodigo(cod);    
        if (i != -1){
            // imprimir cliente
            ImprimirCliente(clientes[i]);
            clientes[i] = null;
            System.out.println("O cliente foi excluído com    sucesso!!!");
        }else{
            System.out.println("O cliente com o código    informado não existe!!!");
        }
    }
    public static void ExcluirAtendente(){
        Scanner scan = new Scanner(System.in);
        int cod = 0;
        System.out.println("Informe o código do atendente a ser excluído: ");
        cod = scan.nextInt();    
        // fazer a busca do atendente no vetor
        int i = BuscaAtendentePorCodigo(cod);    
        if (i != -1){
            // imprimir atendentes
            ImprimirAtendente(atendentes[i]);
            atendentes[i] = null;
            System.out.println("O atendente foi excluído com    sucesso!!!");
        }else{
            System.out.println("O atendente com o código    informado não existe!!!");
        }
    }
    public static void ExcluirFilme(){
        Scanner scan = new Scanner(System.in);
        int cod = 0;
        System.out.println("Informe o código do filme a ser excluído: ");
        cod = scan.nextInt();    
        // fazer a busca do filme no vetor
        int i = BuscaFilmePorCodigo(cod);    
        if (i != -1){
            // imprimir filme
            ImprimirFilme(filmes[i]);
            filmes[i] = null;
            System.out.println("O filme foi excluído com    sucesso!!!");
        }else{
            System.out.println("O filme com o código    informado não existe!!!");
        }
    }
//-----------------------------------------------------------------------EXCLUIR
//-----------------------------------------------------------------------BUSCAR
    public static void BuscarClientePorNome(){
        Scanner scan = new Scanner(System.in);
        String nome = "";
        System.out.println("Informe o nome a ser pesquisado: ");
        nome = scan.nextLine();
        int i = BuscaNomeAtendente(nome);
        if (i != -1){
            ImprimirCliente(clientes[i]);
        }else{
            System.out.println("O cliente informado não foi encontrado!!!");
        }
    }
    public static void BuscarAtendentePorNome(){
        Scanner scan = new Scanner(System.in);
        String nome = "";
        System.out.println("Informe o nome a ser pesquisado: ");
        nome = scan.nextLine();
        int i = BuscaNomeAtendente(nome);
        if (i != -1){
            ImprimirAtendente(atendentes[i]);
        }else{
            System.out.println("O atendente informado não foi encontrado!!!");
        }
    }
    public static void BuscarFilmePorNome(){
        Scanner scan = new Scanner(System.in);
        String nome = "";
        System.out.println("Informe o nome a ser pesquisado: ");
        nome = scan.nextLine();
        int i = BuscaNomeFilme(nome);
        if (i != -1){
            ImprimirFilme(filmes[i]);
        }else{
            System.out.println("O filme informado não foi encontrado!!!");
        }
    }
//-----------------------------------------------------------------------BUSCAR
//-----------------------------------------------------------------------LISTAR
    public static void ListarClientes(){
        int i = 0;
        for (i = 0; i<20; i++){
            if (clientes[i] != null){
                ImprimirCliente(clientes[i]);
            }
        }
    }
    public static void ListarAtendentes(){
        int i = 0;
        for (i = 0; i<5; i++){
            if (atendentes[i] != null){
                ImprimirAtendente(atendentes[i]);
            }
        }
    }
//-----------------------------------------------------------------------LISTAR
//-----------------------------------------------------------------------MAIN
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String op = "1";
        String op2;
     
        while(!op.equals("0")){
            System.out.println("=======LOCADORA DE FILMES ======");
            System.out.println("1 - Cliente");
            System.out.println("2 - Atendente");
            System.out.println("3 - Filmes");
            System.out.println("0 - SAIR");
            op = scan.nextLine();
            if (op.equals("1")){
                System.out.println("=======MENU CLIENTES ======");
                System.out.println("1 - Cadastrar cliente");
                System.out.println("2 - Excluir cliente");
                System.out.println("3 - Buscar cliente");
                System.out.println("4 - Listar clientes");
                scan = new Scanner(System.in);
                op2 = scan.nextLine();
if(op2.equals("1")){
                    CadastrarCliente();
                }else
                if(op2.equals("2")){
                    ExcluirCliente();
                }else
                if(op2.equals("3")){
                    BuscarClientePorNome();
                }else
                if(op2.equals("4")){
                    ListarClientes();
                }        
            }else
            if (op.equals("2")){
                System.out.println("=======MENU ATENDENTES ======");
                System.out.println("1 - Cadastrar atendente");
                System.out.println("2 - Excluir atendente");
                System.out.println("3 - Buscar atendente");
                System.out.println("4 - Listar atendentes");
                scan = new Scanner(System.in);
                op2 = scan.nextLine();
                if(op2.equals("1")){
                    CadastrarAtendente();
                }else
                if(op2.equals("2")){
                    ExcluirAtendente();
                }else
                if(op2.equals("3")){
                    BuscarAtendentePorNome();
                }else
                if(op2.equals("4")){
                    ListarAtendentes();
                }
            }else
            if (op.equals("3")){
                System.out.println("=======MENU FILMES ======");
                System.out.println("1 - Cadastrar filme");
System.out.println("2 - Excluir filme");
                System.out.println("3 - Buscar filme");
                System.out.println("4 - Listar filmes");
                System.out.println("5 - Locar filme");
                System.out.println("6 - Devolver filme");
                scan = new Scanner(System.in);
                op2 = scan.nextLine();
                if(op2.equals("1")){
                    CadastrarFilme();
                }else
                if(op2.equals("2")){
                    ExcluirFilme();
                }else
                if(op2.equals("3")){
                    BuscarFilmePorNome();
                }else
                if(op2.equals("4")){
                    ListarFilme();
                }else
                if(op2.equals("5")){
                    //LocarFilme();
                }else
                if(op2.equals("6")){
                    //DevolverFilme();
                }
            }
        }
    }
}

Nenhum comentário:

Postar um comentário