Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is problem number 8 page 507 The equation of a line in standard form is ax

ID: 3622110 • Letter: T

Question

This is problem number 8 page 507

The equation of a line in standard form is ax + by = c, where a and b both cannot be zero, and a, b, and c are real numbers. If b !=(Doesn't equal) 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 slop of a vertical line is undefined. two lines are parallel if they have the same slop or both are vertical lines. Two lines are perpendicular if one of the lines is horizontal and another is vertical, or if the product of their slopes is -1. design the class lineType to store a line. to store a line, you need to store the value 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 a1x + b1y = c1 and a2x + b2y = c2 are equal if either a1 = a2, b1 = b2, and c1 = c2 or a1 = ka2, b1 = kb2, and c1 = kc2 for some real number k.)
c. determine if two lines are parallels
d. determine if two lines are perpendicular
e. if two lines are not parallel, then fid the point of intersection.
Add appropriate constructors to initialize variables of lineType. Also write a program to test your class.

Explanation / Answer

import java.io.*; public class LineType { private double a; private double b; private double c; public LineType(double a, double b, double c) { this.a = a; this.b = b; this.c = c; } public double getSlope() { return (-a / b); } public boolean equals(LineType l) { return (l.a * b == l.b * a && l.a * c == l.c * a && l.b * c == l.c * b); } public boolean isParallel(LineType l) { return (l.a * b == l.b * a); } public boolean isPerpendicular(LineType l) { return (l.a * a == -l.b * b); } public PointType intersection(LineType l) { double d = l.a*b - l.b*a; return new PointType((l.c*b-l.b*c)/d,(l.a*c - l.c*a)/d); } public class PointType { public double x; public double y; PointType(double x, double y) { this.x = x; this.y = y; } } public static void main(String[] args) throws IOException { System.out.println("l1 coefficients"); System.out.print("a: "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in) ); double a1 = Double.parseDouble(br.readLine()); System.out.print("b: "); double b1 = Double.parseDouble(br.readLine()); System.out.print("c: "); double c1 = Double.parseDouble(br.readLine()); System.out.println("l2 coefficients"); System.out.print("a: "); double a2 = Double.parseDouble(br.readLine()); System.out.print("b: "); double b2 = Double.parseDouble(br.readLine()); System.out.print("c: "); double c2 = Double.parseDouble(br.readLine()); LineType l1 = new LineType(a1,b1,c1); LineType l2 = new LineType(a2,b2,c2); System.out.println("Slope of l1: "+ l1.getSlope()); System.out.println("l1 equals l2: "+l1.equals(l2)); System.out.println("l1 is parallel to l2: "+l1.isParallel(l2)); System.out.println("l1 is perpendicular to l2: "+l1.isPerpendicular(l2)); if (!l1.isParallel(l2)) { PointType p = l1.intersection(l2); System.out.println("Point of intersection of l1 and l2: ("+p.x+","+p.y+")"); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote