Add methods to get and set all the instance variables. Finallywrite a test class
ID: 3618971 • Letter: A
Question
Add methods to get and set all the instance variables. Finallywrite a test class of this class.class Box { private int height; private int width; private int length; Box() { height=width=length=10; } public int volume() { return length*width*height; } public void setHeight(int h) { height=h; } public int getLength() { return length; } }
class Box { private int height; private int width; private int length; Box() { height=width=length=10; } public int volume() { return length*width*height; } public void setHeight(int h) { height=h; } public int getLength() { return length; } }
Explanation / Answer
Here is the whole code AND the class tester ; Please rate /** * * @author http://www.javacoder.webs.com */ public class Main { public static void main(String args[]) { Box box = new Box(); box.setHeight(3); box.setLength(5); box.setWidth(5); System.out.println(box.getHeight()); System.out.println(box.getLength()); System.out.println(box.getWidth()); } } class Box { private int height; private int width; private int length; Box() { height=width=length=10; } public int volume() { return length*width*height; } public int getHeight() { return height; } public int getWidth() { return width; } public int getLength() { return length; } public void setHeight(int height) { this.height = height; } public void setWidth(int width) { this.width = width; } public void setLength(int length) { this.length = length; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.