d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Basic Help With Netbeans > Volume Of A Box
Add Reply New Topic New Poll
Member
Posts: 10,935
Joined: Dec 27 2007
Gold: 20.00
Sep 26 2012 03:45am
Hey there!
I'm new to this, and I need some help.

I have to make a program that can find the Volume of a box.

First I have to set the Int to Height, Width and Length

Then I have to make constructors for my Box() = height, width and length to 0

Get- and set-methods
getSize() method that returns the (height*width*length).
and then a toString() method that returns Volume + (height*width*length).

like: "5 x 4 x 5 = 100"

I have to make a program that can output 2 boxes, useing the toString method.

i'm currently here: ( rumfang = volume on danish )


public class Box {

private int height;
private int width;
private int length;

public Box() {
height = 0;
width = 0;
length = 0;
}

public Box(int h, int w, int l) {
}

public int getHeight() {
return height;
}

public int getWidth() {
return width;
}

public int getLength() {
return length;
}

public void setHeight(int h) {
height = h;
}

public void setLength(int l) {
length = l;
}

public void setWidth(int w) {
width = w;
}

public int getSize() {
return height * width * length;
}

public int ToString() {
int Rumfang;
Rumfang = height * width * length;
return Rumfang;
}
}

Member
Posts: 827
Joined: Jan 16 2012
Gold: 0.00
Warn: 10%
Sep 26 2012 12:50pm
You don't need methods to get and set the height, width and length of the box at all. in the constructor of the box, you already pass to the object those values. It would be better to just simply have a method called getVolume, and this method will know how to work with the height, width and length, and will just return the volume to you. You don't expose internal data of the object outside of the object, its the concept of "tell, don't ask", witch resumes to: "Procedural code gets information then makes decisions. Object-oriented code tells objects to do things."

if you want to learn more:
http://pragprog.com/articles/tell-dont-ask
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll