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

(5 points) Given an object named diamond, constructed elsewhere, call the getter

ID: 3704679 • Letter: #

Question

(5 points) Given an object named diamond, constructed elsewhere, call the getter method to get the value of the instance variable diagonal and store it in a new int variable called hold. This is still just one method call, no constructors 8. (5 points) Given an object named heart, constructed elsewhere, call the getter method to get the value of the instance variable height and store it in a new int variable called answer. 9. 10. (5 points) Given an object named cylinder, constructed elsewhere, call the getter method to get the value of the instance variable radius and store it in a new int variable called value.

Explanation / Answer

Program:

//Main class

public class MyApp{  

public static void main(String args[]){

Diamond diamond = new Diamond(5);// Creating diamond object

Heart heart = new Heart(10); // Creating heart object

Cylinder cylinder = new Cylinder(15); // Creating cylinder object

int hold = diamond.getDiagonal(); // Retrieving diagonal value and storing in variable hold

int answer = heart.getHeight(); // Retrieving height value and storing in variable answer

int value = cylinder.getRadius(); // Retrieving radius value and storing in variable value

}

}

//Creating Diamond class

class Diamond{

int diagonal;

public Diamond(int x){

diagonal = x;

}

public int getDiagonal(){

return diagonal;

}

}

//Creating Heart class

class Heart{

int height;

public Heart(int x){

height = x;

}

public int getHeight(){

return height;

}

}

// Creating Cylinder class

class Cylinder{

int radius;

public Cylinder(int x){

radius = x;

}

public int getRadius(){

return radius;

}

}