Foto

Mitabeit in der LV


Projektdefinition - Beschreibung: In diesem Abschnitt geht es um die Mitarbeit in der LV. Da ich leider aufgrund der Überschneidungen mit dem Schulpraktikum im Abendgymnasium sehr wenig anwesend war, habe ich mich in der LV nicht sehr stark einbringen können. Ich habe dementsprechend nur das D'Hondt Verfahren in einer Java-Implementierung vorzuweisen. Ich möchte hiermit Herrn Prof. Micheuz für seine Nachsicht danken.

import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class DHondt { public static void main(String[] args) { int numofparties = 4; int maxmand = 12; ArrayList votes = scan(numofparties); ArrayList> all = concat(votes, numofparties, maxmand); ArrayList NumOfMandats = mandatories(all, maxmand); System.out.println(NumOfMandats); } public static ArrayList divide(int votes, int maxmand) { ArrayList votediv = new ArrayList<>(); while (maxmand > 0) { votediv.add(votes); votes = votes / 2; maxmand--; } return votediv; } public static ArrayList scan(int numofparties) { ArrayList parties = new ArrayList<>(); Scanner sc = new Scanner(System.in); for (int i = 0; i < numofparties; i++) { System.out.println("Bitte Stimmen der " + (i + 1) + ". Partei angeben:"); parties.add(sc.nextInt()); } return parties; } public static ArrayList> concat(ArrayList votes, int numofparties, int maxmand) { ArrayList> all = new ArrayList<>(); for (int i = 0; i < numofparties; i++) { all.add(divide(votes.get(i), maxmand)); } return all; } public static int maximumidx(ArrayList> all) { ArrayList max = new ArrayList<>(); for (int i = 0; i < all.size(); i++) { max.add(all.get(i).get(0)); } int obj = Collections.max(max); return max.indexOf(obj); } public static ArrayList mandatories(ArrayList> all, int maxmand) { ArrayList mand = new ArrayList<>(all.size()); for (int i = 0; i < all.size(); i++) { mand.add(0); } for (int i = 0; i < maxmand; i++) { int idx = maximumidx(all); all.get(idx).remove(0); mand.set(idx, mand.get(idx) + 1); } return mand; } }