I need to create a box class that will create three types of boxes, with 0, 1,
or 3 parameters. I have written some code but I don't understand what is
meant by 0, 1, or 3, parameters. I am having problems writing the
constructors for the parameters because I don't understand what they are
supposed to do. Any help clarifying this would be greatly appreciated.
After I write the constructors where in the code would I place them?
Thanks
public class box()
{
this.length = 1.0;
this.width = 1.0;
this.height = 1.0;
}
// Method to determine volume
public void calVolume(double vol)
{
vol = length * width * height;
}
// Method for returning volume
public double getVol()
{
return vol;
}
//Method to determine Area
public void calArea(double area)
{
area = 2*length*width + 2*length*height + 2*width*height;
}
//Return Area
public double getArea()
{
return area;
}
These are the instructions for the assignment
Create a Box class. The program should be able to create three types of boxes,
with 0, 1, or 3 parameters. If the box is a cube you should only have to
provide the length of one side. You should also be able to specify the length,
width, and height of the box. You should also be able to create a box with
zero dimensions, using default values. You should be able to perform the
following calculations on your box: area and volume. Furthermore, you should
be able to make your box larger and smaller in two different ways.
Specify by how much larger (multiplier) you would like to enlarge each
dimension of the object. For example, makeLarger(2) would multiply the length,
width, and height of the box by 2.
Specify the specific amount you would like to add to each dimension of the
box. For example, makeLarger(1, 3, 5) would add 1 to the length, 3 to the
width, and 5 to the height of the box.
Be sure to include methods for the following tasks:
Constructors (three)
Calculate and return the volume
Calculate and return the area
Enlarge the box (two ways)
Output the dimensions
Demonstrate that your program works properly. Display all results to two
decimal places.
Andrew Thompson - 06 Nov 2005 23:03 GMT
> I need to create a box class ..
What a coincidence! Another poster is having the exact
same problem! ..oooh, that's you.
Please do not be impatient when posting to usenet,
you should wait at leasat 48 hours before chasing up
a post, and then it is best to do it on the original
thread, rather than repost the same question.
In this case, it is entirely unnecessary, as you
already have two detailed replies to the first post.
[ BTW - The first post had a much better 'Subject', as well,
'help with code' is rather vague - and both 'help' and 'code'
are almost expected here. An even better Subject might have
been 'NullPointerException in Constructor' - which cuts right
to the technical problem. ]
gumdrop374 - 06 Nov 2005 23:13 GMT
My bad. I'm sorry about the double post. After I posted the first time I
realized that I wasn't very clear and I didn't know how to edit or erase it
after it was posted.
>> I need to create a box class ..
>
[quoted text clipped - 14 lines]
>been 'NullPointerException in Constructor' - which cuts right
>to the technical problem. ]
Andrew Thompson - 06 Nov 2005 23:37 GMT
> My bad. I'm sorry about the double post.
It's cool, no biggy.
>... After I posted the first time I
> realized that I wasn't very clear ..
I cannot immediately see the difference, but I'll assume
those comments are them.
> ..and I didn't know how to edit or erase it
> after it was posted.
Best not erase posts - very few people who post to these
groups* would like to see posts appearing then vanishing.
Simply 'reply' to your own post and 'break into it' like
I am doing here, putting the extra bits. For 'extra points'
you might trim the bulk of the orignal message that remained
the same, but that is not always possible or appropriate.
By replying to the original thread, the entire conversation
is easier to track (but I guess you figured that for yourself
by now).
Best luck with your technical dilemna.
* I note you are using the JavaKB web interface to the
usenet newsgroup comp.lang.java.help, more information here..
<http://www.physci.org/codes/javafaq.jsp#usenet>
<http://www.physci.org/codes/javafaq.jsp#cljh>
HTH