Updated by Ettar 2017-06-19 View revision File Auto.java Added Side-by-side diff More Ignore whitespace Hide word diff +public class Auto { + + private int id; + //private static int idC; + + public Auto(){ + id=Eventmanager.addAID(); + //idC++; + //id=idC; + } + + public void output(){ + System.out.println(id); + } +} File Nutzer.java Added Side-by-side diff More Ignore whitespace Hide word diff +public class Nutzer { + + private int id; + //private static int idC; + + public Nutzer(){ + id=Eventmanager.addNID(); + //idC++; + //id=idC; + } + + public void output(){ + System.out.println(id); + } +} File mainClass.java Added Side-by-side diff More Ignore whitespace Hide word diff +import java.util.ArrayList; + +public class mainClass { + public static void main(String[] ARGS){ + int d=10; + + ArrayList<Auto> aList = new ArrayList<>(); + ArrayList<Nutzer> nList = new ArrayList<>(); + + for(int i=0;i<d;i++){ + aList.add(new Auto()); + } + + for(int i=0;i<d;i++){ + nList.add(new Nutzer()); + } + + iterate(aList); + System.out.println(); + iterate(nList); + + } + + public static void iterate(ArrayList<?> list){ + for(Object obj:list){ + if(obj instanceof Auto){ + ((Auto) obj).output(); + } + else{ + ((Nutzer) obj).output(); + } + + } + } +}
Created by Ettar 2017-06-19 View revision File Eventmanager.java Added Side-by-side diff More Ignore whitespace Hide word diff +public class Eventmanager { + public static int autoid=0; + public static int nutzerid=0; + + public static int addAID(){ + autoid++; + return autoid; + } + + public static int addNID(){ + nutzerid++; + return nutzerid; + } +}