Design a class named LINEAR EQUATION for a 2 times 2 system of linear equations:
ID: 440971 • Letter: D
Question
Design a class named LINEAR EQUATION for a 2 times 2 system of linear equations: Ax + by = e Cx + dy = f The class contains: Private data fields, a, b, c, d, e, and f A constructor with the arguments for a, b, c, d, e, and f. Six get methods for a, b,, d, e, and f. A method name is Solvable Q that returns true if ad - bc is not 0. Methods get X() and get Y() that return the solution for the equation. Draw the UML diagram for the class. 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 is 0, report that 'The equation has no solution."Explanation / Answer
the complete program is written below with sample output. I have checked it in eclipse
-----------
import java.util.Scanner;
public class LinearEquation {
static Scanner scan=new Scanner(System.in);
private int a,b,c,d,e,f;
public LinearEquation(int a, int b, int c, int d, int e, int f) {
super();
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.f = f;
}
public int getA() {
return a;
}
public int getB() {
return b;
}
public int getC() {
return c;
}
public int getD() {
return d;
}
public int getE() {
return e;
}
public int getF() {
return f;
}
public boolean isSolvable()
{
if((getA()*getD()-getB()*getC())!=0)
{
return true;
}
else return false;
}
public double getX(){
double x;
x=(getE()*getD()-getB()*getF())/(getA()*getD()-getB()*getC());
return x;
}
public double getY()
{
double y;
y=(getA()*getF()-getE()*getC())/(getA()*getD()-getB()*getC());
return y;
}
public static void main(String[] args)
{
int a,b,c,d,e,f;
System.out.println("enter A");
a=Integer.parseInt(scan.nextLine());
System.out.println("enter B");
b=Integer.parseInt(scan.nextLine());
System.out.println("enter C");
c=Integer.parseInt(scan.nextLine());
System.out.println("enter D");
d=Integer.parseInt(scan.nextLine());
System.out.println("enter E");
e=Integer.parseInt(scan.nextLine());
System.out.println("enter F");
f=Integer.parseInt(scan.nextLine());
LinearEquation le=new LinearEquation(a,b,c,d,e,f);
if(le.isSolvable()){
System.out.println("Is solvable :"+le.isSolvable());
System.out.println("Solution is.......");
System.out.println("x="+ le.getX());
System.out.println("y="+ le.getY());
}
else
System.out.println("no solution");
}
}
-------------------------------
sample output
--------------------------
enter A
2
enter B
1
enter C
3
enter D
-4
enter E
7
enter F
5
Is solvable :true
Solution is.......
x=3.0
y=1.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.