Advertisement
Guest User

RightTriangle.java

a guest
May 24th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. public class RightTriangle{
  2.   //fields
  3.   private int base, height;
  4.  
  5.   //constructor
  6.   public RightTriangle( int b, int h ){
  7.     base = b;
  8.     height = h;
  9.   }
  10.  
  11.   //accessor
  12.   public int getBase(){
  13.     return base;
  14.   }
  15.  
  16.   public int getHeight(){
  17.     return height;
  18.   }
  19.  
  20.   public double area(){
  21.     return 0.5 * base * height;
  22.   }
  23.  
  24.   public static void main(String[] args){
  25.     RightTriangle rt = new RightTriangle( 3, 4 );
  26.     RightTriangle bob = new RightTriangle( 8, 12 );
  27.     System.out.println( rt.getBase() );
  28.     System.out.println( bob.area() );
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement