Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package abstractions;
  2. /**
  3. * Program Name: Rectangle
  4. * This program will have multiple methods of setting the rectangle height and width as well as
  5. * methods to find area and perimeter of the rectangle.
  6. * @author Benger
  7. * Date Created: 4/4/2018
  8. */
  9.  
  10. public class Rectangle {
  11. private double height,width;
  12. private static int i=1;
  13. private String id="R-00";
  14.  
  15. public Rectangle() {
  16. height=1.0;
  17. width=1.0;
  18. i++;
  19. System.out.println(id+i);
  20.  
  21. }
  22. public Rectangle(Rectangle r) {
  23. r.height=height;
  24. r.width=width;
  25. i++;
  26. System.out.println(id+i);
  27. }
  28.  
  29. public Rectangle(double h,double w) {
  30. w=width;
  31. h=height;
  32. i++;
  33. System.out.println(id+i);
  34.  
  35. }
  36. // get and sets
  37. void setHeight(double height) {
  38. height=this.height;
  39. }
  40.  
  41. void setWidth(double width) {
  42. width=this.width;
  43. }
  44.  
  45. double getHeight() {
  46. return height;
  47. }
  48.  
  49. double getWidth() {
  50. return width;
  51. }
  52.  
  53. public double area() {
  54. return height*width;
  55. }
  56.  
  57. public double perimeter() {
  58. return 2*height+2*width;
  59. }
  60.  
  61. public void thisShape() {
  62. System.out.println("This is a rectangle");
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement