Advertisement
fosterbl

Rectangle.java w/o special methods

Oct 28th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. public class Rectangle{//class header
  2.    //data - instance variables
  3.    private double length, width;
  4.    
  5.    //functionality - methods
  6.    public void setLength( double len ){
  7.       length = len;
  8.    }
  9.    
  10.    public void setWidth( double wid ){
  11.       width = wid;
  12.    }
  13.    
  14.    public double area(){
  15.       return length * width;
  16.    }
  17.    
  18.    public double perimeter(){
  19.       return 2 * length + 2 * width;
  20.    }
  21.    
  22.    public double diagonal(){
  23.       return Math.sqrt( Math.pow(width,2) + Math.pow(length,2) );
  24.    }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement