A
Adler13
Hallo.
Ich habe folgendes Problem. Ich habe dieses Programm geschrieben - weiß allerdings nicht wie es sortieren kann?! Es soll nach Gold, Silber, Bronze sortiert werden.
Da ich relativ "neu" in Java bitte ich euch um Hilfe. Danke.
-------------------------------------------Main-Programm---------------------------------------------
Ich habe folgendes Problem. Ich habe dieses Programm geschrieben - weiß allerdings nicht wie es sortieren kann?! Es soll nach Gold, Silber, Bronze sortiert werden.
Da ich relativ "neu" in Java bitte ich euch um Hilfe. Danke.
-------------------------------------------Main-Programm---------------------------------------------
Java:
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args)throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Land> laender = new ArrayList<Land>();
char eingabe;
char eingabe2;
boolean abbruch = false;
boolean abbruch2 = false;
while (abbruch == false)
{
Land L = new Land();
System.out.println("Medaillenspiegel");
System.out.print("Bitte geben Sie das Land ein: ");
L.Team = input.readLine();
System.out.print("Goldmedaillen: ");
L.gold = Integer.parseInt(input.readLine());
System.out.print("Silbermedaillen: ");
L.silber = Integer.parseInt(input.readLine());
System.out.print("Bronzemedaillen: ");
L.bronze = Integer.parseInt(input.readLine());
System.out.println("");
laender.add(L);
System.out.print("Wollen Sie noch ein Land eingeben? (J/N):");
System.out.print("");
eingabe = input.readLine().charAt(0);
System.out.print("");
if ((eingabe == 'N') || (eingabe == 'n'))
{
abbruch = true;
}
}
System.out.println("");
System.out.print("Medaillenspiegel");
System.out.println("");
for(Land Nation: laender)
{
System.out.println(Nation.Team + " Gold: " + Nation.gold + " | Silber: " + Nation.silber + " | Bronze: " + Nation.bronze);
}
while (abbruch2 == false )
{
System.out.println("");
System.out.print("Wollen Sie Medaillen editieren? (J/N): ");
eingabe2 = input.readLine().charAt(0);
if ((eingabe2 == 'J') || (eingabe2 == 'j'))
{
System.out.print("Gold(G) Silber(S) Bronze(B): ");
eingabe2 = input.readLine().charAt(0);
if ((eingabe2 == 'G') || (eingabe2 == 'g'))
{
System.out.print("Bei Welchen Land wollen Sie die Medaille editieren?");
String strland = input.readLine();
for(Land Nation: laender)
{
if(Nation.Team.contains(strland))
{
System.out.print("Wieviel +(Zahl) / -(-Zahl)?");
int anzahl = Integer.parseInt(input.readLine());
Nation.gold += anzahl;
break;
}
}
}
if ((eingabe2 == 'S') || (eingabe2 == 's'))
{
System.out.print("Bei Welchen Land wollen Sie die Medaille editieren?");
String strland = input.readLine();
for(Land Nation: laender)
{
if(Nation.Team.contains(strland))
{
System.out.print("Wieviel +(Zahl) / -(- Zahl)?");
int anzahl = Integer.parseInt(input.readLine());
Nation.silber += anzahl;
break;
}
}
}
if ((eingabe2 == 'B') || (eingabe2 == 'b'))
{
System.out.print("Bei Welchen Land wollen Sie die Medaille editieren?");
String strland = input.readLine();
for(Land Nation: laender)
{
if(Nation.Team.contains(strland))
{
System.out.print("Wieviel +(Zahl) / -(- Zahl)?");
int anzahl = Integer.parseInt(input.readLine());
Nation.bronze += anzahl;
break;
}
}
}
for(Land Nation: laender)
{
System.out.print("Nation: " + Nation.Team + " Gold: " + Nation.gold + " | Silber: " + Nation.silber + " | Bronze: " + Nation.bronze + "\n");
}
}
if ((eingabe2 == 'N') || (eingabe2 == 'n'))
{
abbruch2 = true;
System.out.print("--Programmende--");
}
}
}
}
-------------------------------------------------Klasse-Land-------------------------------------------
public class Land
{
public String Team;
public int gold;
public int silber;
public int bronze;
public Land()
{
Team = "";
gold = 0;
silber = 0;
bronze = 0;
}
}
Zuletzt bearbeitet von einem Moderator: