desislava_topuzakova

1. Rectangle

Jun 4th, 2021
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public class Rectangle {
  2. private double length;
  3. private double width;
  4. private String name;
  5.  
  6. public Rectangle(double length, double width, String name){
  7. this.length = length;
  8. this.width = width;
  9. this.name = name;
  10. }
  11.  
  12. public double getLength() {
  13. return this.length;
  14. }
  15.  
  16. public double getWidth() {
  17. return this.width;
  18. }
  19.  
  20. public double getName() {
  21. return this.width;
  22. }
  23.  
  24. public double radius() {
  25. return 0.5 * Math.sqrt(length * length + width * width);
  26. }
  27.  
  28. public void resize (double x ,double y) {
  29. this.width = width * y;
  30. this.length = length * x;
  31. }
  32.  
  33. public String toString() {
  34. return String.format("Rectangle %s, width: %f, length: %f", this.name, this.width, this.length);
  35. }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment