(Triangles) 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 side1 , double side2, double side3)
/** Return the area of the triangle. */
public static double area(
double side1, double side2, double side3)
Write a test program that reads three sides for a triangle and uses the isValid 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 a triangle is given in
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (4th Edition)
SURVEY OF OPERATING SYSTEMS
Java: An Introduction to Problem Solving and Programming (8th Edition)
Modern Database Management
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Problem Solving with C++ (10th Edition)
- (YOU ARE NOT ALLOWED TO USE ARRAYLIST IN THIS PROJECT)Write a Java program to simulate a blackjack game of cards. The computer will play the role of the dealer. The program will randomly generate the cards dealt to the player and dealer during the game. Cards in this game will be represented by numbers 1 to 13 with Ace being represented by a 1. Remember, that face cards (i.e. Jack, Queen, and King) are worth 10 points to a hand while an Ace can be worth 1 or 11 points depending on the user’s choice. The numbered cards are worth their number value to the hand.arrow_forward(3) public static void test_b(int n) { if (n>0) test_b(n-2); System.out.println(n + " "); Consider the following method: What is printed by the call test_b(4)? A. 0 2 4 B. 0 2 C. 2 4 D. 4 2 E. 4 20 3 (4) What is the efficacy class of +? n 3 A: ©(1) B: O (log n) C: O (n) D: O (n log n) E: Θ n)arrow_forwardClass: Blocks Write a program that prompts for an integer (that a side length) and displays, using asterisks, a filled and hollow square, placed next to each other. For example if the side length is 5, the program should display: ***** ********** * ****** * ****** * ****** *****arrow_forward
- Method to check if x is power of 2*/ static boolean isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x!=0 && ((x&(x-1)) == 0); }.arrow_forwardTrue or False: (a) In a debugger, we can choose whether to step into, step over, or step out of a particular method call. (b) Debuggers, tests, and println() statements are all legitimate ways to help us find errors in our code.arrow_forwardJavaarrow_forward
- (Intro to Java) explain the answers to the below questions using step-by-step explanation.arrow_forward21. Consider the following method: public static void sketch(int x1, int y1, int x2, int y2, int n) ( if (n <= 0) O else ( } drawLine(x1, y1, x2, y2); Assume that the screen looks like a Cartesian coordinate system with the origin at the center, and that drawLine connects (x1,y1) to (x2,y2). Assume also that x1, y1, x2, and y2 are never too large or too small to cause errors. Which picture best represents the sketch drawn by the method call int xm (x1 + x2 + y1 - y2) / 2; int ym (y1 + y2 + x2-x1) / 2; sketch(x1, y1, xm, ym, n - 1); sketch (xm, ym, x2, y2, n - 1); sketch(a, 0, -a, 0, 2) where a is a positive integer? (A) <-a y -a y a X (B) (D) -a -a y + -a -a aarrow_forwardRemaining Time: 1 hour, 28 minutes, 35 seconds. * Question Completion Status: QUESTTON 11 There are five syntax errors in the following java program. Explain them by mentioning the line number with each error. public class public static void main (String [] args) { { double a = 9; 4 double b = 9.0; int x; System.out.println ("Sum of a and b is if( a = b) + (a+b)) 80 X = a; switch (a+b) { case 0: System.out.println (x); default: System.out.println (x) ; 10 11 12 13 14arrow_forward
- 42) Look at the following method: public static int test2 (int x, int y) if (x < y) { return -5; } else { return (test2 (x - y, y + 5) + 6) ; } } What is returned for test2 (10, 20)? A) -5 B) 1 C) 6 D) 10 43) This term is used for methods that directly call themselves. A) Simple recursion C) Absolute recursion B) Direct recursion D) Native recursion 44) If the base case in a recursive method is never reached: A) The result will always be off by one. C) The method will call itself indefinitely. B) The method will call itself only once. D) The method will never call itself. 45) A(n) is an object that is generated in memory as the result of an error or an unexpected event. A) exception C) default exception handler B) exception handler D) error message 46) All of the exceptions that you will handle are instances of classes that extend this class. A) Exception C) IOException B) RunTimeException D) Error 47) All exceptions are instances of dasses that extend this class. A) Throwable C)…arrow_forwardQ2) Write a method that takes two integer inputs (a and b) and outputs 10 distinct random integers between a and b. Assume b- a> 10.arrow_forwardJAVA Notes: all program codes should be written with method/s separated from the main() structure. Use a separate code files for each. Programming Problems: 1. Write a value-returning method, isVowel, that returns the value true if a given character is a vowel, otherwise return false. Also write a program to test your method. 2. Write a program that prompts the user to enter a sequence of characters and output the number of vowels and consonants separately. (use the method isVowel written in problem 1). 3. Write a program that output inflation rates for two successive years and whether the inflation rates are increasing or decreasing. Ask the user to input the current price of an item and its price, one year and two years ago. To calculate the inflation rate for a year, subtract the price of the item for that year and from the price of the item from one year ago and then divide the result by the price a year ago. Your program must contain a method to calculate the results. Use…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education