SHARE
TWEET

Rectangle

a guest Jan 18th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top