Advertisement
Guest User

Rectangle.java

a guest
Feb 26th, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import java.awt.Color;
  2.  
  3. public class Rectangle extends Point {
  4. private int width;
  5. private int height;
  6. private Color color;
  7.  
  8. public Rectangle() {
  9. super(2, 0, 3);
  10. width = 3;
  11. height = 5;
  12. color = Color.ORANGE;
  13. }
  14.  
  15. public Rectangle(int width, int height, int length, Color color) {
  16. super((int) Math.ceil((double) width / 2),
  17. (int) Math.ceil((double) length / 2),
  18. (int) Math.ceil((double) height / 2));
  19.  
  20. this.width = width;
  21. this.height = length;
  22. this.color = color;
  23. }
  24.  
  25. public Rectangle(int newX, int newY, int newWidth, int newHeight) {
  26. super(newX, newY, 0);
  27. width = newWidth;
  28. height = newHeight;
  29. }
  30.  
  31. public void setWidth(int width) {
  32. this.width = width;
  33. setZ((int) Math.ceil((double) height / 2));
  34. }
  35.  
  36. public void setHeight(int height) {
  37. this.height = height;
  38. setZ((int) Math.ceil((double) height / 2));
  39. }
  40.  
  41. public int getWidth() {
  42. return width;
  43. }
  44.  
  45. public int getHeight() {
  46. return height;
  47. }
  48.  
  49. public int calcArea() {
  50. return width * height;
  51. }
  52.  
  53. public DrawFigure drawFigure() {
  54. DrawFigure rectangle1 = new DrawFigure(1, width, height, 0);
  55. return rectangle1;
  56. }
  57.  
  58. public String toString() {
  59. return "Width = " + width + " Height = " + height + "\n" + color + "\nCenter: " + super.toString();
  60. }
  61.  
  62. public int calcVolume() {
  63. return 0;
  64. }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement