Created
September 8, 2014 21:52
-
-
Save joshrosso/1dea4b3cc430f1e98d5a to your computer and use it in GitHub Desktop.
Cuboid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lenny.turbo | |
public class Cuboid { | |
/* All field in Java are 'private' unless specified otherwise | |
* ...does this app need to access the values directly after consturction? | |
* If so....generate getters and setters..since the spec doesn't ask for it | |
* I will not implement them. | |
*/ | |
// Cuboid data members / fields - Remeber they are private | |
int length; | |
int breadth; | |
int voulume; | |
/* Begin constructors | |
* Need for 4 constructors in POJO | |
* Default Constructor ( 0 arg ) | |
* 1 arg, 2 arg, and 3 arg - use example to map args to fields | |
*/ | |
// Begin default constructor | |
public Cuboid() { | |
this.length = 1; | |
this.breadth = 1; | |
this.voulume = 1; | |
} | |
// Begin 1 arg constructor | |
public Cuboid(int lengthAndBreadthAndVolume) { | |
this.length = lengthAndBreadthAndVolume; | |
this.breadth = lengthAndBreadthAndVolume; | |
this.voulume = lengthAndBreadthAndVolume; | |
} | |
// Begin 2 arg constructor | |
public Cuboid(int lengthAndBreadth, int voulume) { | |
this.length = lengthAndBreadth; | |
this.breadth = lengthAndBreadth; | |
this.voulume = voulume; | |
} | |
// Begin 3 arg constructor | |
public Cuboid(int length, int breadth, int voulume) { | |
this.length = length; | |
this.breadth = breadth; | |
this.voulume = voulume; | |
} | |
// Implement getVolume method based on example criteria | |
public int getVolume() { | |
return this.length * this.breadth * this.voulume; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment