Write a main method for SpacePirate. It should first initialize two SpacePirates with a crew size of 1 (just themselves) and the other values as you like. Then, have the first one try to pay their bounty. Next, use an appropriate method call to form a new crew made up of these two pirates and any spaceship. Finally, print the String representation of both pirates. You do not need to show the output.
Fill in the four blanks so that randomValue has a random int…
Fill in the four blanks so that randomValue has a random integer value between 9 and 99, both ends inclusive. int randomValue = __1__ (__2__.random() * __3__) + __4__; Use this template for your answer (please type fully – you cannot copy): 1: 2: 3: 4:
Can we override private methods? If so, explain a scenario i…
Can we override private methods? If so, explain a scenario in which we would do so. If not, explain why.
Please read carefully: The remaining questions from this exa…
Please read carefully: The remaining questions from this exam are all part of the same problem, divided into many smaller questions. You will be asked to write 2 classes: Pirate (an abstract class) and SpacePirate (a concrete class, and child of Pirate). Each question will indicate the part and class you will be working on. Do NOT write getters and setters unless otherwise indicated. You won’t need any that are not indicated (and you cannot use any that are not indicated). Do NOT write Javadocs. All your constructors and methods should be visible to all classes unless otherwise noted in their description. All your instance variables and class variables should have the strictest visibility modifier. When asked for constructors or methods, do not repeat the class header or any other code. Constructors and setters must use parameter names that are the same as the related instance variable(s). You should use constructor chaining in all constructors where it can be properly applied. Your chaining must reduce the necessary code in the constructors as much as possible. You don’t need null-checks for Strings or arrays. Syntax, capitalization, and spelling matter. Canvas Tip for all Qs: Click on the dropdown that says “Paragraph” and switch to “Preformatted” to get a monospaced font – this can help in coding answers The questions begin below.
Constructor chaining … (select one)
Constructor chaining … (select one)
Write the class header and the variable declarations (a clas…
Write the class header and the variable declarations (a class without constructors or methods, with correct syntax) for Pirate (an abstract class). Besides a name, a Pirate has a bounty that represents the reward for capturing the pirate and an amount of gold that reflects the Pirate’s wealth. Pirate has the following variables: name (String) bounty (int) gold (int) pirateCount (this variable, an int, is shared between all instances and keeps track of how many pirates exist. Make sure it starts at 0)
Inheritance reduces the need to ______________ existing code…
Inheritance reduces the need to ______________ existing code. (select one)
Write a method for Pirate called payBounty. This method does…
Write a method for Pirate called payBounty. This method doesn’t take any parameters or return a value. The pirate will pay as much of their bounty as possible. If the amount of gold they have meets or exceeds their bounty, it will deduct the bounty from the gold and set the bounty to 0. Otherwise, the pirate will pay as much of their bounty as possible by deducting the gold from their bounty and setting their gold to 0. Tip: This is equivalent to deducting the minimum of bounty and gold from the two instance variables.
[EXTRA CREDIT] Write an equals method for SpacePirate. Two i…
Write an equals method for SpacePirate. Two instances of SpacePirate are equal if their parent’s variables are equal and if they have the same crewSize and spaceship. You must use the parent’s equals method for credit.
Write a constructor for SpacePirate. The constructor will ta…
Write a constructor for SpacePirate. The constructor will take the name, bounty, gold, crewSize, and spaceship, and set all instance variables appropriately. Remember that you cannot directly assign to the variables in Pirate, and that SpacePirate is a child class.