** MUST BE DONE USING JAVA*** **This program involves refering to 3.25 and using
ID: 3562345 • Letter: #
Question
** MUST BE DONE USING JAVA***
**This program involves refering to 3.25 and using the Linear Equation class in 9.11.
**9.12 is the program I need to run correctly.
********3.25
two lines one line 1 are given as (x1,y1) and (x2,y2) and on line 2 as (x3,y3) and (x4, y4). The intersecting point of the two lines can be found by solving the following linear equation:
(y1-y2)x - (x1-x2)y = (y1-y2)x1 - (x1 - x2)y1
(y3-y4)x - (x3-x4)y = (y3-y4)x3 - (x3-x4)y3
The linear equation can be solved using Cramer's rule. If the equation has no solution the two lines are parrallel. Write a program that prompts the user to enter 4 points and displays the intersecting point.
********9.11
Design a class named LinearEquation for a 2x2 system of linear equations:
ax + by = e
cx + dy = f
x = (ed - bf) / (ad - bc)
y = (af - ec) / (ad - bc)
The class contains:
Private data fields a,b,c,d,e, and f.
A constructor with the arguements for a,b,c,d,e, and f.
six getter methods for a, b, c, d, e, and f.
The method named isSolvable() that returns true if ad - bc is not 0.
Methods getX() and getY() that return the solution for the equation.
Implement the class. Write a test program that prompts the user to enter a,b,c,d,e, and f and displays the result. if ad-bc = 0, report that " The equation has no solution".
*********9.12
Suppose two line segments intersect. The two endpoints for the first line segment are (x1, y1) and (x2 y2) and for the second line segment are (x3, y3) and (x4, y4). Write a program that prompts the user to enter these four endpoints and displays the intersecting point. As discussed in programming excercise 3.25, the intersecting point can be found by solving a linear equation. Use the LinearEquation class in programming excercise 9.11 to solve this equation.
Explanation / Answer
please rate
import java.util.Scanner;
public class LinearEquation {
private double a,b,c,d,e,f;
public LinearEquation(double a,double b,double c,double d,double e,double f){
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.f = f;
}
public double getA(){
return a;
}
public double getB(){
return b;
}
public double getC(){
return c;
}
public double getD(){
return d;
}
public double getE(){
return e;
}
public double getF(){
return f;
}
public boolean isSolvable(){
return a*d-b*c==0?true:false;
}
public double getX(){
return (e*d-b*f) / (a*d - b*c);
}
public double getY(){
if(isSolvable())
return (a*f-e*c) / (a*d-b*c);
else
return -1;
}
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter the values of a,b,c,d,e and f:");
double a,b,c,d,e,f;
a = input.nextDouble();
b = input.nextDouble();
c = input.nextDouble();
d = input.nextDouble();
e = input.nextDouble();
f = input.nextDouble();
LinearEquation le = new LinearEquation(a, b, c, d, e, f);
if(le.isSolvable()){
System.out.println("X: "+le.getX()+" Y: "+le.getY());
}else{
System.out.println("The equation has no solution");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.