> Can someone provide me a structure type of template that shows me how
> to design this class? Any comments or suggestions are highly welcomed.
> Thank you
Don't aks people to do your homework for you. Otherwise you are cheating
yourself out of an education. Make an attempt and then ask for help with
specific points that you cannot solve. Break it down into small steps.
> Design and implement a class called Box
You are going to have something like:
class Box {
// some declarations, constructors and other methods go here
}
> that contains instance data
> that represents the height, width, and depth of the box.
You are going to insert this somewhere in your code:
int height, width, depth;
But consider what data type these variables should be, maybe floating
point is more appropriate? Perhaps it doesn't matter for this exercise?
> Also include a
> boolean variable called full as instance data that represents if the
> box is full or not.
You should be able to work out what to do.
> Define the Box constructor to accept and initialize
> the height, width, and depth of the box.
Note that the Eclipse IDE can create a constructor for you once the
above parts are in place.
> Each newly created Box is
> empty (the constructor should initialize full to false). Include getter
> and setter methods for all instance data. Include a toString method
> that returns a one-line description of the box. Create a driver class
> called BoxTest, whose main method instantiates and updates several Box
> object
Carry on breaking the above into small steps and implement each step one
at a time, see if you can coompile it at each stage and work out what
any error messages mean. Where possible, eliminate any errors before
implementing the next part of the specification.
> Design and implement a class called Box that contains instance data
> that represents the height, width, and depth of the box. Also include a
[quoted text clipped - 10 lines]
> to design this class? Any comments or suggestions are highly welcomed.
> Thank you
hi,
Hope following code will help you.
//Box.java
/**
*
*/
package com.omitdev.box;
/**
* @author Kalyani Alshi
*
*/
public class Box {
private double height;
private double width;
private double depth;
private boolean full;
public Box(double height, double width, double depth) {
this.height = height;
this.width = width;
this.depth = depth;
this.full = false;
}
/**
* @return the depth
*/
public double getDepth() {
return depth;
}
/**
* @param depth
* the depth to set
*/
public void setDepth(double depth) {
this.depth = depth;
}
/**
* @return the full
*/
public boolean isFull() {
return full;
}
/**
* @param full
* the full to set
*/
public void setFull(boolean full) {
this.full = full;
}
/**
* @return the height
*/
public double getHeight() {
return height;
}
/**
* @param height
* the height to set
*/
public void setHeight(double height) {
this.height = height;
}
/**
* @return the width
*/
public double getWidth() {
return width;
}
/**
* @param width
* the width to set
*/
public void setWidth(double width) {
this.width = width;
}
private String checkStatus(){
String status = "empty";
if(full){
status = "full";
}
return status;
}
public String toString(){
return "height: " + height + ", width: " + width + ", depth: " +
depth +
"\nThis box is " + checkStatus();
}
}
// BoxTest.java
/**
*
*/
package com.omitdev.box;
/**
* @author Kalyani Alshi
*
*/
public class BoxTest {
public static void main(String[] args) {
Box firstBox = new Box(23.4, 78.9, 56.8);
Box secondBox = new Box(23, 56, 14);
Box thirdBox = new Box(24.8, 67, 98);
System.out.println("\nDescription of firstBox: ");
System.out.println(firstBox);
System.out.println("\nDescription of secondBox: ");
System.out.println(secondBox);
System.out.println("\nDescription of thirdBox: ");
System.out.println(thirdBox);
}
}
cheers,..
Kalyani Alshi
Matt Humphrey - 16 Oct 2006 12:18 GMT
>> Design and implement a class called Box that contains instance data
>> that represents the height, width, and depth of the box. Also include a
[quoted text clipped - 14 lines]
>
> Hope following code will help you.
<snip code>
Wow, that's a pretty excessive hint. Are you going to take the test for him
also?
http://mindprod.com/jgloss/homework.html
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
> Design and implement a class called Box that contains instance data
> that represents the height, width, and depth of the box.
throw new HomeworkException();
digibooster@gmail.com - 16 Oct 2006 20:04 GMT
> > Design and implement a class called Box that contains instance data
> > that represents the height, width, and depth of the box.
>
> throw new HomeworkException();
Yes It is part of my homework. It is the one I am stucked at. I am
asking nicely for some hint. If you know something and don't want to
tell me, you don't have to laugh at me instead.
Joe Attardi - 17 Oct 2006 03:46 GMT
On Oct 16, 3:04 pm, digiboos...@gmail.com wrote:
> Yes It is part of my homework. It is the one I am stucked at. I am
> asking nicely for some hint. If you know something and don't want to
> tell me, you don't have to laugh at me instead.
You weren't asking for a hint, you were asking for us to show you how
to do it. And we're not laughing at you, it's really for your own good
in the long run.
The link Matt posted is worth taking a look at, and bears repeating:
http://mindprod.com/jgloss/homework.html
Give that a read, and try to see where we're coming from!

Signature
Joe
digibooster@gmail.com - 17 Oct 2006 06:21 GMT
This was what I wrote:
Can someone provide me a structure type of template that shows me how
to design this class? Any comments or suggestions are highly welcomed.
Thank you
All I am asking for is a structure type of thing that can get me
started. I've never asked for any code. A nice easy template is all I
was asking for. Maybe it is the question I copied and paste scared
people. Thanks for your concern, and I totally understand that I need
to learn this stuff on my own.
> On Oct 16, 3:04 pm, digiboos...@gmail.com wrote:
> > Yes It is part of my homework. It is the one I am stucked at. I am
[quoted text clipped - 8 lines]
>
> Give that a read, and try to see where we're coming from!
Andrew Thompson - 17 Oct 2006 08:04 GMT
> This was what I wrote:
> Can someone provide me a structure type of template that shows me how
> to design this class? Any comments or suggestions are highly welcomed.
..
> All I am asking for is a structure type of thing that can get me
> started.
class ClassName {
//insert code here..
}
>... I've never asked for any code.
Ummm.. OK, so what do you want this 'template' written in?
Will Tanu-Tuvan do?
Andrew T.
Tom Forsmo - 17 Oct 2006 10:46 GMT
> All I am asking for is a structure type of thing that can get me
> started. I've never asked for any code. A nice easy template is all I
The point is that the code for this exercise is so simple that giving
you a template solves half you homework. A better approach to getting
help on these news groups is to ask specific question. So if you don't
understand what to do, ask if any of us can explain what is to be done,
that's a completely different question from asking about providing the
answer. If you don't know where to start, ask us for a hint, if you have
a compilation or design problem, show us how you have solved it so far
and ask what you must look for to fix it.
As I stated, reading the first couple of chapters of a java book will
give you enough information to figure out the template for the homework
yourself.
tom
Andy Dingley - 17 Oct 2006 14:02 GMT
> Yes It is part of my homework.
So why not _do_ your homework, as you're meant to? What is your
excuse?
You clearly haven't even tried to start on this problem. It's a poorly
phrased question and gives you far too much help to begin with -- even
with this much help you didn't make any attempt to even begin it. Why
can't you understand it? Are you very, very lazy? Were you asleep in
the classes? Do your parents know that they are wasting their money on
classes that you are trying to cheat your way through?
> I am asking nicely for some hint.
No, you didn't "ask" for a "hint", you re-posted the whole question,
with no contribution from you. None at all.
Dijon Yu - 17 Oct 2006 15:05 GMT
I agreed with Andy Dingley. I think a good question with thinking is
like this:
How to express a property of a Box, so I can use it in my class.
How to abstract the height of a Box, ......... and so on .
If you didn't thinking before ask help , you won't learn anything.
Dijon Yu
> > Yes It is part of my homework.
>
[quoted text clipped - 11 lines]
> No, you didn't "ask" for a "hint", you re-posted the whole question,
> with no contribution from you. None at all.