Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Mannschaft {
- private String name;
- private int tore;
- private int gegentore;
- private int siege;
- private int niederlagen;
- private int unentschieden;
- public Mannschaft(String name){
- this.name = name;
- this.tore = 0;
- this.gegentore = 0;
- this.siege = 0;
- this.niederlagen = 0;
- this.unentschieden = 0;
- }
- public String getName(){
- return this.name;
- }
- public int getTore(){
- return this.tore;
- }
- public int getGegentore(){
- return this.gegentore;
- }
- public int getPunkte(){
- return siege * 3 + unentschieden;
- }
- public int getSpiele(){
- return siege + niederlagen + unentschieden;
- }
- public int getTorDifferenz(){
- return tore - gegentore;
- }
- public void eintragenErgebnis(int tore, int gegentore){
- if (tore > gegentore){
- this.siege++;
- }else if (tore == gegentore){
- this.unentschieden++;
- }else {
- this.niederlagen++;
- }
- this.tore += tore;
- this.gegentore += gegentore;
- }
- public void print(){
- System.out.println(this.name + "\tTD:" +
- this.getTorDifferenz() + "\tPKT:" +
- this.getPunkte() + "\t\tS:"+
- this.siege + "\t\tU:" +
- this.unentschieden+ "\t\tN:" +
- this.niederlagen );
- }
- }
- // Klasse Tabelle
- package alexander_treise_bundesliga;
- public class Tabelle {
- private static String[] namen = {"Schalke 04", "Bayer 04", "FC Bayern", "Werder", "HSV", "Dortmund", "Hoffenheim", "Mainz 05", "Wolfsburg", "Eintracht",
- "M'gladbach", "Freiburg", "Hannover", "1.FC Köln", "Stuttgart", "Bochum", "Nürnberg", "Hertha BSC"};
- private static final int LIGA_GROESSE = namen.length;
- private Mannschaft[] team;
- private Mannschaft[] tabelle = new Mannschaft[namen.length];
- public Tabelle(){
- team = new Mannschaft[namen.length];
- for (int i = 0; i <namen.length ; i++) {
- team[i] = new Mannschaft(namen[i]);
- }
- }
- public boolean spielen(String heim, String gast, int heimTore, int gastTore){
- boolean rc = false;
- int indexH;
- for(indexH = 0; indexH < namen.length; indexH++){
- if (heim.equalsIgnoreCase(team[indexH].getName())){
- break;
- }
- }
- int indexG;
- for (indexG = 0; indexG < namen.length;indexG++){
- if (gast.equalsIgnoreCase(team[indexG].getName())){
- break;
- }
- }
- if (indexH<LIGA_GROESSE && indexG<LIGA_GROESSE && indexH != indexG){
- team[indexH].eintragenErgebnis(heimTore,gastTore);
- team[indexG].eintragenErgebnis(gastTore,heimTore);
- rc = true;
- }
- return rc;
- }
- public void print(){
- Mannschaft[] teamTemp = new Mannschaft[namen.length];
- for (int i = 0; i <team.length ; i++) {
- for (int j = 1; j <team.length-i ; j++) {
- if (team[j].getPunkte()>team[j-1].getPunkte()){
- teamTemp[i]=team[j-1];
- team[j-1]=team[j];
- team[j]=teamTemp[i];
- }
- }
- }
- System.out.println("R. \tName \t\tTorDi. \tPunkte \t\tSiege \tUnents. Niederl.");
- for (int i = 0; i < namen.length;i++) {
- System.out.print(i + "\t");
- team[i].print();
- }
- }
- public static void main(String[] args) {
- Tabelle bundesliga = new Tabelle();
- bundesliga.spielen("FC Bayern","Werder",3,1);
- bundesliga.spielen("Werder","FC Bayern",1,3);
- bundesliga.spielen("Schalke 04","HSV",1,1);
- bundesliga.spielen("HSV","Schalke 04",1,1);
- bundesliga.spielen("Hannover","Hoffenheim",1,2);
- bundesliga.spielen("Hoffenheim","Hannover",2,1);
- bundesliga.spielen("Eintracht","Mainz 05",4,2);
- bundesliga.spielen("Mainz 05","Eintracht",0,2);
- bundesliga.print();
- }
- }
- Ausgabe:
- R. Name TorDi. Punkte Siege Unents. Niederl.
- 0 FC Bayern TD:4 PKT:6 S:2 U:0 N:0
- 1 Hoffenheim TD:2 PKT:6 S:2 U:0 N:0
- 2 Eintracht TD:4 PKT:6 S:2 U:0 N:0
- 3 Schalke 04 TD:0 PKT:2 S:0 U:2 N:0
- 4 HSV TD:0 PKT:2 S:0 U:2 N:0
- 5 Bayer 04 TD:0 PKT:0 S:0 U:0 N:0
- 6 Werder TD:-4 PKT:0 S:0 U:0 N:2
- 7 Dortmund TD:0 PKT:0 S:0 U:0 N:0
- 8 Mainz 05 TD:-4 PKT:0 S:0 U:0 N:2
- 9 Wolfsburg TD:0 PKT:0 S:0 U:0 N:0
- 10 M'gladbach TD:0 PKT:0 S:0 U:0 N:0
- 11 Freiburg TD:0 PKT:0 S:0 U:0 N:0
- 12 Hannover TD:-2 PKT:0 S:0 U:0 N:2
- 13 1.FC Köln TD:0 PKT:0 S:0 U:0 N:0
- 14 Stuttgart TD:0 PKT:0 S:0 U:0 N:0
- 15 Bochum TD:0 PKT:0 S:0 U:0 N:0
- 16 Nürnberg TD:0 PKT:0 S:0 U:0 N:0
- 17 Hertha BSC TD:0 PKT:0 S:0 U:0 N:0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement