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

Linear Equations A 2 x 2 system of linear equations can be solved via Cramer\'s

ID: 3622478 • Letter: L

Question

Linear Equations
A 2 x 2 system of linear equations can be solved via Cramer's rule, as shown below:
ax + by = e
cx + dy = f
x = (ed - bf)/(ad - bc)
y = (af - ec)/(ad - bc)


Implement a class named LinearEquation that contains everything in the list
below. Include a test program that prompts the user to enter values for a, b, c, d, e,
and f and displays the result (x and y). If ad - bc is 0, report that "The equation has no
solution."
a. Private double instance variables for a, b, c, d, e, and f
b. A constructor that takes arguments for a, b, c, d, e, and f
c. Six get() methods for a, b, c, d, e, and f
d. A boolean method named isSolvable(). This method returns true if ad - bc
is not 0.
e. Methods getX() and getY() that return the solution for the equation.
NOTE: Your solution should use double variables to represent a, b, c, d, e, f, x,
and y!

And also, modify your solution so that it reads the values of a, b, c, d,
e, and f from a text file. You may hard-code the name of the data file into your
program, or get the filename either from the user or from the command line
.

Explanation / Answer

please rate

public class LinearEquation {
    private double a,b,c,d,e,f,x,y;
    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 double getX() throws Exception {
        if(!isSolvable()){
            //implement your own exception or print not solvable
        }
        x = (e*d-b*f)/(a*d-b*c);//x = (ed - bf)/(ad - bc)
        return x;
    }
    public double getY(){
        if(!isSolvable()){
    //implement your own exception or print not solvable
        }
        y = (a*f-e*c)/(a*d-b*c);//y = (af - ec)/(ad - bc)
        return y;
    }

    public boolean isSolvable(){
        if((a*d-b*c)==0){
            return false;
        }
        return true;
    }
}

Write another class containing the main function and create a object of linear equation.You can use the java.util.Scanner class to scan the input from text file. like Scanner sc = new Scanner(new File("pathname")); Import java.io.File also. use nextDouble function of scanner class to get input. catch exceptions that might occur like filenotfound

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