Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. public class Box {
  2.  
  3. static private double width;
  4. static private double length;
  5. static private double height;
  6.  
  7.  
  8.  
  9. public Box() {
  10.  
  11. this.width = 1.0;
  12. this.length = 1.0;
  13. this.height = 1.0;
  14.  
  15. }
  16.  
  17. public Box(double w, double l, double h) {
  18.  
  19. if (w < 0)
  20. w = 1.0;
  21.  
  22. if (h < 0)
  23. h = 1.0;
  24.  
  25. if (l < 0)
  26. l = 1.0;
  27.  
  28. width = w;
  29. height = h;
  30. length = l;
  31.  
  32. }
  33.  
  34. public static String toString(Box x) {
  35.  
  36. return String.format("Width: %.2f Length: %.2f Height: %.2f",
  37. x.getWidth(),x.getLength(),x.getHeight());
  38.  
  39. }
  40.  
  41. public static void main(String[] args) {
  42.  
  43. Box sample = new Box(43,57,3423);
  44.  
  45. toString(sample);
  46.  
  47. // System.out.printf("Width: %.2f Length: %.2f Height: %.2f%n",
  48. //sample.getWidth(),sample.getLength(),sample.getHeight());
  49.  
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement