I'm a student and I have been tasked to make a program that takes in the three sides of a triangle and outputs the angles of the triangle in reference to the sides. I haven't programmed the equation yet but I have been messing around with the Scanner and "if" statements to start the program. Already I have a problem:
--Here is the output of the beginning part of the program. But that is where it stops. I prompt the user to type a "D" or a "R" and it won't allow the user to type in that spot. However, earlier in the program I was able to prompt the user for a character. Can someone figure out why the previous prompt works and this one does not.--
This is the SSS Triangle program to find the angles of a triangle. Do you know all the sides of a triangle but need to know the angles? (Y/N):Y
What are the lengths of the sides of your triangle? -If all the same length then don't worry about the smallest, medium, and largest- The length of the smallest side: 3 The length of the medium side: 4 The length of the longest side: 5 Would you like the angles in degrees or radians? (D/R):
--Here is the code. The last line is where I am having trouble--
public class SSSTriangle {
public static Scanner read= new Scanner(System.in);
public static void main(String[]args) {
System.out.print("This is the SSS Triangle program to find the angles of a triangle. \n Do you know all the sides of a triangle but need to know the angles? (Y/N):");
String response= read.nextLine();
if (response.contains("N")) {
System.out.println("Okay, have a good day!");
}
if (response.contains("Y")) {
giveMeTheSides();
}
}
public static void giveMeTheSides() {
System.out.println("\nWhat are the lengths of the sides of your triangle? \n -If all the same length then don't worry about the smallest, medium, and largest-");
System.out.print("The length of the smallest side: ");
double a = read.nextDouble();
System.out.print("The length of the medium side: ");
double b = read.nextDouble();
System.out.print("The length of the longest side: ");
double c = read.nextDouble();
if (a<=0||b<=0||c<=0) {
System.out.println("Nice try! Your given sides do not produce a possible triangle.");
}
else {
if ((a+b)<c) {
System.out.println("Nice try! Your given sides do not produce a possible triangle.");
}
else {
System.out.println("Would you like the angles in degrees or radians? (D/R): ");
String newResponse= read.nextLine();