Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. /*
  2. * Program: BoxClass
  3. * Programmer: David Martinez
  4. * Date: December 8th
  5. * Description: This class is used to create a box object. Class include area,
  6. * volume and one display methods. This class has two contructors, so now the
  7. * user can create objects by passing number of strings.
  8. */
  9. package boxclass;
  10.  
  11. public class Box {
  12. // Initialization
  13. double depth; // Depth of the box
  14. double width; // Height of the box
  15. double length; // Width of the box
  16.  
  17. // Contructor - user provides the values to create the box object
  18. public Box(double d, double l, double w){
  19. // Take the values that are passed for the user to set the local var.
  20. this.depth = d;
  21. this.length = l;
  22. this.width = w;
  23. } // End of costructor
  24.  
  25. // Overloaded constructor
  26. public Box(String d, String l, String w){
  27. // Convert the passed String to number and set the Box dimensions
  28. this.depth = Double.parseDouble(d);
  29. this.length = Double.parseDouble(l);
  30. this.length = Double.parseDouble(w);
  31. } // End of constructor
  32.  
  33. // Calculation method
  34. public double volumn(){
  35. // Multiply the 3 dimesions to calculate the volumn of the box
  36. return depth * length * width;
  37. } // End of method
  38.  
  39. public double area(){
  40. // Multiply the length and width to calculate the floor area of the box
  41. return length * width;
  42. } // End of method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement