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

public class Alien { private static int alienCount; private static int rogueCoun

ID: 3700198 • Letter: P

Question

public class Alien {

private static int alienCount;

private static int rogueCount;

private String name;        // original name

private String homePlanet; // the home planet

private Location location; // where the alien is currently located

private String alias;       // name that they go by on earth

private boolean wanted; // if the MIB agency is looking for them

/**

* Default constructor - We know we have an alien but don't know much

* about it. This method simply calls the explicit value constructor.

*/

public Alien() {

this("Unknown", "Unknown", Location.ISAT, "Unknown");

}

/**

* Explicit value constructor - Sets each of the attributes based on

the

* parameters and sets wanted to false. This method should increment

the

* alien count.

*

* @param name this alien's original name

* @param homePlanet the origination of this alien

* @param loc the current location for this alien

* @param alias the name this alien goes by on Earth

*/

public Alien(String name, String homePlanet, Location loc, String

alias) {

}

/**

* Indicates that an alien that has been captured and placed at

* the JMU detention facility.

* If the alien was a wanted criminal, then reset wanted to false and

* decrement the rogueCount. In either case, this alien should be

placed

* at the JMU location.

*/

public void capturedJMU() {

}

/**

* Indicates an alien has been deported. It is possible to deport an

* alien without a prior capture. If this alien is wanted, reset the

* the wanted attribute to false and decrement the rogueCount. In

either

* case, set the location to null and decrement the alienCount.

*/

public void deport() {

}

/**

* Identifies that an alien has violated the rules of alien

immigration.

* If this is a new identification (wanted is false), set wanted to

true

* and increment the rogue count. If this alien is already wanted,

then

* do neither.

*/

public void goneRogue() {

}

/**

* Places this alien into a new location.

*

* @param newLoc new current location

*/

public void move(Location newLoc) {

}

/**

* Returns the current location of this alien.

*

* @return current location

*/

public Location getCurrentLocation() {

}

/**

* Returns the total number of aliens on the planet.

*

* @return total number of aliens (including those wanted)

*/

public static int getNumberAliens() {

}

/**

* Returns the total number of wanted aliens on the planet.

*

* @return number of wanted aliens

*/

public static int getNumberWanted() {

}

/**

* Returns basic information about this alien.

*

* @return a String of the form: "%s aka %s from %s currently at %s"

* followed by the term "ROGUE" or the empty String,

* depending on whether isWanted is true or false.

* If location is null, output "Off Planet" in place of the location.

*/

public String toString() {

String location;

String rogue;

if (this.location != null) {

location = this.location.toString();

}

else {

location = "Off Planet";

}

if (wanted) {

rogue = "ROGUE";

}

else {

rogue = "";

}

return String.format("%s aka %s from %s is currently at %s %s",

this.name, this.alias, this.homePlanet,

location, rogue);

}

}

Alien.java 6. Why is it important that all the attributes of the Alien class are private? 7. What is the purpose of the class variables? Why are they private and static? 8. What would happen if they were not static? i.e., when you create 9. Which of the methods in Alien.java are mutator methods? 10. Which of the methods in Alien.java are accessor methods? objects)

Explanation / Answer

6.

When you make a data member public, other programmers who use your class will naturally tend to use these public members rather than some member function that provides similar or the same information simply because it's easier

When a attribute of the class in this case Alien declared as private it can not be accessed out side of the class which would increases the security of the data and avoide unwanted access. When a attribute declared as a private it can be accessed only with in the class or member function of the class.

?7. Class variable are the one (are also known as static member variables) and there's only one copy of that variable that is shared with all instances of that class. Any changes to the variable will be visible to all object of the the class it belong to. Class variables private which means it can be accessed only by that class. Any other class can't affect those variables. Since class variables are not attached to any object and needs to be accessed with out creation of the object it kept static becuase static members and variables can be accessed without object

8. When a attribute is not static when we create an object each object will have own copy of the attribute whereas when it is decleared as static only one copy of the attribute shared across the object of the class which are helpful in some cases when we wanted to track a common count in this case alienCount.

9. In computer science, a mutator method is a method used to control changes to a variable. They are also widely known as setter methods. So abelow are mutator of Alien

10. In computer science, a accessor method is a method used to access the variable. They are also widely known as getter methods. So all getter of the class are accessor