basicbox.java
来自「国外的数据结构与算法分析用书」· Java 代码 · 共 39 行
JAVA
39 行
/** A simple box class with variables for the length, width, and height,
and methods to return its volume, a string representation of the box,
and test for equality. */
public class BasicBox
{
/** Instance variables for the class. */
int length, width, height;
/** Constructor for a box. */
public BasicBox(int l, int w, int h)
{
length = l;
width = w;
height = h;
}
/** Method for returning the volume of the box. */
public int volume()
{
return length * width * height;
}
/** A string representation of the box formed by appending a string
representation of each attribute. */
public String toString()
{
String temp = " Length = " + length + "\n"
+ " Width = " + width + "\n"
+ " Height = " + height + "\n";
return temp;
}
/** Does this box have equal variable values as box other? */
public boolean equals(BasicBox other)
{
return length == other.length & width == other.width & height == other.height;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?