he equation of a line in standard form is ax + by = c, wherein both a and b cann
ID: 3773245 • Letter: H
Question
he equation of a line in standard form is ax + by = c, wherein both a and b cannot be zero, and a, b, and c are real numbers. If b != 0, then –a/b is the slope of the line. If a = 0, then it is a horizontal line, and if b = 0, then it is a vertical line. The slope of a vertical line is undefined. Two lines are parallel if they have the same slope or both are vertical lines. Two lines are perpendicular if either one of the lines is horizontal and the other is vertical or the product of their slopes is –1. Design the class lineType to store a line. To store a line, you need to store the values of a (coefficient of x), b (coefficient of y), and c. Your class must contain the following operations. Implement the class lineType while considering the following: a. Overloads the stream insertion operator, >, for easy intput. (The line ax + by = c is input as (a, b, c).) c. Overloads the assignment operator to copy a line into another line. d. Overloads the unary operator +, as a member function, so that it returns true if a line is vertical; false otherwise. e. Overloads the unary operator -, as a member function, so that it returns true if a line is horizontal; false otherwise. f. Overloads the operator ==, as a member function, so that it returns true if two lines are equal; false otherwise. g. Overloads the operator ||, as a member function, so that it returns true if two lines are parallel; false otherwise. h. Overloads the operator &&, as a member function, so that it returns true if two lines are perpendicular; false otherwise.
Explanation / Answer
public class Line {
private double a2,a1,b2,b1,c2,c1;
Line(){}
public void setLine1(double a, double b ,double c)
{a1 = a; b1 = b; c1 = c;}
public void setLine2(double a, double b ,double c){
a2 = a; b2 = b; c2 = c;}
public String slope1(){
if(b1 == 0 )
return (" Verticle line and the slope is Undefined.");
else if (a1 == 0)
return (" Horizontal line and the slope is 0.");
else{
Double m = Double.parseDouble(Double.toString(a1));
Double m2 = Double.parseDouble(Double.toString(b1));
Double slope1; slope1 = (-1*m)/m2;
return(" The slope of the first line is " + slope1 + ".");}}
public String slope2(){
if( b2 == 0)
return (" Verticle line and the slope is Undefined.");
else if ( a2==0)
return (" Horizontal line and the slope is 0.");
else{
Double m3 = Double.parseDouble(Double.toString(a2));
Double m4 = Double.parseDouble(Double.toString(b2));
Double slope2; slope2 = (-1*m3)/m4;
return(" The slope of the second line is " + slope2 + ".");}}
public String equal(){
if ( (a1 == a2) && (b1 == b2) &&( c1 == c2))
return (" and equal.");
return (" and not equal.");}
public String parallel(){
double m = (-1*a1)/b1;
double m1 = (-1*a2)/b2;
if (m == m1)
return (" The lines are parallel");
else if (b1 == 0 & b2 == 0)
return(" The lines are parallel");
return(" The lines are not parallel");}
public String perpendicular(){
double m = (-1*a1)/b1;
double m1 = (-1*a2)/b2;
if ((a1 == 0) & (b2 == 0))
return(", perpendicular");
else if ((b1 == 0) & (a2 == 0))
return (", perpendicular");
else if ((m * m1) == -1 )
return (", perpendicular");
return(", not perpendicular");}
public double getA1()
{return a1;}
public double getB1()
{return b1;}
public double getC1()
{return c1;}
public double getA2()
{return a2;}
public double getB2()
{return b2;}
public double getC2()
{return c2;}}
JOptionPane.QUESTION_MESSAGE);}}}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.