Advertisement
Guest User

prototip :D

a guest
Oct 25th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.ArrayList;
  2. public class Naracka {
  3.     public String destinacija_adresa;
  4.     public ArrayList<Sendvic> sendvici;
  5.    
  6.     public Naracka(){
  7.         sendvici = new ArrayList<Sendvic>();
  8.     }
  9. }
  10.  
  11.  
  12. public class Sendvic implements Cloneable{
  13.     public String meso;
  14.     public String dodatok;
  15.     public String preliv;
  16.     private int numOfClones = 0;
  17.    
  18.     public Sendvic(String meso, String dodatok, String preliv) {
  19.         this.meso = meso;
  20.         this.dodatok = dodatok;
  21.         this.preliv = preliv;
  22.     }
  23.  
  24.     @Override
  25.     protected Sendvic clone() throws CloneNotSupportedException {
  26.         Sendvic clonedSendvic = (Sendvic) super.clone();
  27.  
  28.         if(numOfClones == 198){
  29.             clonedSendvic.meso = new String("stek");
  30.         }
  31.         if(numOfClones == 199){
  32.             clonedSendvic.dodatok = new String("salata");
  33.         }
  34.         numOfClones++;
  35.  
  36.         return clonedSendvic;
  37.     }
  38.    
  39.     @Override
  40.     public String toString() {
  41.         return String.format("Sendvic%d: [meso:%-10s, dodatok:%-7s, preliv:%-2s ]", numOfClones, meso, dodatok, preliv);
  42.     }
  43. }
  44.  
  45.  
  46. public class Test {
  47.  
  48.     public static void main(String[] args) {
  49.         Naracka n = new Naracka();
  50.         Sendvic s = new Sendvic("pleskavica", "pomfrit", "/");
  51.         for(int i=0; i<200; i++){
  52.             try{
  53.             Sendvic ss = s.clone();
  54.             n.sendvici.add(ss);
  55.             System.out.println(ss);
  56.             }
  57.             catch(Exception e){}
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement