Difference between revisions of "Java - I/O und Exceptions"

From Coders.Bay Wiki
Jump to navigation Jump to search
Line 96: Line 96:


<font size=3><strong>Requirements</strong></font>
<font size=3><strong>Requirements</strong></font>
======InvaldName-Exception======   
======InvaldPersonName-Exception======   
When a user creates a person that has a number in the name, an "InvalidName-Exception" should be thrown.<br>
When a user creates a person that has a number in the name, an "InvalidPersonName-Exception" should be thrown.<br>
The creation of the object shall be aborted and the user should be informed that this name is invalid.<br>
The creation of the object shall be aborted and the user should be informed that this name is invalid.<br>
The program should not terminate, but ask the user to enter a new name.<br>
The program should not terminate, but ask the user to enter a new name.<br>

Revision as of 06:46, 28 March 2023

Exceptions

Aufgabe: Erweitere die Personenverwaltung um Exceptions

Die, in der früheren Aufgabe erstellte, Personenverwaltung, soll nun etwas sicherer für Fehler gemacht werden.
Erweitere den Code so, dass der User die Personen mit Hilfe eines Scanners erstellt.
Dabei soll auf ungültige Inputs vernünftig reagiert werden, ohne dass das Programm abstürzt.

Requirements

InvaldPersonName-Exception

Wenn ein Nutzer eine Person anlegt, die eine Zahl im Namen hat, soll eine "InvalidPersonName-Exception" geworfen werden.
Die Anlegung des Objektes soll abgebrochen werden und der Nutzer informiert, dass dieser Name ungültig ist.
Das Programm soll nicht terminieren, sondern den Nutzer erneut bitten einen Namen einzugeben.

NullpointerException

Der Nutzer soll Personen durch ihren Namen finden können.
Wird ein Name eingegeben, der nicht existiert, soll eine NullpointerException in der Personalverwaltung geworfen werden.
Der Stacktrace dieser Exception soll in der Main ausgegeben werden.
Das Programm soll nicht terminieren und weitere Inputs erhalten.

Terminierung

Das Programm soll nur durch die Eingabe von ":q!" terminierbar sein.

File I/O

Aufgabe: Nutze die CSV-Dateien um ein Pokémon Arena Spiel zu erstellen

Mit den zur Verfügung gestellten Datensätzen soll der Arenakampf von Pokémon nachgebaut werden.
Der User soll ein Pokémon Team auswählen und mithilfe verschiedener Attacken ein gegnerisches Pokémon Team, welches vom Computer gesteuert wird, bekämpfen.

Requirements

CSV Einlesen

Importiere die Pokémon CSV und Attack CSV aus dem Kompetenzcenter in dein Projekt.
Lese die Daten ein und erstelle daraus die notwendigen Klassen.
Jedes Pokémon soll vier zufällige Attacken bekommen. Mindestens eine davon soll vom Typ Normal sein und mindestens eine Attacke soll dem Typ des Pokemon entsprechen.

Auswahl

Beide Spieler sollen sechs Pokémon erhalten. Das gleiche Pokémon kann mehrfach vorkommen.
Wenn ein Pokémon selektiert wird, wird sein Level zufällig von 10 bis 100 ausgewürfelt. Die Werte des Pokémon skalieren mit dem Level.
Für jedes Level erhöhen sich die HP um 1/25 pro Level, die Att/Def/Sp.Att/Sp.Def um 1/50 pro Level und die Speed um 1/100 pro Level.
Der Nutzer kann zu Beginn des Spiels das erste Pokémon durch Angabe der Index-Nummer oder dem Namen wählen, dieses wird für den Kampf ausgewählt.
Anschließend werden fünf zufällige weitere hinzugefügt.
Gib auf der Konsole aus, um welche Pokémon es sich handelt und welche Werte und mögliche Attacken es hat.
Die gegnerischen Pokémon wählt der Computer zufällig.

Kampf

Nach der Selektion soll der Kampf gestartet werden.
Zu Beginn des Kampfs werden dem Nutzer die Werte all seiner Pokémon ausgegeben.
Der Nutzer kann eines der Pokémon auswählen. Dieses kommt in den Kampf gegen ein zufälliges des gegnerischen Teams.
Haben beide Spieler ein Pokémon ausgewählt, beginnt der Kampf.

Dem Nutzer werden die vier Attacken aufgelistet. Zusätzlich noch die Möglichkeit ein neues Pokémon zu wählen und die Möglichkeit den Kampfverlauf automatisch zu beenden.
Wählt der Nutzer einen Angriff aus der Liste, versucht das Pokémon anzugreifen.
Wenn die gewählte Attacke keine Powerpoints (PP) hat, kann sie nicht ausgeführt werden.
Wenn die Attacke ausgeführt wird, dann beginnt die Schadensberechnung.

Schadensberechnung

Der Schaden berechnet sich wie folgt:

Schaden = (Atk_Pw) * (APk_A / DPk_D) * (Lvl / 50) * Rnd * STAB

