Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rectangle{//class header
- //instance variables
- private double length, width;
- //constructor
- public Rectangle( double l, double w ){
- length = l;
- width = w;
- }
- //methods
- public void printArea(){
- double area = length * width;
- System.out.println( "Area: " + area );
- }
- public void printPerimeter(){
- double perim = 2 * length + 2 * width;
- System.out.println( "Perimeter: " + perim );
- }
- //main method
- public static void main(String[] args){
- Rectangle r1 = new Rectangle( 26.0, 5.0 );//instantiation
- r1.printArea();
- r1.printPerimeter();
- Rectangle r2 = new Rectangle( 10.0, 14.0 );
- r2.printArea();
- r2.printPerimeter();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement