how will i do this??

private double height;//Height

private double base;//Base length

public Triangle(double h, double b);//Constructor

public void setHeight(double x);//Sets height

public double getHeight();//Gets height

public void setBase(double x);//Sets base length

public double getBase();//Gets base length

public double getArea();//Returns the area of the triangle

Use the Scanner class in the main method. The main method will be a calling method where it invokes all method in the Triangle class.

...

Code :

/** * @(#)gg.java * * * @author * @version 1.00 2012/10/22 */ import java.util.*; public class gg { Scanner br= new Scanner(System.in); private double height; private double base; public static void main(String []args) { double h=getHeight(); double b=getBase(); System.out.println(""+b.getArea()); } public double getHeight(){ System.out.println("Enter height of the triangle: "); height=br.nextDouble(); return height; } public double getBase(){ System.out.println("Enter Base of the triangle: "); base=br.nextDouble(); return base; } public double getArea(){ return (0.5*height*base); } }

Sample Output:

Enter height of the triangle : 5

Enter base of the triangle : 10

The area of a triangle is 25.00