Compare commits
	
		
			14 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					e1a7f69bc7 | ||
| 90a323ce01 | |||
| 0643732d08 | |||
| 7ca888121d | |||
| da5bcc93bf | |||
| 
						 | 
					81b4cbeb7e | ||
| 
						 | 
					aab1fe68d7 | ||
| 
						 | 
					8382a47d7e | ||
| daf0ec541d | |||
| 268f4eee43 | |||
| a2bd838467 | |||
| 78dfa848fa | |||
| 
						 | 
					2562126caa | ||
| 9c6592fbff | 
@@ -1,5 +1,3 @@
 | 
			
		||||
Jahr;Schlüssel;Region;verfügbares Einkommen der privaten Haushalte;verfüg. Einkommen der priv. Haushalte je Einwohner
 | 
			
		||||
;;;Tsd. EUR;EUR
 | 
			
		||||
2016;01001;Flensburg, Kreisfreie Stadt;1602046;18481
 | 
			
		||||
2016;01002;Kiel, Landeshauptstadt, Kreisfreie Stadt;4643584;18810
 | 
			
		||||
2016;01003;Lübeck, Hansestadt, Kreisfreie Stadt;4237638;19575
 | 
			
		||||
 
 | 
			
		||||
		
		
			
  | 
							
								
								
									
										35
									
								
								src/EinkommenInfo.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/EinkommenInfo.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
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 datei = new GebietsDatei("Einkommen.csv");
 | 
			
		||||
        List<Gebiet> gebiet = datei.getGebiete();
 | 
			
		||||
        GebietsListe gebietsListe = new GebietsListe(gebiet);
 | 
			
		||||
 | 
			
		||||
        System.out.println(gebietsListe.getAnzahlGesamt() + " Gebiete wurden eingelesen.");
 | 
			
		||||
        System.out.println(gebietsListe.getAnzahlUnvollstaendig() + " davon haben unvollständige Angaben.\n");
 | 
			
		||||
 | 
			
		||||
        System.out.println("Gebiet mit dem geringsten Durchschnittseinkommen:");
 | 
			
		||||
        System.out.println(gebietsListe.getGebietMinDurchschnittEinkommen());
 | 
			
		||||
 | 
			
		||||
        System.out.println("Gebiet mit der größten Einwohernzahl:");
 | 
			
		||||
        System.out.println(gebietsListe.getGebietMaxEinwohner());
 | 
			
		||||
 | 
			
		||||
        Scanner sc = new Scanner(System.in);
 | 
			
		||||
        while (true) {
 | 
			
		||||
            System.out.print("Name des Gebietes: ");
 | 
			
		||||
            String input = sc.nextLine();
 | 
			
		||||
            if (input.isEmpty()) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            List<Gebiet> foundAreas = gebietsListe.getGebietNachNamen(input);
 | 
			
		||||
            for (Gebiet area : foundAreas) {
 | 
			
		||||
                System.out.println(area);
 | 
			
		||||
            }
 | 
			
		||||
            System.out.println(foundAreas.size() + " Gebiete wurden gefunden.\n");
 | 
			
		||||
        }
 | 
			
		||||
        sc.close();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
 | 
			
		||||
public class Gebiet implements GebietInterface{
 | 
			
		||||
public class Gebiet implements GebietInterface {
 | 
			
		||||
    private int jahr;
 | 
			
		||||
    private int schlüssel;
 | 
			
		||||
    private String name;
 | 
			
		||||
@@ -31,16 +30,31 @@ public class Gebiet implements GebietInterface{
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public long getGesamtEinkommen() {
 | 
			
		||||
        if (gesamtEinkommen <= 0) {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
        return gesamtEinkommen;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getDurchschnittsEinkommen() {
 | 
			
		||||
        if (durchschnittsEinkommen <= 0) {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
        return durchschnittsEinkommen;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getAnzahlEinwohner() {
 | 
			
		||||
        return 0;
 | 
			
		||||
        return (int) (gesamtEinkommen * 1000 / durchschnittsEinkommen);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        if (getDurchschnittsEinkommen() <= 1 || getGesamtEinkommen() <= 1) {
 | 
			
		||||
            return getName() + "\n" + "Einwohnerzahl unbekannt\n" + "Durchschnittseinkommen unbekannt\n";
 | 
			
		||||
        }
 | 
			
		||||
        return getName() + "\n" + getAnzahlEinwohner() + " Einwohner\n" + getDurchschnittsEinkommen()
 | 
			
		||||
                + " Euro / Einwohner\n";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,9 @@ public class GebietsDatei {
 | 
			
		||||
        try {
 | 
			
		||||
            Files.readAllLines(Paths.get(dateiName)).forEach(line -> {
 | 
			
		||||
                String[] parts = line.split(";");
 | 
			
		||||
                gebiete.add(new Gebiet(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), parts[2], Long.parseLong(parts[3]), Integer.parseInt(parts[4])));
 | 
			
		||||
                gebiete.add(new Gebiet(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), parts[2],
 | 
			
		||||
                        (parts[3].equals("-")) ? -1 : Long.parseLong(parts[3]),
 | 
			
		||||
                        (parts[4].equals("-")) ? -1 : Integer.parseInt(parts[4])));
 | 
			
		||||
            });
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,40 @@
 | 
			
		||||
public class GebietsListe {
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class GebietsListe {
 | 
			
		||||
    private List<Gebiet> gebiete = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    public GebietsListe(List<Gebiet> gebiete) {
 | 
			
		||||
        this.gebiete = gebiete;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Gebiet getGebietMinDurchschnittEinkommen() {
 | 
			
		||||
        return gebiete.stream()
 | 
			
		||||
                .filter(g -> g.getDurchschnittsEinkommen() != -1)
 | 
			
		||||
                .min((g1, g2) -> g1.getDurchschnittsEinkommen() - g2.getDurchschnittsEinkommen())
 | 
			
		||||
                .get();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Gebiet getGebietMaxEinwohner() {
 | 
			
		||||
        return gebiete.stream()
 | 
			
		||||
                .filter(g -> g.getDurchschnittsEinkommen() != -1)
 | 
			
		||||
                .max((g1, g2) -> g1.getAnzahlEinwohner() - g2.getAnzahlEinwohner())
 | 
			
		||||
                .get();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getAnzahlGesamt() {
 | 
			
		||||
        return gebiete.size();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getAnzahlUnvollstaendig() {
 | 
			
		||||
        return (int) gebiete.stream()
 | 
			
		||||
                .filter(g -> g.getDurchschnittsEinkommen() == -1 || g.getGesamtEinkommen() == -1)
 | 
			
		||||
                .count();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<Gebiet> getGebietNachNamen(String namensanfang) {
 | 
			
		||||
        return gebiete.stream()
 | 
			
		||||
                .filter(g -> g.getName().startsWith(namensanfang))
 | 
			
		||||
                .toList();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
public class Main {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        System.out.println("Hello world!");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user