Last active
October 1, 2020 14:09
-
-
Save Jo0001/c46e5b02e38a00e342b21531481e33e0 to your computer and use it in GitHub Desktop.
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
package aufgabe; | |
import java.util.Scanner; | |
public class Aufgabe { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
Scanner scannerInt = new Scanner(System.in); | |
System.out.println("Wie viele Noten sollen eingeben werden?"); | |
int l = scannerInt.nextInt(); | |
NotenEintrag[] notenEintraege = new NotenEintrag[l]; | |
for (int i = 0; i < l; i++) { | |
System.out.println("Name eingeben"); | |
String name = scanner.nextLine(); | |
System.out.println("Notenpunkte eingeben"); | |
notenEintraege[i] = new NotenEintrag(name, scannerInt.nextInt()); | |
System.out.println(); | |
} | |
do { | |
System.out.println("List | Listi | Exit eingeben"); | |
String command = scanner.nextLine(); | |
if (command.equalsIgnoreCase("listi")) { | |
System.out.println("Index eingeben"); | |
System.out.println(notenEintraege[scannerInt.nextInt()].toString()); | |
} else if (command.equalsIgnoreCase("list")) { | |
for (NotenEintrag notenEintrag : notenEintraege) { | |
System.out.println(notenEintrag.toString()); | |
} | |
} else { | |
System.out.println("Unbekanntes Kommando"); | |
} | |
} while (!scanner.nextLine().equalsIgnoreCase("exit")); | |
} | |
} | |
class NotenEintrag { | |
private final String name; | |
private final int punkte; | |
public NotenEintrag(String name, int punkte) { | |
this.name = name; | |
if (punkte > 15 || punkte < 1) { | |
//Hier soll eine IllegalArgumentException mit "Ungültige Notenpunkte" als Fehlermeldung ausgegeben werden | |
} | |
this.punkte = punkte; | |
} | |
public String getName() { | |
return name; | |
} | |
public int getPunkte() { | |
return punkte; | |
} | |
@Override | |
public String toString() { | |
return "NotenEintrag{" + | |
"name='" + name + '\'' + | |
", punkte=" + punkte + | |
'}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment