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

Identify the following items bylabeling them with the given numbers: constructio

ID: 3613613 • Letter: I

Question

Identify the following items bylabeling them with the given numbers: construction statement (1),instance field (2), “other” constructor (3), explicitparameter (4), method (5), object variable (6), default constructor(7).

public class Ch2Demo3
{
public static void main(String[] args)
{
Bot robot = new Bot("Fred", 50, 60);
Bot bobot = new Bot();
System.out.println(bobot.getName());
System.out.println(robot.getName());
bobot.move(30, 40);
System.out.println(bobot.getPosition());
}
}

public class Bot
{
public Bot()
{
this("", 0, 0);
}
public Bot(String newName, int myX, int myY)
{
name = newName;
x = myX;
y = myX;
}
public void move(int xDist, int yDist)
{
this.x = this.x + xDist;
this.y = this.y + yDist;
}
public String getName()
{
return name;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public String getPosition()
{
String position = getX() + " " + getY();
return position;
}
private String name;
private int x;
private int y;
}

Explanation / Answer

1) Construction statement: These are the statements through whichnew objects are created 2) Instance field: These are the variables declared in the classfor which every object of the class has its own value.                         These aredefined without the keyword static 3) Other constructor: constructor other than thedefault constructor 4) explicit parameter: These are in the format, this.x = x (this.x= this.x + something) 5) Method: code snippet with parameters to perform some specifiedfunction 6) Object variable: Variable to type certain Object 7) Default constructor: Default constructor without anyarguments labels are shown next to the line in bold letters =============================================================== public class Ch2Demo3 { public static void main(String[] args) { Bot robot = new Bot("Fred", 50, 60);    //object construction statement 1,                                                                                                                      // robot, bobot areobject variables -6 Bot bobot = new Bot();                       // object constructionstatement 1 System.out.println(bobot.getName()); System.out.println(robot.getName()); bobot.move(30, 40);                          System.out.println(bobot.getPosition()); } } public class Bot { public Bot()    //default constructor7 { this("", 0, 0); } public Bot(String newName, int myX, int myY) //otherconstructor 3 { name = newName; x = myX; y = myX; } public void move(int xDist, int yDist)      //method 5 { this.x = this.x + xDist;                       // explicit parameter 4 this.y = this.y + yDist;                       // explicit parameter 4 } public String getName()                      //method 5 { return name; } public int getX()                                //method5 { return x; } public int getY()                             //method 5 { return y; } public String getPosition()               //method 5 { String position = getX() + " " + getY(); return position; } private String name;                    //instance field 2 private int x;                                 //instance field 2 private int y;                                 //instance field 2 }