id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > quiz2020_12_15_SLHL_solve
prev  |  next  |  chance

Write a method that finds the intersection of two lines. The two lines are represented by arrays of length 2 called 'line1' and 'line2' where index 0 is the slope and index 1 is the y-value of the y-intercept. You will return an array of length three. In that array, index 0 is the x-value of the point of intersection, index 1 is the y-value of the point of intersection, and index 2 is a special code. If the lines intersect in exactly one point, the special code is 0 and the point of intersection is represented as described above. If the lines do NOT intersect in exactly one point, then index 0 and index 1 should each contain 0 and the special code should be as follows: Use -1 to indicate that the lines are parallel and therefore have no points of intersection. Use 1 to indicate that the lines are really the same line and therefore intersect at all points on that line. Look at the test data for examples. This problem will be MUCH easier if you do some scratch-work on an actual piece of physical paper with an actual writing implement. Note: While the lines will only have integer values for the slope and the y-value of the y-intercept, this could still result in non-integer values for the point of intersection. Therefore, we will return an array of type double. Remember that you can type-cast an int to a double by putting (double) in front of the int variable. WHERE you do this might matter immensely.


quiz2020_12_15_SLHL_solve([17, 2], [-13, 8]) → [0.2, 5.4, 0.0]
quiz2020_12_15_SLHL_solve([5, 900], [6, -800]) → [1700.0, 9400.0, 0.0]
quiz2020_12_15_SLHL_solve([3, 4], [5, 6]) → [-1.0, 1.0, 0.0]

...Save, Compile, Run (ctrl-enter)

public double[] quiz2020_12_15_SLHL_solve(int[] line1, int[] line2) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 280

Copyright Nick Parlante 2017 - privacy