I need to find the instance of an attribute of an object that is in an array to print it

0

I have to find the Motorola instance of the ClientCellular attribute. It is in a switch inside a for. Yes, the flow of control is a big mess but it occurred to me that way. Thanks in advance. The exercise is this: name and certificate of the first customer to acquire a motorola.

package principal1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import recursos.Cliente;

public class Principal1 {


public static void main(String[] args) throws IOException{
    BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
    int opc=0;
    double ventasLG=0.0;
    int ventasKyocera=0;
    String nombre="";
    Cliente clientes[]=new Cliente[5];


    for (int i = 0; i < clientes.length; i++) {

        clientes[i] = new Cliente(nombre);

        String marcaCelular="";
        int celular=0;

        System.out.println("Ingrese marca del celular:\n1.-Nokia\n2.-Motorola"
                + "\n3.-LG\n4.-Kyocera");
        celular=Integer.parseInt(in.readLine());
        switch(celular){
            case 1:
                clientes[i].setMarcaCelular("Nokia");
                System.out.println("Ingrese nombre del cliente");
                nombre=in.readLine();
                System.out.println("Ingrese cedula de identidad");
                int cedulaIdentidad=Integer.parseInt(in.readLine());
                System.out.println("Ingrese precio del celular");
                int precioCelular=Integer.parseInt(in.readLine());
                clientes[i]=new Cliente(nombre, cedulaIdentidad, marcaCelular, precioCelular);
                  break;
            case 2:
                clientes[i].setMarcaCelular("Motorola");
                System.out.println("Ingrese nombre del cliente");
                nombre=in.readLine();
                System.out.println("Ingrese cedula de identidad");
                cedulaIdentidad=Integer.parseInt(in.readLine());
                System.out.println("Ingrese precio del celular");
                precioCelular=Integer.parseInt(in.readLine());
                clientes[i]=new Cliente(nombre, cedulaIdentidad, marcaCelular, precioCelular);

                break;
            case 3:
                clientes[i].setMarcaCelular("LG");
                System.out.println("Ingrese nombre del cliente");
                nombre=in.readLine();
                System.out.println("Ingrese cedula de identidad");
                cedulaIdentidad=Integer.parseInt(in.readLine());
                System.out.println("Ingrese precio del celular");
                precioCelular=Integer.parseInt(in.readLine());
                clientes[i]=new Cliente(nombre, cedulaIdentidad, marcaCelular, precioCelular);
                //2
                ventasLG++;
                break;
            case 4:
                clientes[i].setMarcaCelular("Kyocera");
                System.out.println("Ingrese nombre del cliente");
                nombre=in.readLine();
                System.out.println("Ingrese cedula de identidad");
                cedulaIdentidad=Integer.parseInt(in.readLine());
                System.out.println("Ingrese precio del celular");
                precioCelular=Integer.parseInt(in.readLine());
                if(precioCelular>=300000){
                ventasKyocera++;
                }
                clientes[i]=new Cliente(nombre, cedulaIdentidad, marcaCelular, precioCelular);
                break;
            default:
                System.out.println("Opcion incorrecta");
        }
    
asked by carpopper 11.11.2018 в 21:52
source

1 answer

0

To know which of the clients have motorola it is enough to put suppose that they have getters if(clientes[i].getMarcaCelular.equal("Motorola")) within a While for when you find it within the client's arrangement you know which is the first one. I should stay like that assuming you have the getters and the rest you adapt to your code

boolean flag=true;
int i=0;
While(flag==true){
   if(clientes[i].getMarcaCelular.equal("Motorola"){
      System.out.println(clientes[i].getNombre()+ "Cedula"+ clientes[i].getCedula());
      flag=false;
   }
   i++;   
}
    
answered by 11.11.2018 в 22:09