i need find the instance of an attribute that the object is into an array












-3














i dont know how i find the intance Motorola in the array clientes that is in a swich into a for. the exercise is this: Name and identification of de first cliente in buy a Motorola celphone. Maybe i need a condition like an if or a while in case 2 but i dont know how to do it. Again, sorry for my english, thanks!!!



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) {
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.-Nokian2.-Motorola" + "n3.-LGn4.-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");
}
}
}
}









share|improve this question
























  • Hello. Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.
    – Mickael
    Nov 12 at 12:55












  • i need print nombre and cedulaIdentidad of the first Cliente in buy a Motorola, so how i find that Cliente what her marcaCelular is Motorola and was the first instance and i need her name and cedulaIdentidad. i make a switch for each marcaCelular and create a class Cliente for instantiate the clientes,
    – carpopper
    Nov 12 at 13:37
















-3














i dont know how i find the intance Motorola in the array clientes that is in a swich into a for. the exercise is this: Name and identification of de first cliente in buy a Motorola celphone. Maybe i need a condition like an if or a while in case 2 but i dont know how to do it. Again, sorry for my english, thanks!!!



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) {
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.-Nokian2.-Motorola" + "n3.-LGn4.-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");
}
}
}
}









share|improve this question
























  • Hello. Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.
    – Mickael
    Nov 12 at 12:55












  • i need print nombre and cedulaIdentidad of the first Cliente in buy a Motorola, so how i find that Cliente what her marcaCelular is Motorola and was the first instance and i need her name and cedulaIdentidad. i make a switch for each marcaCelular and create a class Cliente for instantiate the clientes,
    – carpopper
    Nov 12 at 13:37














-3












-3








-3







i dont know how i find the intance Motorola in the array clientes that is in a swich into a for. the exercise is this: Name and identification of de first cliente in buy a Motorola celphone. Maybe i need a condition like an if or a while in case 2 but i dont know how to do it. Again, sorry for my english, thanks!!!



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) {
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.-Nokian2.-Motorola" + "n3.-LGn4.-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");
}
}
}
}









share|improve this question















i dont know how i find the intance Motorola in the array clientes that is in a swich into a for. the exercise is this: Name and identification of de first cliente in buy a Motorola celphone. Maybe i need a condition like an if or a while in case 2 but i dont know how to do it. Again, sorry for my english, thanks!!!



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) {
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.-Nokian2.-Motorola" + "n3.-LGn4.-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");
}
}
}
}






java arrays methods






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 16:25









Nicholas K

5,44851031




5,44851031










asked Nov 12 at 12:52









carpopper

44




44












  • Hello. Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.
    – Mickael
    Nov 12 at 12:55












  • i need print nombre and cedulaIdentidad of the first Cliente in buy a Motorola, so how i find that Cliente what her marcaCelular is Motorola and was the first instance and i need her name and cedulaIdentidad. i make a switch for each marcaCelular and create a class Cliente for instantiate the clientes,
    – carpopper
    Nov 12 at 13:37


















  • Hello. Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.
    – Mickael
    Nov 12 at 12:55












  • i need print nombre and cedulaIdentidad of the first Cliente in buy a Motorola, so how i find that Cliente what her marcaCelular is Motorola and was the first instance and i need her name and cedulaIdentidad. i make a switch for each marcaCelular and create a class Cliente for instantiate the clientes,
    – carpopper
    Nov 12 at 13:37
















Hello. Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.
– Mickael
Nov 12 at 12:55






Hello. Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.
– Mickael
Nov 12 at 12:55














i need print nombre and cedulaIdentidad of the first Cliente in buy a Motorola, so how i find that Cliente what her marcaCelular is Motorola and was the first instance and i need her name and cedulaIdentidad. i make a switch for each marcaCelular and create a class Cliente for instantiate the clientes,
– carpopper
Nov 12 at 13:37




i need print nombre and cedulaIdentidad of the first Cliente in buy a Motorola, so how i find that Cliente what her marcaCelular is Motorola and was the first instance and i need her name and cedulaIdentidad. i make a switch for each marcaCelular and create a class Cliente for instantiate the clientes,
– carpopper
Nov 12 at 13:37












1 Answer
1






active

oldest

votes


















0














You can have a boolean motorola = false, and inside case 2 put a



