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

Task 1: Classes and fields Create the following classes (written in italics) and

ID: 3898457 • Letter: T

Question

Task 1: Classes and fields Create the following classes (written in italics) and "fields" / "private data members" (enclosed in double quotes): Each Gun has a "position", "power" and "points", all integers. Each gun also has a "justFired" status which can be either true or false (i.e. of type boolean; see the free textbook online by Parsons, sectio 3.1.3, "Boolean Variables", page 33, or google java tutorial boolean). . The PlayerShip has "position", an integer, and two instances of Gun, called "gunl" and "gun2" Each EnemyShip has "position", "velocity" and "life", all integers. Each enemy ship also has a "justHit" status which can be either true or false (i.e. of type boolean see the free online textbook by Parsons, section 3.1.3, "Boolean Variables", page 33). The class EnemyShip also maintains a count of the number of enemy ships that have been created so far, called "number", an integer, which is not attached to any one particular enemy ship, but rather is associated with the whole class of enemy ships. Thus "number" in EnemyShip has a similar role to "numSummersn SummerOO .A Game has 1 PlayerShip called "player", and 3 instances of EnemyShip called "enemyl" "enemy2" and "enemy3" In the above bullet point descriptions, note that the names of the classes and fields follow Java's naming conventions. That is, class names begin with an uppercase letter, field names begin with a lowercase letter, compound nouns are joined without a space and the second word begins with an uppercase letter). Note: all fields should be declared as private. When you have completed this entire task, submit your code to PLATE.

Explanation / Answer

class Gun {

    private int position;
    private int power;
    private int points;
    private boolean justFired;

    public Gun(int p, int po){
        position = p;
        power = po;
    }
    public void move(int a){
        position = position + a;
    }
    public int getPoints(){
       return points;
    }
}

class PlayerShip {

    private int position;
    private Gun gun1;
    private Gun gun2;

    public PlayerShip(){
        position = Global.promptInt("Player position:");
        gun1 = new Gun(5,position-1);
        gun2 = new Gun(5,position+1);
    }
    public void move(int a){
        position = position + a;
        gun1.move(a);
        gun2.move();
    }
    String toString(){
        int point = gun1.getPoints() + gun2,getPoints();
        return "Player(" + Integer.toString(position) + "," + Integer.toString(point) + " pts )";
    }
   
}

class EnemyShip {

    private int position;
    private int velocity;
    private int life;
    private boolean justHit;
    public final static n = 0;

    public EnemyShip(){
        n++;
        System.out.println("Enemy #" + n);
        Scanner sc = new Scanner(System.in);
        System.out.print("- Initial position: ");
        position = sc.nextInt();
        System.out.print("- Initial velocity: ");
        velocity = sc.nextInt();
        life = 10;
        justHit = false;
    }
    String toString(){
        return "Enemy(" + Integer.toString(position) + " )";
    }
}

class Game {
     private PlayerShip player;
     private EnemyShip enemy1,enemy2, enemy3;
     public Game(){

        player = new PlayerShip();
        enemy1 = new EnemyShip();
        enemy2 = new EnemyShip();
        enemy3 = new EnemyShip();
      
     }
     String toString(){
        return enemy1.toString() + " " + enemy2.toString() + " " + enemy3 .toString() + " " + player.toString();
     }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote