Proaram 3 (20 pointsl: Design and implement two Java programs for programming ex
ID: 3590269 • Letter: P
Question
Proaram 3 (20 pointsl: Design and implement two Java programs for programming exercise 6.19, page 238. The first program (called MyTriangle) is to implement the specified methods. The second program (called TestMyTriangle) is to test the first program methods. Program TestMyTriangle is used to compute the area of a triangle if the input is valid. Use Heron's formula (provided in textbook exercise 2.19) to compute the area of the triangle (do not use any other formula). Notice that methodisvalid ) is used to validate the input before attempting to compute the area. See listings 6.10 and 6.11 (page 224) on how to write 2 programs (main program and test program). Design the test program main method (all input and output is handled by the main method) such that it allows the user to re-run the program with different inputs ((i.e., use a loop structure). Document your code and organize the outputs properly using appropriate formatting techniques Submit both programs to the same Assignment Submission folder meiang to valeogra»y the 6 0 0 0Explanation / Answer
Please find my implementation for Q6.19.
public class MyTriangle {
public static boolean isValid(int side1, int side2, int side3){
int longestSide = side1;
if (side2 > longestSide )
longestSide = side2;
if(side3 > longestSide )
longestSide = side3;
return (longestSide < side1 + side2 + side3 - longestSide);
}
}
#######
import java.util.Scanner;
public class TestMyTriangle {
public static void main(String[] args) {
int l1, l2, l3;
Scanner sc = new Scanner(System.in);
System.out.println(" Length of First Side: ");
l1 = sc.nextInt();
System.out.println(" Length of Second Side: ");
l2 = sc.nextInt();
System.out.println(" Length of Third Side: ");
l3 = sc.nextInt();
sc.close();
System.out.println(MyTriangle.isValid(l1, l2, l3));
}
}
/*
Sample run:
Length of First Side:
4
Length of Second Side:
4
Length of Third Side:
5
true
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.