if(!motorola) {
System.out.println("print first Motorola client ...");
motorola = true;
}


Or after you have all clients:



Every time a Cliente buys a phone, his information is saved in clientes array. This is stored in chronological order so the first guy that bought a Motorola will be before the next guys who bought the same phone. Then you only have to iterate the clientes array and print the first Cliente that bought a Motorola.



for(int i = 0; i < clientes.length; i++) {
if(clientes[i].getMarcaCelular().equals("Motorola")){
System.out.println(
clientes[i].getNombre() + " , " +
clientes[i].getCedulaIdentidad()
);
break;
}
}


Also, try to write code in English as a convention. Im sure you do not want to read Chinese typed code.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262594%2fi-need-find-the-instance-of-an-attribute-that-the-object-is-into-an-array%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can have a boolean motorola = false, and inside case 2 put a



    if(!motorola) {
    System.out.println("print first Motorola client ...");
    motorola = true;
    }


    Or after you have all clients:



    Every time a Cliente buys a phone, his information is saved in clientes array. This is stored in chronological order so the first guy that bought a Motorola will be before the next guys who bought the same phone. Then you only have to iterate the clientes array and print the first Cliente that bought a Motorola.



    for(int i = 0; i < clientes.length; i++) {
    if(clientes[i].getMarcaCelular().equals("Motorola")){
    System.out.println(
    clientes[i].getNombre() + " , " +
    clientes[i].getCedulaIdentidad()
    );
    break;
    }
    }


    Also, try to write code in English as a convention. Im sure you do not want to read Chinese typed code.






    share|improve this answer




























      0














      You can have a boolean motorola = false, and inside case 2 put a



      if(!motorola) {
      System.out.println("print first Motorola client ...");
      motorola = true;
      }


      Or after you have all clients:



      Every time a Cliente buys a phone, his information is saved in clientes array. This is stored in chronological order so the first guy that bought a Motorola will be before the next guys who bought the same phone. Then you only have to iterate the clientes array and print the first Cliente that bought a Motorola.



      for(int i = 0; i < clientes.length; i++) {
      if(clientes[i].getMarcaCelular().equals("Motorola")){
      System.out.println(
      clientes[i].getNombre() + " , " +
      clientes[i].getCedulaIdentidad()
      );
      break;
      }
      }


      Also, try to write code in English as a convention. Im sure you do not want to read Chinese typed code.






      share|improve this answer


























        0












        0








        0






        You can have a boolean motorola = false, and inside case 2 put a



        if(!motorola) {
        System.out.println("print first Motorola client ...");
        motorola = true;
        }


        Or after you have all clients:



        Every time a Cliente buys a phone, his information is saved in clientes array. This is stored in chronological order so the first guy that bought a Motorola will be before the next guys who bought the same phone. Then you only have to iterate the clientes array and print the first Cliente that bought a Motorola.



        for(int i = 0; i < clientes.length; i++) {
        if(clientes[i].getMarcaCelular().equals("Motorola")){
        System.out.println(
        clientes[i].getNombre() + " , " +
        clientes[i].getCedulaIdentidad()
        );
        break;
        }
        }


        Also, try to write code in English as a convention. Im sure you do not want to read Chinese typed code.






        share|improve this answer














        You can have a boolean motorola = false, and inside case 2 put a



        if(!motorola) {
        System.out.println("print first Motorola client ...");
        motorola = true;
        }


        Or after you have all clients:



        Every time a Cliente buys a phone, his information is saved in clientes array. This is stored in chronological order so the first guy that bought a Motorola will be before the next guys who bought the same phone. Then you only have to iterate the clientes array and print the first Cliente that bought a Motorola.



        for(int i = 0; i < clientes.length; i++) {
        if(clientes[i].getMarcaCelular().equals("Motorola")){
        System.out.println(
        clientes[i].getNombre() + " , " +
        clientes[i].getCedulaIdentidad()
        );
        break;
        }
        }


        Also, try to write code in English as a convention. Im sure you do not want to read Chinese typed code.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 13 at 21:26

























        answered Nov 13 at 21:17









        elbraulio

        4589




        4589






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262594%2fi-need-find-the-instance-of-an-attribute-that-the-object-is-into-an-array%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown