Programming and Computer Science in Java:

See Course Home Page.

**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 = ax

** 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 e

e^{x}
= 1 + x + x^{2}/2!
+ x^{3}/3!
+ x^{4}/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 e^{1}, 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.

Good luck!

DK

See Course Home Page.