Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the “promptInt” method in class Global, a constructor for class PlayerShip

ID: 3899812 • Letter: U

Question

Using the “promptInt” method in class Global, a constructor for class PlayerShip reads input from the user and initialises the “position” field. Your code should provide the String “Player position: “ as a parameter to method “promptInt”. (Note that in the String there is a space after the colon.) The following is an example of what this I/O looks like when the constructor executes (the bold and underlined text indicates the user’s input):
The PlayerShip constructor also creates two guns with power 5, with the first gun immediately one position to the left of the player ship, and the second gun immediately one position to the right of the player ship. * Write a description of class PlayerShip here * author (your name) :vsi version nunber or a date) public class PlayerShip // instance variables replace the example below with your own private int position; private Gun gun1: private Gun gun2 public Playership() // initialise instance variables position Global.promptInt(" player position:")

Explanation / Answer

public PlayShip(){

      position = Global.propmptInt("player position: ");
      gun1 = new Gun(position-1,5) // Assuming we have a constructor Gun(int position, int points)
      gun2 = new Gun(position+11,5) // Assuming we have a constructor Gun(int position, int points)
}