Skip to content

Instantly share code, notes, and snippets.

@Gzoref
Created November 29, 2018 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gzoref/539d5d80d80072c2687b041f2a90291f to your computer and use it in GitHub Desktop.
Save Gzoref/539d5d80d80072c2687b041f2a90291f to your computer and use it in GitHub Desktop.
package com.object.params;/*
* Name: Geoffrey Zoref
* Date: 9/7/2018
* Project: Classes and Objects - Ch. 6
*/
public class Box {
double width, height, depth;
public Box(Box obj) {
width = obj.width;
height = obj.height;
depth = obj.depth;
}
public Box(double width, double height, double depth) {
this.width = width;
this.height = height;
this.depth = depth;
}
Box() {
width = -1;
height = -1;
depth = -1;
}
Box(double len) {
width = height = depth = len;
}
public double volume() {
return width * height * depth;
}
public static void main(String[] args) {
Box box1 = new Box(10, 20, 15);
Box box2 = new Box();
Box box3 = new Box(7);
Box myClone = new Box(box3);
double volume = box1.volume();
System.out.println("Volume of box 1 is " + volume);
volume = box2.volume();
System.out.println("Volume of box 2 is " + volume);
volume = box3.volume();
System.out.println("Volume of cube is " + volume);
volume = myClone.volume();
System.out.println("Volume of clone is " + volume);
}
}
/**
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment