Concept explainers
(Geomentry: point position)
/** Return true if point (x2, y2) is on the left side of the * directed line from (x0, y0) to (x1, y1) */
public static boolean leftOfTheline (double x0, double y0 , double x1 , double y1 , double x2 , double y2)
/** Return true if point (x2, y2) is on the same * line from (x0, y0) to (x1, y1) */
public static boolean onTheSameline{double x0 , double y0, double x1 , double y1 , double x2, double y2)
/** Return true if poi nt (x2, y2) is on the • line segment from (x0, y0) to (x1, y1) */
public static boolean onThelineSegment(double x0, double y0, double x1, double y1, double x2 , double y2)
Write a program that prompts the user to enter the three points for p0, p1, and p2 and displays whether p2 is on the left side of the line from p0 to p1, right side, the same Line, or on the Line segment. Here are some sample runs:
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)
- (Algebra: solve 2 x 2 linear equations) You can use Cramer's rule to solve the following 2 x 2 system of linear equation: ax + by = e ed – bf af- ec ad - bc cx + dy = f ad – bc y = Write a program that prompts the user to enter a and f and display the result. If ad - bc is 0 b, c, d , e, , report that The equation has no solution.arrow_forwardQ1) Write a method that checks whether two words are anagrams. Two words are anagrams if they contain the same letters in any order. For example, "silent" and "listen" are anagrams. Write a test program that prompts the user to enter two strings and, if they are anagrams, displays "anagram", otherwise displays "not anagram". Note: The header of the method is as follows: public static boolean isAnagram(String s1, String s2) Sample Input #1: Enter two strings: Silent listen Sample Output #1: The string “Silent” and “listen” are anagrams. Sample Input #1: Enter two strings: teach peach Sample Output #1: The string “teach” and “peach” aren’t anagrams.arrow_forward2) Two integers are said to be relatively prime if their greatest common divisor (GCD) is one. For example 12 and 13 are relatively prime, but 12 and 14 are not. a. Write a method called relativelyPrime that accepts two integer parameters A and B. The method should output if A, and B are relatively prime or nat. Use the following method header: public static void relativelyPrime(int A, int B) b. Write a test program (main) to test the method by asking the user to input two positive integers X and Y. Then the program will call the method relativelyPrime to output if X and Y are relatively prime or not. Sample Run 1: Enter Two positive integers X and Y: 12 13 12 and 13 are relatively prime Sample Run 2: Enter Two positive integers X and Y: 12 14 12 and 14 are not relatively primearrow_forward
- Problem 1: Complete the isExactReverse() method in Reverse.java as follows: The method takes two Strings x and y as parameters and returns a boolean. The method determines if the String x is the exact reverse of the String y. If x is the exact reverse of y, the method returns true, otherwise, the method returns false. Other than uncommenting the code, do not modify the main method in Reverse.java. Sample runs provided below. Argument String x "ba" "desserts" "apple" "regal" "war" "pal" Argument String y "a" "stressed" "apple" "lager" "raw" "slap" Return Value false true false true true falsearrow_forward"NEED ONLY CODE NO EXPLANATION" Harry has a big wall clock, that got hit while he was playing. Now, the minute hand doesn't rotate by the angle 2π/3600 each second, but now it moves according to different angle x. You can assume that coordinates of the centre of the clock are (0, 0) and the length of the minute hand is l. One endpoint of the minute hand is always located at the clock centre; the other endpoint is initially located at the point (0, l). One second later, Harry observes that this endpoint is at distance d above the x-axis, i.e., the y-coordinate of this endpoint is equal to d. Harry is curious about where the minute hand will be (specifically, its y-coordinate) after t seconds. Because t can be very large, Harry can't wait for that moment. Please help him to write a python code that prints a single line containing the output. Input: 4 2 2 Output 4arrow_forward(Written in Java or Python) Write a program that allows a user to select 3 points on a graphics panel. Then, draw a triangle using these 3 points. Allow the user to specify a number of random points to be generated inside of the triangle. For each random point that is within the boundaries of the triangle draw a small dot at each of the points that are halfway between the randomly generated point and each vertex of the triangle. Do not draw the randomly generated point. Allow the user to repeat the process without removing the old dots. Allow the user to clear the screen.arrow_forward
- (Java in Eclipse) Write code that finds the sum of two matrices. Use the following method header public static int[][] addMatrix(int[][] a, int[][] b) The rules for adding two matrices are:1. both matrices should have the exact same dimensions (i.e. height and width) – you need to check for this rule in your program.2. both matrices should have elements that have compatible types – you don’t have to add extra code to check this rule in your method as it will only accept int arrays included is a test class and a sample runarrow_forward(Algebra: solve 2 X 2 linear equations) You can use Cramer's rule to solve the following 2 x 2 system of linear equations: ed – bf af – ec y bc ax + by = e X = cx + dy = f ad ad – bc Write a function with the following header: void solveEquation(double a, double b, double c, double d, double e, double f, double& x, double& y, bool& isSolvable) If ad – bc is 0, the equation has no solution and isSolvable should be false. Write a program that prompts the user to enter a, b, c, d, e, and f and displays the result. If ad – bc is 0, report that "The equation has no solution." See Program- ming Exercise 3.3 for sample runs.arrow_forward(Convert decimals to fractions)Write a program that prompts the user to enter a decimal number and displays the number in a fraction.Hint: read the decimal number as a string, extract the integer part and fractional part from the string, and use the Rational class in LiveExample 13.13 to obtain a rational number for the decimal number. Use the template athttps://liveexample.pearsoncmg.com/test/Exercise13_19.txt The problem can not use BigInteger //Below is the Rational LiveExample 13.13 that goes with the problem/question; notice "long" instead of "BigInteger" class Rational extends Number implements Comparable<Rational> { // Data fields for numerator and denominator private long numerator = 0; private long denominator = 1; /** Construct a rational with default properties */ public Rational() { this(0, 1); } /** Construct a rational with specified numerator and denominator */ public Rational(long numerator, long denominator) { long gcd = gcd(numerator,…arrow_forward
- (Computer-Assisted Instruction) The use of computers in education is referred to as computer-assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use a Random object to produce two positive one-digit integers. The program should then prompt the user with a question, such as How much is 6 times 7? The student then inputs the answer. Next, the program checks the student’s answer. If it’s correct, display the message "Very good!" and ask another multiplication question. If the answer is wrong, display the message "No. Please try again." and let the student try the same question repeatedly until the student finally gets it right. A separate method should be used to generate each new question. This method should be called once when the application begins execution and each time the user answers the question correctly.arrow_forward(Check password) Some websites impose certain rules for passwords. Write a method that checks whether a string is a valid password. Suppose the password rules are as follows: A password must have at least eight characters. A password consists of only letters and digits. A password must contain at least two digits. Write a program that prompts the user to enter a password and displays Valid Password if the rules are followed or Invalid Password otherwise.arrow_forward(Please do not give solution in image format thanku) Using Java, Integer variables totalBudget and productCost are read from input. A product costs productCost to make, and a budget is given by totalBudget. Assign remainingBudget with the remaining budget after making as many products as possible.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