Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Program: BoxClass
- * Programmer: David Martinez
- * Date: December 8th
- * Description: This class is used to create a box object. Class include area,
- * volume and one display methods. This class has two contructors, so now the
- * user can create objects by passing number of strings.
- */
- package boxclass;
- public class Box {
- // Initialization
- double depth; // Depth of the box
- double width; // Height of the box
- double length; // Width of the box
- // Contructor - user provides the values to create the box object
- public Box(double d, double l, double w){
- // Take the values that are passed for the user to set the local var.
- this.depth = d;
- this.length = l;
- this.width = w;
- } // End of costructor
- // Overloaded constructor
- public Box(String d, String l, String w){
- // Convert the passed String to number and set the Box dimensions
- this.depth = Double.parseDouble(d);
- this.length = Double.parseDouble(l);
- this.length = Double.parseDouble(w);
- } // End of constructor
- // Calculation method
- public double volumn(){
- // Multiply the 3 dimesions to calculate the volumn of the box
- return depth * length * width;
- } // End of method
- public double area(){
- // Multiply the length and width to calculate the floor area of the box
- return length * width;
- } // End of method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement