Java how to print two different values from one array -


i striving print 2 different values 1 array of stored models of computers. @ moment program print first computer index cannot how print 1 of particular model. fragment of main class

computerlist list = new computerlist(); coputer item; string model; switch (option)  {     case 'm':        model = console.askstring("enter model?: ");    item = list.findmodel(model); if (item == null)    system.out.println("cannot find " + model); else    item.print("computer details..." + model); 

... , computerlist class

arraylist<laptop> laptops; private arraylist<string> models;        public seriallist() { laptops = new arraylist<laptop>(); models = new arraylist<string>(); }  public void add(computer ancomputer) { laptops.add(ancomputer); models.add(ancomputer.getmodel()); }  public void print() {      int nitems = computer.size();     (int i=0; i<nitems; i++)     {         system.out.println(computers.get(i));  }  public computer findmodel(string amodel) {     int index = models.indexof(amodel);     if (index == -1)         return null;     else         return computers.get(index); } 

}

i struggling resolve matter few days of tutorials based on numbers, values etc. grateful of matter. regards

when print object identifier @222222 etc...

you have print attributes. system.out.println(computer.getname + computer.getid);


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -