Advertisement
Guest User

Untitled

a guest
May 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. import java.util.*;
  6. /**
  7.  *
  8.  * @author lazar
  9.  */
  10. public class kolll {
  11.  
  12.     /**
  13.      * @param args the command line arguments
  14.      */
  15.     String ime;
  16.     String prezime;
  17.     public static void main(String[] args) {
  18.         // TODO code application logic here
  19.         imenik i=new imenik();
  20.         i.dodaj ("Petar", "Kralj");
  21.         i.dodaj("Marko", "Markovic");
  22.         i.prikazi();
  23.         i.pretraga("Lazar", "Stojnic");
  24.  
  25.     }
  26. }
  27. class imenik {
  28.     private List <kolll>is;
  29.  
  30.  public imenik(){
  31.  
  32. is=new ArrayList();
  33.  }
  34. public void dodaj(String ime,String pre){
  35.     kolll k=new kolll();
  36.  k.ime=ime;
  37. k.prezime=pre;
  38. is.add(k);
  39. }
  40. public void prikazi (){
  41.     int i=0;
  42. while (i<this. is.size ()) {
  43. System.out.println("Ime"+is.get(i).ime+"prezime"+is.get(i).prezime); i++;
  44. }
  45.  
  46.  
  47.  
  48. }
  49. public boolean pretraga (String ime, String pre){
  50.     boolean rezultat = false; for (int i=0; i<this. is .size () ; i++) {
  51. if(this.is.get(i).ime.equals(ime)){
  52. System.out.println("Trazeno ime je"+this.is.get(i).ime+"prezime");
  53.         rezultat = true; break;
  54. }
  55. }if(rezultat==false){
  56. System.out.println("Novi kontakt"+ime+pre);
  57. }
  58. return rezultat; }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement