Need help with area of triangle

First off this is not my forte. but im trying to help some by trying to get help help from you guys which know what your doing. She is writing a basic program that base to give her the area of a triangle. The base is 5 and the height is 10. This is the code she has so far but dose not work we have been trying to figure this out for 2 days now. If some one could please tell me and her what is wrong it would be very helpful.

public class Myfirstprogram

{

public static void main(String[] args)

{

System.out.print("Hello ");

System.out.print("My name is Anne Maslanka ");

System.out.print(" This is my first program and im a little confused.");

}

}//End main method

public class Triangle{

public Triangle(int base, int height, int area)

{

double base = 5;

double height = 10;

double area = 1/2 * base * height;

System.out.println("The area of a triangle with the base" +base+ "and the height" +height+ "is: " +area);

}

{

area=(base*height)/2; base=5; height=10;

}

public void print(int base, int height, int area){

System.out.println("The area of a triangle with the base" +base+ "and the height" +height+ "is: " +area);

}

}//End main method

Re: Need help with area of triangle

First, why are you printing what you do in the first three lines?

Second, your problem is 1/2 in the formula. 1/2 evaluates to 0 because they are both integers and integers round down to whole numbers. Change the 2 to 2.0.

Also, add some spacing in your final print statement to avoid your values butting up against the text.

Regards,

Jim

Re: Need help with area of triangle

thanks that's what there proff wants I guess but I did what you said and it still will not work anymore advice?

Re: Need help with area of triangle

Sorry I didn't read this more carefully my first time thru. First, you should read the FAQ and the guide for new posters. All code should be placed between tags. I have done it for you here.

Code:

`public class Myfirstprogram {`

public static void main(String[] args)

{

System.out.print("Hello ");

System.out.print("My name is Anne Maslanka ");

System.out.print(" This is my first program and im a little confused.");

}

}//End main method

public class Triangle{

public Triangle(int base, int height, int area)

{

double base = 5;

double height = 10;

double area = 1/2 * base * height;

System.out.println("The area of a triangle with the base" +base+ "and the height" +height+ "is: " +area);

}

{

area=(base*height)/2; base=5; height=10;

}

public void print(int base, int height, int area){

System.out.println("The area of a triangle with the base" +base+ "and the height" +height+ "is: " +area);

}

}//End main method

There are a number of problems here. Are you supposed to be using a separate class for calculating the area? If so, you are declaring your variables inside the constructor. This won't even compile. What errors are you seeing?

Regards,

Jim