Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cube;
- public class Cube {
- private double length = 1, width = 1, depth = 1;
- public Cube() {
- }
- public Cube(double l, double w, double d) {
- length = l;
- width = w;
- depth = d;
- }
- public void setLength(double l) {
- length = l;
- getLength();
- }
- public void setWidth(double w) {
- width = w;
- getWidth();
- }
- public void setDepth(double d) {
- depth = d;
- getDepth();
- }
- public double getLength() {
- return(length);
- }
- public double getWidth() {
- return(width);
- }
- public double getDepth() {
- return(depth);
- }
- public double volume() {
- return(length * width * depth);
- }
- @Override
- public String toString() {
- String cubeString;
- cubeString = "Cube has volume: " + volume();
- return(cubeString);
- }
- }
- package cube;
- public class TestCube {
- public static void main(String[] args) {
- Cube cube1 = new Cube(5,5,5);
- System.out.println("The length of the cube is: " + cube1.getLength());
- System.out.println("The width of the cube is: " + cube1.getWidth());
- System.out.println("The depth of the cube is: " + cube1.getDepth());
- System.out.println(cube1.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement