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.Next, add the code necessary to check whether the values entered do indeed form a triangle. To do this, use the triangle inequality theorem: "any side of a triangle is always shorter than the sum of the other two sides". Print a warning message and stop if the values are invalid.
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 know that triangle inequality theorem is a+b>c a+c>b b+c>a I can write it as a code but how can i get a warning message and stop the programme if the values are invalid. Can you help me?
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:");
int a=in.nextInt();
System.out.print("Please enter lenght for b:");
double b=in.nextInt();
System.out.print("Please enter lenght for c:");
int c=in.nextInt();
int s=(a+b+c)/2;
int x=(s*(s-a)*(s-b)*(s-c));
double Area=Math.sqrt(x);
double flower=(Area*17);
int roundVal= (int) Math.round(flower);
System.out.printf("Max flower is: "+ roundVal);
}
}