Atk_Pw = Power Wert der Attacke, die Ausgewählt wurde
APk_A = Attack Wert des angreifenden Pokémon , falls der Angriff ein Physical kind ist. Special Attack Wert, falls es ein Special kind ist
DPk_D = Defense Wert des verteidigenden Pokémon , falls der Angriff ein Physical kind ist. Special Defense Wert, falls der Angriff ein Special kind ist
Lvl = Das Level des angreifenden Pokémon
50 = Die Zahl 50
Rnd = Zufälliger Wert zwischen 0,5 und 1,5
STAB = 1,25 Falls der Type des Angriffs einem der Types des Pokémon entspricht, sonst 1

Das Pokémon mit dem größeren Speed Wert greift zuerst an. Verliert das angegriffene Pokémon bevor es angegriffen hat, wird der Angriff übersprungen.

Zusatzaufgabe Effektivität

Erweitere die Schadensberechnung und berücksichtige die Typen des Angriffs und des verteidigenden Pokémon.

Schaden = (Atk_Pw) * (APk_A / DPk_D) * (Lvl / 50) * Rnd * STAB * Eff1 * Eff2

Eff1 = Effektivität des Angriffs gegen Typ1 des verteidigenden Pokémon
Eff2 = Effektivität des Angriffs gegen Typ2 des verteidigenden Pokémon

Nutze die Effectiveness.csv Datei, um die Koeffizienten zu ermitteln.

English

Exceptions

Task: Add exceptions to the person management

The person administration, that was created in the previous task, should now be made more resilient to errors.
Extend the code so the user can create the people through a scanner.
React properly to invalid inputs by using Exceptions to change Control Flow.

Requirements

InvaldPersonName-Exception

When a user creates a person that has a number in the name, an "InvalidPersonName-Exception" should be thrown.
The creation of the object shall be aborted and the user should be informed that this name is invalid.
The program should not terminate, but ask the user to enter a new name.

NullpointerException

The user should be able to find people by name.
If a name is entered that does not exist, a NullpointerException should be thrown in the person management.
The stacktrace of this exception should be printed in the main method.
The program shall not terminate and receive new inputs from the user.

Termination

The execution of the program shall only stop for the user input ":q!"


File I/O

Task: Use the CSV files to create a Pokémon Arena game


Use the provided data sets to recreate the arena battle of Pokemon.
The user is to select a Pokemon team and use different attacks to fight an opposing Pokemon team controlled by the computer.

CSV Import

Import the Pokémon CSV and Attack CSV from the Competence Center into your project.
Read the data and create the necessary classes from it.
Each Pokemon should have four random attacks. At least one of them should be of type Normal and at least one attack should correspond to the Pokemon's type.

Select

Both players shall receive six Pokemon. The same Pokemon may appear more than once.
When a Pokemon is selected, its level is randomly rolled from 10 to 100. The Pokémon 's stats scale with its level.
For each level, HP increases by 1/25 per level, Att/Def/Sp.Att/Sp.Def increases by 1/50 per level, and Speed increases by 1/100 per level.
The user can choose the first Pokémon at the beginning of the game by specifying the index number or name of the Pokémonm that will be selected for battle.
After that, five random others are added.
Display the selected team of the player on the console.
The opposing Pokémon will be chosen randomly by the computer.

Fight

After the selection, the fight should be started.
At the beginning of the fight, the user is given the stats of all his Pokémon.
The user can select one of the Pokémon. The chosen one fights against a random one of the opposing team.
When both players have selected a Pokémon, the battle starts.

The four attacks are listed to the user. In addition, the possibility to choose a new Pokémon and the possibility to conclude the fight automatically.
If the user chooses an attack from the list, the Pokémon tries to attack.
If the selected attack has no power points (PP), it cannot be executed.
If the attack is executed, then the damage calculation starts.

DamageCalculation

Damage is calculated as follows:

Damage = (Atk_Pw) * (APk_A / DPk_D) * (Lvl / 50) * Rnd * STAB

Atk_Pw = Power value of the attack that was Selected
APk_A = Attack value of the attacking Pokemon, if the attack is a Physical kind. Special Attack value, if it is a Special kind
DPk_D = Defense value of the defending Pokemon, if the attack is a Physical kind. Special Defense value if the attack is a Special kind
Lvl = The level of the attacking Pokemon
50 = The number 50
Rnd = Random value between 0.5 and 1.5
STAB = 1.25 If the Type of the attack matches one of the Pokemon's Types, otherwise 1

The Pokemon with the greater Speed value attacks first. If the attacked Pokemon loses before it has attacked, the attack is skipped.

Additional Task Effectivness

Expand the damage calculation to take into account the types of the attacking and defending Pokemon.

Damage = (Atk_Pw) * (APk_A / DPk_D) * (Lvl / 50) * Rnd * STAB * Eff1 * Eff2

Eff1 = Effectiveness of attack against type1 of defending Pokemon
Eff2 = Effectiveness of attack against type2 of defending Pokemon

Use the Effectiveness.csv file to determine the coefficients.