Compare commits
	
		
			26 Commits
		
	
	
		
			50cce6a92b
			...
			master
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 91b71a30d9 | |||
| 43899c9192 | |||
| 27766e49fc | |||
| f558cb059f | |||
| a3aaed397f | |||
| 4e2778d2c5 | |||
| 1395a5ddc2 | |||
| 032c3602a7 | |||
| 77c4a09c6a | |||
| 4afbedc1a8 | |||
| ed4c058713 | |||
| caf5b72d90 | |||
| 248eae539c | |||
| 7cc604fad9 | |||
| 0218fe81cb | |||
| 5bce0a0c4d | |||
| cc39b7f240 | |||
| 25ff282f27 | |||
| a75a69163c | |||
| d45ae26461 | |||
| d6685d8020 | |||
| 8f0a176d97 | |||
| becadc63be | |||
| dfe440bde3 | |||
| 34346f757b | |||
| a6a35222eb | 
							
								
								
									
										54
									
								
								src/EinkommenInfo.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								src/EinkommenInfo.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
				
			|||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Scanner;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class EinkommenInfo {
 | 
				
			||||||
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
 | 
					        System.out.println("Übersicht über Bevölkerungszahl und Einkommen in Deutschland");
 | 
				
			||||||
 | 
					        GebietsDatei gebietsDatei = new GebietsDatei("Einkommen.csv");
 | 
				
			||||||
 | 
					        List<Gebiet> gebiete = gebietsDatei.getGebiete();
 | 
				
			||||||
 | 
					        GebietsListe gebietsListe = new GebietsListe(gebiete);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        System.out.println(gebietsListe.getAnzahlGesamt() + " Gebiete wurden eingelesen.");
 | 
				
			||||||
 | 
					        System.out.println(gebietsListe.getAnzahlUnvollständig() + " davon haben unvollständige Angaben\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        System.out.println("Gebiet mit dem geringsten Durchschnittseinkommen:");
 | 
				
			||||||
 | 
					        Gebiet tmp = gebietsListe.getGebietMinDurchschnittsEinkommen();
 | 
				
			||||||
 | 
					        System.out.println(tmp.getName());
 | 
				
			||||||
 | 
					        System.out.println(tmp.getAnzahlEinwohner() + " Einwohner");
 | 
				
			||||||
 | 
					        System.out.println(tmp.getDurchschnittsEinkommen() + " Euro / Einwohner");
 | 
				
			||||||
 | 
					        System.out.println("");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        System.out.println("Gebiet mit der größten Einwohnerzahl");
 | 
				
			||||||
 | 
					        tmp = gebietsListe.getGebietMaxAnzahlEinwohner();
 | 
				
			||||||
 | 
					        System.out.println(tmp.getName());
 | 
				
			||||||
 | 
					        System.out.println(tmp.getAnzahlEinwohner() + " Einwohner");
 | 
				
			||||||
 | 
					        System.out.println(tmp.getDurchschnittsEinkommen() + " Euro / Einwohner");
 | 
				
			||||||
 | 
					        System.out.println("");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        System.out.print("Name des Gebietes : ");
 | 
				
			||||||
 | 
					        Scanner reader = new Scanner(System.in);
 | 
				
			||||||
 | 
					        String eingabe = reader.nextLine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        while(!eingabe.isEmpty()) {
 | 
				
			||||||
 | 
					            List<Gebiet> tmpList;
 | 
				
			||||||
 | 
					            tmpList = gebietsListe.getGebieteNachNamen(eingabe);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (Gebiet g : tmpList) {
 | 
				
			||||||
 | 
					                System.out.println(g.getName());
 | 
				
			||||||
 | 
					                if(g.getDurchschnittsEinkommen() > 0) {
 | 
				
			||||||
 | 
					                    System.out.println(g.getAnzahlEinwohner() + " Einwohner");
 | 
				
			||||||
 | 
					                    System.out.println(g.getDurchschnittsEinkommen() + " Euro / Einwohner");
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    System.out.println("Einwohnerzahl unbekannt");
 | 
				
			||||||
 | 
					                    System.out.println("Durchschnittseinkommen unbekannt");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                System.out.println("");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            System.out.println(tmpList.size() + " Gebiete wurden gefunden.");
 | 
				
			||||||
 | 
					            System.out.println();
 | 
				
			||||||
 | 
					            System.out.print("Name des Gebietes : ");
 | 
				
			||||||
 | 
					            eingabe = reader.nextLine();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,17 +1,16 @@
 | 
				
			|||||||
public class Gebiet {
 | 
					public class Gebiet implements GebietInterface{
 | 
				
			||||||
    private int jahr;
 | 
					    private int jahr;
 | 
				
			||||||
    private int schlüssel;
 | 
					    private int schluessel;
 | 
				
			||||||
    private String name;
 | 
					    private String name;
 | 
				
			||||||
    private long gesamtEinkommen;
 | 
					    private long gesamtEinkommen;
 | 
				
			||||||
    private int durchschnittsEinkommen;
 | 
					    private int durchschnittsEinkommen;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Gebiet(int jahr, int schlüssel, String name, long gesamtEinkommen, int durchschnittsEinkommen) {
 | 
					    public Gebiet(int jahr, int schluessel, String name, long gesamtEinkommen, int durchschnittsEinkommen) {
 | 
				
			||||||
        this.jahr = jahr;
 | 
					        this.jahr = jahr;
 | 
				
			||||||
        this.schlüssel = schlüssel;
 | 
					        this.schluessel = schluessel;
 | 
				
			||||||
        this.name = name;
 | 
					        this.name = name;
 | 
				
			||||||
        this.gesamtEinkommen = gesamtEinkommen;
 | 
					        this.gesamtEinkommen = gesamtEinkommen;
 | 
				
			||||||
        this.durchschnittsEinkommen = durchschnittsEinkommen;
 | 
					        this.durchschnittsEinkommen = durchschnittsEinkommen;
 | 
				
			||||||
        // lol
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int getJahr() {
 | 
					    public int getJahr() {
 | 
				
			||||||
@@ -19,7 +18,7 @@ public class Gebiet {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int getSchlüssel() {
 | 
					    public int getSchlüssel() {
 | 
				
			||||||
        return schlüssel;
 | 
					        return schluessel;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getName() {
 | 
					    public String getName() {
 | 
				
			||||||
@@ -35,14 +34,14 @@ public class Gebiet {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int getAnzahlEinwohner() {
 | 
					    public int getAnzahlEinwohner() {
 | 
				
			||||||
        return 1;
 | 
					        return (int)(gesamtEinkommen * 1000 / durchschnittsEinkommen);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public String toString() {
 | 
					    public String toString() {
 | 
				
			||||||
        return "Gebiet{" +
 | 
					        return "Gebiet{" +
 | 
				
			||||||
                "jahr=" + jahr +
 | 
					                "jahr=" + jahr +
 | 
				
			||||||
                ", schlüssel=" + schlüssel +
 | 
					                ", schluessel=" + schluessel +
 | 
				
			||||||
                ", name='" + name + '\'' +
 | 
					                ", name='" + name + '\'' +
 | 
				
			||||||
                ", gesamtEinkommen=" + gesamtEinkommen +
 | 
					                ", gesamtEinkommen=" + gesamtEinkommen +
 | 
				
			||||||
                ", durchschnittsEinkommen=" + durchschnittsEinkommen +
 | 
					                ", durchschnittsEinkommen=" + durchschnittsEinkommen +
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										8
									
								
								src/GebietInterface.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/GebietInterface.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					public interface GebietInterface {
 | 
				
			||||||
 | 
					    int getJahr();
 | 
				
			||||||
 | 
					    int getSchlüssel();
 | 
				
			||||||
 | 
					    String getName();
 | 
				
			||||||
 | 
					    long getGesamtEinkommen();
 | 
				
			||||||
 | 
					    int getDurchschnittsEinkommen();
 | 
				
			||||||
 | 
					    int getAnzahlEinwohner();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,12 +1,54 @@
 | 
				
			|||||||
import java.lang.reflect.Array;
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					import java.nio.file.Files;
 | 
				
			||||||
 | 
					import java.nio.file.Path;
 | 
				
			||||||
 | 
					import java.nio.file.Paths;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class GebietsDatei {
 | 
					public class GebietsDatei implements GebietsDateiInterface{
 | 
				
			||||||
 | 
					    private List<Gebiet> gebiete = new ArrayList<>();
 | 
				
			||||||
    public String dateiname;
 | 
					    public String dateiname;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public GebietsDatei(String dateiname) {
 | 
					    public GebietsDatei(String dateiname) {
 | 
				
			||||||
        this.dateiname = dateiname;
 | 
					        this.dateiname = dateiname;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void laden() {
 | 
				
			||||||
 | 
					        Path pfad = Paths.get(dateiname);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            List<String> zeilen = Files.readAllLines(pfad);
 | 
				
			||||||
 | 
					            for (int i = 2; i < zeilen.size(); i++) {
 | 
				
			||||||
 | 
					                String[] teile = zeilen.get(i).split(";");
 | 
				
			||||||
 | 
					                int jahr = Integer.parseInt(teile[0]);
 | 
				
			||||||
 | 
					                int schlüssel = Integer.parseInt(teile[1]);
 | 
				
			||||||
 | 
					                String name = teile[2];
 | 
				
			||||||
 | 
					                int gesamtEinkommen;
 | 
				
			||||||
 | 
					                if(teile[3].equals("-")){
 | 
				
			||||||
 | 
					                    gesamtEinkommen = -1;
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    gesamtEinkommen = Integer.parseInt(teile[3]);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                int durchsEinkommen;
 | 
				
			||||||
 | 
					                if(teile[4].equals("-")){
 | 
				
			||||||
 | 
					                    durchsEinkommen = -1;
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    durchsEinkommen = Integer.parseInt(teile[4]);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                gebiete.add(new Gebiet(jahr, schlüssel, name, gesamtEinkommen, durchsEinkommen));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        } catch (IOException e) {
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<Gebiet> getGebiete() {
 | 
				
			||||||
 | 
					        laden();
 | 
				
			||||||
 | 
					        return gebiete;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								src/GebietsDateiInterface.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/GebietsDateiInterface.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface GebietsDateiInterface {
 | 
				
			||||||
 | 
					    List<Gebiet> getGebiete();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,2 +1,72 @@
 | 
				
			|||||||
public class GebietsListe {
 | 
					
 | 
				
			||||||
 | 
					import java.sql.Array;
 | 
				
			||||||
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class GebietsListe implements GebietsListeInterface{
 | 
				
			||||||
 | 
					    private List<Gebiet> gebiete;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public GebietsListe(List<Gebiet> gebiete) {
 | 
				
			||||||
 | 
					        this.gebiete = gebiete;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Gebiet getGebietMinDurchschnittsEinkommen(){
 | 
				
			||||||
 | 
					        int gebietA = 0;
 | 
				
			||||||
 | 
					        int gebietB = gebiete.get(0).getDurchschnittsEinkommen();
 | 
				
			||||||
 | 
					        Gebiet gebietMitMinDurchschnittsEinkommen = null;
 | 
				
			||||||
 | 
					        for (Gebiet g:gebiete) {
 | 
				
			||||||
 | 
					            gebietA = g.getDurchschnittsEinkommen();
 | 
				
			||||||
 | 
					            if (gebietA < gebietB && gebietA > 0) {
 | 
				
			||||||
 | 
					                gebietMitMinDurchschnittsEinkommen = g;
 | 
				
			||||||
 | 
					                gebietB = gebietA;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (gebietMitMinDurchschnittsEinkommen == null) {
 | 
				
			||||||
 | 
					            System.err.println("Fehler bei der Suche nach dem geringsten Durchschnittseinkommen.");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return gebietMitMinDurchschnittsEinkommen;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Gebiet getGebietMaxAnzahlEinwohner() {
 | 
				
			||||||
 | 
					        int gebietA = 0;
 | 
				
			||||||
 | 
					        int gebietB = 0;
 | 
				
			||||||
 | 
					        Gebiet gebietMitMaxEinwohnern = null;
 | 
				
			||||||
 | 
					        for (Gebiet g:gebiete) {
 | 
				
			||||||
 | 
					            gebietA = g.getAnzahlEinwohner();
 | 
				
			||||||
 | 
					            if (gebietA > gebietB)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                gebietMitMaxEinwohnern = g;
 | 
				
			||||||
 | 
					                gebietB = gebietA;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (gebietMitMaxEinwohnern == null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            System.err.println("Fehler bei der Suche nach den meisten Einwohnern .");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return gebietMitMaxEinwohnern;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int getAnzahlGesamt()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return gebiete.size();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int getAnzahlUnvollständig(){
 | 
				
			||||||
 | 
					        int zaehler = 0;
 | 
				
			||||||
 | 
					        for (Gebiet g:gebiete) {
 | 
				
			||||||
 | 
					            if (g.getGesamtEinkommen() <= 0 || g.getDurchschnittsEinkommen() <= 0) {
 | 
				
			||||||
 | 
					                zaehler++;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return  zaehler;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<Gebiet> getGebieteNachNamen(String namensanfang) {
 | 
				
			||||||
 | 
					        List<Gebiet> gebieteNachNamen = new ArrayList<Gebiet>();
 | 
				
			||||||
 | 
					        for (Gebiet g:gebiete) {
 | 
				
			||||||
 | 
					            if (g.getName().contains(namensanfang)){
 | 
				
			||||||
 | 
					                gebieteNachNamen.add(g);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return gebieteNachNamen;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										9
									
								
								src/GebietsListeInterface.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/GebietsListeInterface.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface GebietsListeInterface {
 | 
				
			||||||
 | 
					    Gebiet getGebietMinDurchschnittsEinkommen();
 | 
				
			||||||
 | 
					    Gebiet getGebietMaxAnzahlEinwohner();
 | 
				
			||||||
 | 
					    int getAnzahlGesamt();
 | 
				
			||||||
 | 
					    int getAnzahlUnvollständig();
 | 
				
			||||||
 | 
					    List<Gebiet> getGebieteNachNamen(String namensanfang);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user