Created
June 19, 2013 08:38
-
-
Save Ichag/5812694 to your computer and use it in GitHub Desktop.
A little Java-"Program"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Anwendung { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
List<Land> laender = new ArrayList<Land>(); | |
Land nrw = new Bundesland("Nordrhein-Westfalen"); | |
Land he = new Bundesland("Hessen"); | |
Stadt f = new Stadt ("Frankfurt", false); | |
Stadt wi = new Stadt ("Wiesbaden", true); | |
Stadt d = new Stadt ("Duesseldorf", true); | |
Stadt bi = new Stadt("Bielefeld", false); | |
laender.add(nrw); | |
laender.add(he); | |
Collections.sort(laender); | |
for(Land land: laender) { | |
System.out.println(land); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class Bundesland extends Land { | |
public Bundesland(String name) { | |
super(name); | |
} | |
@Override | |
public int compareTo(Land vergleichsLand) { | |
return this.getName().compareTo(vergleichsLand.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public abstract class Land implements java.lang.Comparable<Land> { | |
private String name; | |
private List<Stadt> staedteListe = new ArrayList<Stadt>(); | |
public Land(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public void setStadt (Stadt pStadt) { | |
staedteListe.add(pStadt); | |
} | |
public Stadt getStadt(int pos) { | |
return staedteListe.get(pos); | |
} | |
public Stadt getHauptstadt() { | |
for (Stadt s: staedteListe) { | |
if (s.isCapital()) | |
return s; | |
} | |
return null; | |
} | |
@Override | |
public String toString() { | |
String output = "Name: " + this.getName(); | |
return output; | |
} | |
@Override | |
public int compareTo(Land vergleichsLand) { | |
return this.getName().compareTo(vergleichsLand.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Stadt implements Comparable<Stadt> { | |
private String name; | |
private boolean isCapital; | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public boolean isCapital() { | |
return isCapital; | |
} | |
public void setCapital(boolean isCapital) { | |
this.isCapital = isCapital; | |
} | |
public Stadt(String name, boolean isCapital) { | |
this.name = name; | |
this.isCapital = isCapital; | |
} | |
public int compareTo(Stadt vergleichsStadt) { | |
return this.getName().compareTo(vergleichsStadt.getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment