Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CPSC 1150 Lab 5 [20 Marks] Objective: To write the Java program that uses methods. Problem 1: Implement the following two methods: /** Return true
CPSC 1150 Lab 5 [20 Marks] Objective: To write the Java program that uses methods. Problem 1: Implement the following two methods: /** Return true if the sum of every two sides is greater than the third side. */ public static boolean isValid(double sidel, double side2, double side3) /**Return the area of the triangle. */ public static double area(double sidel, double side2, double side3) . Write a test program (Triangles.java) that reads three sides for a triangle and uses the is Valid method to test if the input is valid and uses the area method to obtain the area. The program displays the area if the input is valid. Otherwise, it displays that the input is invalid. The formula for computing the area of triangle is: 8 = (side] + side2 + side3)/2; area - v s (s - sidel) (s - side2) (s - side3) Your program should be repeated as long as the user types Yes. When the user types No, the program should end. Sample Output: Enter three sids in double: 5 6 7 The are of the triangle is 14.70 Would you like to repeat the program? Yes Enter three sids in double: 3 5 8 Input is invalid Would you like to repeat the program? Yes Enter three sids in double: 3 4 5 The are of the triangle is 6.00 Would you like to repeat the program? No End of ProgramProblem 2: Implement the following method: /** Return true if num is prime. */ public static boolean isPrime(int num) . Write a program (TwinPrimes.java) to find all twin primes in the range 2 to 100. The program should use the method isPrime to determine if a number is prime or not. Display the output as shown in the sample screenshot. Twin primes are a pair of prime numbers that differ by 2. For example, 3 and 5 are twin primes, 5 and 7 are twin primes, and 11 and 13 are twin primes. Sample Output: (3, 5) (5, 7) (11, 13) (17, 19) (29, 31) (41, 43) (59, 61) (71, 73) Hand In: . Make a folder named lab5_yourname containing the source code files, zip the folder and submit the zipped file to BrightSpace. Note: Always follow good programming style. No magic numbers should appear in the program. Use named constants where necessary. . All the double/float values in the outputs should be displayed with only two significant digits after the decimal point. Check the link: Rubrics: Program: . [3 marks] Presentation and Style: Readability, descriptive identifier, indentation, bracket placement, internal documentation (comments), use of appropriate constants [7 marks] Correctness: Program works without bugs
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started