Create a class named Box that includes integer data fields for length, width, an
ID: 3621996 • Letter: C
Question
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 files as Box.java and TestBox.java.Explanation / Answer
please rate - thanks
import java.util.*;
class TestBox
{
public static void main(String[] args)
{Box a=new Box(10);
Box b=new Box(10,20);
Box c=new Box(10,20,30);
}
}
---------------
class Box
{
private int length;
private int width;
private int height;
public Box(int l)
{length=l;
width=0;
height=0;
System.out.println("Line created");
}
public Box(int l,int w)
{length=l;
width=w;
height=0;
System.out.println("Rectangle created");
}
public Box(int l,int w,int h)
{length=l;
width=w;
height=h;
System.out.println("Box created");
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.