Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RightTriangle{
- //fields
- private int base, height;
- //constructor
- public RightTriangle( int b, int h ){
- base = b;
- height = h;
- }
- //accessor
- public int getBase(){
- return base;
- }
- public int getHeight(){
- return height;
- }
- public double area(){
- return 0.5 * base * height;
- }
- public static void main(String[] args){
- RightTriangle rt = new RightTriangle( 3, 4 );
- RightTriangle bob = new RightTriangle( 8, 12 );
- System.out.println( rt.getBase() );
- System.out.println( bob.area() );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement