Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Naracka {
- public String destinacija_adresa;
- public ArrayList<Sendvic> sendvici;
- public Naracka(){
- sendvici = new ArrayList<Sendvic>();
- }
- }
- public class Sendvic implements Cloneable{
- public String meso;
- public String dodatok;
- public String preliv;
- private int numOfClones = 0;
- public Sendvic(String meso, String dodatok, String preliv) {
- this.meso = meso;
- this.dodatok = dodatok;
- this.preliv = preliv;
- }
- @Override
- protected Sendvic clone() throws CloneNotSupportedException {
- Sendvic clonedSendvic = (Sendvic) super.clone();
- if(numOfClones == 198){
- clonedSendvic.meso = new String("stek");
- }
- if(numOfClones == 199){
- clonedSendvic.dodatok = new String("salata");
- }
- numOfClones++;
- return clonedSendvic;
- }
- @Override
- public String toString() {
- return String.format("Sendvic%d: [meso:%-10s, dodatok:%-7s, preliv:%-2s ]", numOfClones, meso, dodatok, preliv);
- }
- }
- public class Test {
- public static void main(String[] args) {
- Naracka n = new Naracka();
- Sendvic s = new Sendvic("pleskavica", "pomfrit", "/");
- for(int i=0; i<200; i++){
- try{
- Sendvic ss = s.clone();
- n.sendvici.add(ss);
- System.out.println(ss);
- }
- catch(Exception e){}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement