Java Reference
In-Depth Information
you need to store the values of a (coefficient of x), b (coefficient of y), and c.
Your class must contain the following operations:
a. If a line is nonvertical, then determine its slope.
b. Determine if two lines are equal. (Two lines a 1 x + b 1 y ¼ c 1 and a 2 x + b 2 y ¼ c 2
are equal if either a 1 ¼ a 2 , b 1 ¼ b 2 , and c 1 ¼ c 2 or a 1 ¼ ka 2 , b 1 ¼ kb 2 , and
c 1 ¼ kc 2 for some real number k.)
c. Determine if two lines are parallel.
d. Determine if two lines are perpendicular.
e. If two lines are not parallel, then find the point of intersection.
Add appropriate constructors to initialize variables of Line . Also write a
program to test your class.
8. Rational fractions are of the form a / b,wherea and b are integers and b 0.
In this exercise, by ''fractions'' we mean rational fractions. Suppose that a / b and
c / d are fractions. Arithmetic operations on fractions are defined by the following
rules:
a / b + c / d ¼ (ad + bc)/bd
a / b - c / d ¼ (ad - bc)/bd
a / b c / d ¼ ac / bd
(a / b)/(c / d) ¼ ad / bc, where c / d 0
Fractions are compared as follows: a / bopc/ d if ad op bc, where op is any of
the relational operations. For example, a / b < c / d if ad < bc.
Design the class Fraction that can be used to manipulate fractions in a
program. Among others, the class Fraction must include methods to add,
subtract, multiply, and divide fractions. When you add, subtract, multiply, or
divide fractions, your answer need not be in the lowest terms. Also, override the
method toString so that the fractions can be output using the output statement.
Write a Java program that, using the class Fraction , performs operations on
fractions.
8
Search WWH ::




Custom Search