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

Java programming (Algebra: 2 * 2 linear equations ) Design a class named LinearE

ID: 3810734 • Letter: J

Question

Java programming

(Algebra: 2 * 2 linear equations) Design a class named LinearEquation for a 2 * 2 system of linear equations:

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 getter methods for a, b, c, d, e, and f.

A method named isSolvable() that returns true if ad - bc is not 0.

Methods getX() and getY() that return the solution for the equation.

Draw the UML diagram for the class and then 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.”

See Programming Exercise 3.3 for sample runs

ax + by = e-ed-bf-of-ec cx + dy = f x= ad-be y ad-bc

Explanation / Answer

public class LinearEquation {

// declare the six coefficient

private static int a;

private static int b;

private static int c;

private static int d;

private static int e;

private static int f;

// a constructor to initial the coefficient

LinearEquation(int inputA, int inputB, int inputC, int inputD, int inputE, int inputF){

a = inputA;

b = inputB;

c = inputC;

d = inputD;

e = inputE;

f = inputF;

}

// method isSolvable to show whether the equations has solution or not

static int isSolvable(){

if(((a*d) - (b*c)) == 0)

return 0;

else

return 1;

}

// method getX() to calculate the solution of x

static double getX(){

return (((e*d) - (b*f))/((a*d) - (b*c)));

}

// method getY() to calculate the solution of y

static double getY(){

return (((a*f) - (e*c))/((a*d) - (b*c)));

}

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