Due Date: Fri, Mar 14, 2003
For each of the following questions, anything which your programs compute must be computed within a new method, and not directly inside your main method.
Question 1: Slope of a Line. Write a Java program which reads in four integers, x1, y1, x2, y2. Print out the slope of the line (as a double) which goes through the points (x1,y1) and (x2,y2). If the line is vertical, print out an appropriate message (you may not just crash by dividing by zero!).
Question 2: Zeroes of a Parabola. Write a Java program which reads in three integers, a, b, and c, prints out (as a double) where the parabola y = ax2 + bx + c crosses the x axis (that is, where y = 0). These are called the real zeroes of the parabola. Note that it may do so zero times, one time, or two times, and you must handle all three cases. To solve this problem, you will want to use the quadratic formula. As with the previous problem, you may not crash (here by taking the square root of a negative number).
Question 3: Line intersection. Write a Java program which reads in four integers: m1, b1, m2, b2. These represent the lines y = m1 * x + b1, and y = m2 * x + b2. Print out the point (x,y) (where x and y are doubles) where these two lines intersect. If the two lines are the same line, or if they are parallel, print out appropriate messages.
Question 4: The value of e. The value of ex can be computed as follows:
ex = 1 + x + x2/2! + x3/3! + x4/4! + ...
where k! is "k factorial", which as you know equals k*(k-1)*...*2*1.
Write a Java program which uses this technique to compute the value of e (which is e1, right?), stopping when the next term to be added is smaller than 0.00000001. Verify your answer by comparing with the value of Math.E, a builtin constant in Java.
See Course Home Page.