Advertisement
Guest User

Rectangle

a guest
Jan 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1.  
  2. public class Rectangle {
  3. //fields
  4. private int width;
  5. private int height;
  6. //constructors
  7. public Rectangle(int startWid, int startHei) {
  8. setDimensions(startWid, startHei);
  9. }
  10. //mutators
  11. public void setWidth(int newWid) {
  12. width = newWid;
  13. }
  14. public void setHeight(int newHeight) {
  15. height = newHeight;
  16. }
  17. public void setDimensions(int newWid, int newHei) {
  18. setWidth(newWid);
  19. setHeight(newHei);
  20. }
  21. //accessors
  22. public double area() {
  23. return width*height;
  24. }
  25. public double parimeter() {
  26. return 2*width + 2*height;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement