Monty374

Disk

Nov 25th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. package puck;
  2.  
  3. public class Disk extends Circle {
  4. private double thickness;
  5.  
  6. public Disk(double r, double t) {
  7. super(r);
  8. thickness = t;
  9.  
  10. }
  11.  
  12. public void setThickness(double newThickness) {
  13. thickness = newThickness;
  14. }
  15.  
  16. public double getThickness() {
  17. return(thickness);
  18. }
  19.  
  20. public double volume() {
  21. double v;
  22.  
  23. v = super.area() * thickness;
  24. return(v);
  25. }
  26.  
  27. public boolean equals(Object obj) {
  28. Disk testObj = (Disk)obj;
  29.  
  30. if (testObj.getRadius() == super.getRadius() &&
  31. testObj.getThickness() == thickness) {
  32. return(true);
  33. } else {
  34. return(false);
  35. }
  36. }
  37.  
  38. public String toString() {
  39. String diskString;
  40.  
  41. diskString = "The disk has radius " + super.getRadius() +
  42. " and thickness " + thickness;
  43. return(diskString);
  44. }
  45. }
Add Comment
Please, Sign In to add comment