Quidditch – Part 1
The Quidditch application will cover:
Stream Pipelines
HashMap
(new)hashCode()
(new)static variables
static final constants
static methods
Setup
requirements.txt
Objects: Team
and Game
.
Team
:- fields:
house
,keeper
,seeker
, andchasers
.
- fields:
Game
:- fields:
scoreBoard
. - actions: see test cases.
- constants:
QUAFFLE_POINTS
andSNITCH_POINTS
.
- fields:
Task 1
Add the necessary fields to the Team
class. Protect each field using the private
keyword.
Task 2
Add a constructor. The constructor parameters are String house
, String keeper
, String seeker
, String[] chasers
.
Task 3
Add a copy constructor.
Task 4
Add getters and setters.
Task 5
Add a toString
method that returns the following:
return "House: " + this.house + "\n" +
"Keeper: " + this.keeper + "\n" +
"Seeker: " + this.seeker + "\n" +
"Chasers: " + Arrays.toString(this.chasers) + "\n";
Task 6
Test your code by creating two objects of the Team
class:
new Team("GRYFFINDOR", "Oliver", "Harry",
new String[] {"Angelina", "Ginny", "Katie"});
new Team("SLYTHERIN", "Vincent", "Draco",
new String[] {"Bridget", "Harper", "Malcolm"});
Finally, print each object:
>>: House: GRYFFINDOR
>>: Keeper: Oliver
>>: Seeker: Harry
>>: Chasers: [Angelina, Ginny, Katie]
>>: House: SLYTHERIN
>>: Keeper: Vincent
>>: Seeker: Draco
>>: Chasers: [Bridget, Harper, Malcolm]
Your terminal should point to the folder quidditch-game
.
But, Main.java
is inside src/main
. I recommend just using the run button. Keep pressing "Proceed" until the errors go away.
Alternatively, if you feel like writing out the commands:
-
Mac users: write
javac
src/main
/Main.java
. -
Windows users: write
javac
src\main
\Main.java
.
Mac uses /
forward-slash for paths. Windows uses backslash \
.