Hello I'm a new java student and I have an assignment which is
Design and implement a program that computes the maximum number of flowers that can be planted in a triangular-shaped garden having sides of length a, b and c meters, assuming at most 17 flowers can be planted in each square meter. You can use Heron's formula (below) to compute the area of the garden, but remember, the total number of flowers should be an integer! Tip: the Math class has a function Math.sqrt that you can use to compute the square root of a value.
Heron's formula: the area, A, of a triangle whose sides have lengths a, b, and c is
A = sqrt{s(s-a)(s-b)(s-c)},
where s is the semi-perimeter of the triangle; that is,
s={a+b+c}/{2}.
I have a little problem with this, I can get the max flower but it's not an integer but the teacher wants this to be an integer. How can i solve that? Here's my code
package berk;
import java.util.Scanner;
public class FirstProgramme{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.print("Please enter lenght for a:");
double a=in.nextDouble();
System.out.print("Please enter lenght for b:");
double b=in.nextDouble();
System.out.print("Please enter lenght for c:");
double c=in.nextDouble();
double s=(a+b+c)/2;
double x=(s*(s-a)*(s-b)*(s-c));
double Area=Math.sqrt(x);
double flower=(Area*17);
System.out.printf("Max flower is: %8.2f",flower);
}
}