Create a class named Box that includes integer data fields for length, width, and height. Create three constructors that require one, two, and three arguments, respectively. When one argument is used, assign it to length, assign zeros to height and width, and print "Line created". When two arguments are used, assign them to length and width, assign zero to height, and print "Rectangle created". When three arguments are used, assign them to the three variables and print "Box created". Save your file as Box.java. Write an application named TestBoxes to instantiate three Box objects. Make sure you demonstrate all three constructors. Save your file as TestBox.java.
rajmani · Mar 27, 2009 1:58 AM · 3,069 views
/* Box.java */ public class Box { private int lenght; private int width; private int height; public Box(int firstParam){ this.lenght = firstParam; this.width = 0; this.height = 0; System.out.println("Line Created"); } public Box(int firstParam, int secondParam){ this.lenght=firstParam; this.width=secondParam; System.out.println("Rectangle Created"); this.height=0; } public Box(int firstParam, int secondParam, int thirdParam){ this.lenght=firstParam; this.width=secondParam; this.height=thirdParam; System.out.println("Box Created"); } /*TestBoxes.java * Be sure to import the Box.java file or keep it in same folder * I don't know if this is what you're looking for, but it looks someting like this. You said however application. I dunno abt tht :) sry just tryn to help where * I can. */ public class TestBoxes{ public static void main(String[] args){ Box(10); Box(10,11); Box(10,11,12); } } }
dekchidriver · Mar 27, 2009 2:24 AM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion