A08
Due Date:
Friday, November 24
File(s) to be submitted:
Pirate.java, Ship.java
Sample Output:
SampleOutput.html
Starter Files:
SUBMIT
/
Check
Summary
The world of "One Piece" is filled with pirates
who are led by their dreams.
Each notable pirate is known by their bounty—the amount of money (Belly)
which the World Government wants for their head.
Pirate crews consist of members,
each with a specific role.
In this assignment,
you will implement two classes,
Pirate and Ship,
that capture these concepts.
Onward to adventure!
Details
Implement the
Pirate and Ship classes as described below:
Pirate
- Implement variables:
- name, dream, bounty: instance variables (bounty should be integer)
- highestBounty: class variable
that tracks the highest bounty among all the pirates
(think about where the best place is to update this variable)
- Implement two constructors:
- One that accepts name, dream, and bounty.
- Another that accepts just name and dream and initializes bounty to 0.
- Utilize the keyword this
to call one constructor from another one.
- Implement the methods:
- Getters for all instance variables in this class:
getName(),
getDream(), and
getBounty()
- increaseBounty(int amount):
to increase the bounty on the pirate.
Bounties can only go up,
so the amount must be 0 or more, or the change is rejected
with an error message (do not throw an exception).
Note:
This is not a setter.
The new bounty depends not only on the amount given,
but also on what the bounty was before.
That's why it's not called
setBounty.
- isMostWantedPirate():
To check if this pirate has the highest bounty.
It should return true if a bounty for this pirate
equals the amount of the highestBounty
and false otherwise.
(That means it is possible for two or more pirates
to be the most wanted,
if they have the same bounty and it is equal to the highest bounty.
The method returns true for all those pirates.)
- getHighestBounty(): to retrieve the amount of the highest bounty.
(Note that it does not need to know
who any of the most wanted pirates is,
and that the answer does not depend on which pirate you ask.)
- toString(): To return a string representation of the pirate
(see the sample run for the exact String representation of a pirate)
Ship
- Implement variables:
- name: the name of this ship
- crewName: the name this crew is known by (collectively)
- captain, swordsman, navigator (all of type Pirate)
- Implement a constructor:
- Accepts the ship's name and the name its crew is known by
(the captain, swordsman and navigator should be set to null)
- Implement the methods:
- getters for all instance variables in this class:
getName(),
getCrewName(),
getCaptain(),
getSwordsman(), and
getNavigator()
- methods to appoint officers of the ship:
- setCaptain(Pirate pirate): to set/change the captain of the ship
- setSwordsman(Pirate pirate): to set/change the swordsman
- setNavigator(Pirate pirate): to set/change the navigator
Note:
The getters and setters are not just working with the names
of the Pirates.
You must give setCaptain an actual Pirate object,
not just a String.
Likewise the getters return Pirate objects,
not just Strings.
- printDetails to display the ship's information
as shown in the sample run.
A08Tester
You are given the A08Tester.java file to test your code.
If you get the same output as in the sample output
when you run the A08Tester program,
then it's very likely that you have done everything correctly.
Grading Outline
- 5 points: the Pirate class has all instance variables declared properly
- 5 points: the Pirate class has all class variables declared properly
- 10 points: Proper implementation of the Pirate class constructor with three parameters.
- 5 points: Proper implementation of the Pirate class constructor with two parameters.
- 5 points: Correct implementation of the getter methods in the Pirate class.
- 5 points: Correct implementation of the increaseBounty method in the Pirate class.
- 5 points: Correct implementation of the isMostWantedPirate method in the Pirate class.
- 5 points: Correct implementation of the getHighestBounty static method.
- 10 points: Correct implementation of the toString method in the Pirate class.
- 5 points: the Ship class has all instance variables declared properly
- 10 points: Correct implementation of the Ship class constructor.
- 5 points: Correct implementation of the getter methods in the Pirate class
- 5 points: Correct implementation of the setter methods in the Ship class.
- 5 points: Proper implementation of the printDetails method in the Ship class.
- 15 points: Proper code formatting and Javadocs as required for the course
SUBMIT
/
Check