Java Advanced Exam - 22 Feb 2020 problem 03. Guild 88/100
Здравейте,
От изпита Java Advanced Exam - 22 Feb 2020 на задача 03.Guild последният 9-ти тест гърми. Предполагам, че методът
kickPlayersByClass(String clazz) е причината теста да гърми, но не мога да намеря грешката.
Player class-a -> https://pastebin.com/V2EdbHRb
Guild class-a -> https://pastebin.com/RE0Xw4mX
Main class-a -> https://pastebin.com/XbKtEQ6s
Линк към Judge -> https://judge.softuni.org/Contests/Practice/Index/2036#2
Условието на задачата:
Your task is to create a repository which stores players by creating the classes described below.
Player
First, write a Java class Player with the following fields:
- name: String
- clazz: String
- rank: String – "Trial" by default
- description: String – "n/a" by default
The class constructor should receive name and clazz. You need to create the appropriate getters and setters. Override the toString() method in the following format:
"Player {name}: {clazz}
Rank: {rank}
Description: {description}"
Guild
Next, write a Java class Guild that has a roster (a collection which stores Player entities). All entities inside the repository have the same fields. Also, the Guild class should have those fields:
- name: String
- capacity: int
The class constructor should receive name and capacity, also it should initialize the roster with a new instance of the collection. Implement the following features:
- Method addPlayer(Player player) - adds an entity to the roster if there is room for it
- Method removePlayer(String name) - removes a player by given name, if such exists, and returns boolean
- Method promotePlayer(String name) - promote (set his rank to "Member") the first player with the given name. If the player is already a "Member", do nothing.
- Method demotePlayer(String name)- demote (set his rank to "Trial") the first player with the given name. If the player is already a "Trial", do nothing.
- Method kickPlayersByClass(String clazz) - removes all the players by the given class and returns all removed players from that class as an array
- Method count() - returns the number of players
- Method report() - returns a String in the following format:
- "Players in the guild: {guildName}:
{Player1}
{Player2}
(…)"
- "Players in the guild: {guildName}:
Constraints
- The names of the players will be always unique.
- You will always have a player added before receiving methods manipulating the Guild's players.
Examples
This is an example how the Guild class is intended to be used.
Sample code usage |
package guild; //Player Mark: Rogue |
Благодаря, действително това е проблема